public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Li Zefan <lizf@cn.fujitsu.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 10/13] tracing: Simplify trace_option_write()
Date: Tue, 08 Dec 2009 11:17:06 +0800	[thread overview]
Message-ID: <4B1DC532.9010802@cn.fujitsu.com> (raw)
In-Reply-To: <4B1DC476.3030700@cn.fujitsu.com>

- remove duplicate code inside trace_options_write()
- extract duplicate code in trace_options_write() and set_tracer_option()

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
 kernel/trace/trace.c |   85 ++++++++++++++++++-------------------------------
 1 files changed, 31 insertions(+), 54 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 2801b0b..9359b74 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2318,38 +2318,39 @@ static int tracing_trace_options_show(struct seq_file *m, void *v)
 	return 0;
 }
 
+static int __set_tracer_option(struct tracer *trace,
+			       struct tracer_flags *tracer_flags,
+			       struct tracer_opt *opts, int neg)
+{
+	int ret;
+
+	ret = trace->set_flag(tracer_flags->val, opts->bit, !neg);
+	if (ret)
+		return ret;
+
+	if (neg)
+		tracer_flags->val &= ~opts->bit;
+	else
+		tracer_flags->val |= opts->bit;
+	return 0;
+}
+
 /* Try to assign a tracer specific option */
 static int set_tracer_option(struct tracer *trace, char *cmp, int neg)
 {
 	struct tracer_flags *tracer_flags = trace->flags;
 	struct tracer_opt *opts = NULL;
-	int ret = 0, i = 0;
-	int len;
+	int i;
 
 	for (i = 0; tracer_flags->opts[i].name; i++) {
 		opts = &tracer_flags->opts[i];
-		len = strlen(opts->name);
 
-		if (strncmp(cmp, opts->name, len) == 0) {
-			ret = trace->set_flag(tracer_flags->val,
-				opts->bit, !neg);
-			break;
-		}
+		if (strcmp(cmp, opts->name) == 0)
+			return __set_tracer_option(trace, trace->flags,
+						   opts, neg);
 	}
-	/* Not found */
-	if (!tracer_flags->opts[i].name)
-		return -EINVAL;
 
-	/* Refused to handle */
-	if (ret)
-		return ret;
-
-	if (neg)
-		tracer_flags->val &= ~opts->bit;
-	else
-		tracer_flags->val |= opts->bit;
-
-	return 0;
+	return -EINVAL;
 }
 
 static void set_tracer_flags(unsigned int mask, int enabled)
@@ -2369,7 +2370,7 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
 			size_t cnt, loff_t *ppos)
 {
 	char buf[64];
-	char *cmp = buf;
+	char *cmp;
 	int neg = 0;
 	int ret;
 	int i;
@@ -2381,16 +2382,15 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
 		return -EFAULT;
 
 	buf[cnt] = 0;
+	cmp = strstrip(buf);
 
-	if (strncmp(buf, "no", 2) == 0) {
+	if (strncmp(cmp, "no", 2) == 0) {
 		neg = 1;
 		cmp += 2;
 	}
 
 	for (i = 0; trace_options[i]; i++) {
-		int len = strlen(trace_options[i]);
-
-		if (strncmp(cmp, trace_options[i], len) == 0) {
+		if (strcmp(cmp, trace_options[i]) == 0) {
 			set_tracer_flags(1 << i, !neg);
 			break;
 		}
@@ -3888,39 +3888,16 @@ trace_options_write(struct file *filp, const char __user *ubuf, size_t cnt,
 	if (ret < 0)
 		return ret;
 
-	ret = 0;
-	switch (val) {
-	case 0:
-		/* do nothing if already cleared */
-		if (!(topt->flags->val & topt->opt->bit))
-			break;
-
-		mutex_lock(&trace_types_lock);
-		if (current_trace->set_flag)
-			ret = current_trace->set_flag(topt->flags->val,
-						      topt->opt->bit, 0);
-		mutex_unlock(&trace_types_lock);
-		if (ret)
-			return ret;
-		topt->flags->val &= ~topt->opt->bit;
-		break;
-	case 1:
-		/* do nothing if already set */
-		if (topt->flags->val & topt->opt->bit)
-			break;
+	if (val != 0 && val != 1)
+		return -EINVAL;
 
+	if (!!(topt->flags->val & topt->opt->bit) != val) {
 		mutex_lock(&trace_types_lock);
-		if (current_trace->set_flag)
-			ret = current_trace->set_flag(topt->flags->val,
-						      topt->opt->bit, 1);
+		ret = __set_tracer_option(current_trace, topt->flags,
+					  topt->opt, val);
 		mutex_unlock(&trace_types_lock);
 		if (ret)
 			return ret;
-		topt->flags->val |= topt->opt->bit;
-		break;
-
-	default:
-		return -EINVAL;
 	}
 
 	*ppos += cnt;
-- 
1.6.3


  parent reply	other threads:[~2009-12-08  3:17 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-08  3:13 [PATCH 00/13] tracing: various cleanups and small fixes (updated) Li Zefan
2009-12-08  3:14 ` [PATCH 01/13] tracing: Extract duplicate ftrace_raw_init_event_foo() Li Zefan
2009-12-08  7:30   ` Frederic Weisbecker
2009-12-08  7:49     ` Li Zefan
2009-12-08  8:08       ` Frederic Weisbecker
2009-12-08 13:23       ` Steven Rostedt
2009-12-14  9:45   ` [tip:tracing/urgent] " tip-bot for Li Zefan
2009-12-08  3:14 ` [PATCH 02/13] tracing: Extract calls to trace_define_common_fields() Li Zefan
2009-12-08  5:36   ` Lai Jiangshan
2009-12-08  7:57     ` Frederic Weisbecker
2009-12-08  8:03       ` Li Zefan
2009-12-08  8:16         ` Frederic Weisbecker
2009-12-08  8:21           ` Li Zefan
2009-12-08  8:59             ` Frederic Weisbecker
2009-12-14  9:45   ` [tip:tracing/urgent] tracing: Pull up " tip-bot for Li Zefan
2009-12-08  3:14 ` [PATCH 03/13] tracing: Move a printk out of ftrace_raw_reg_event_foo() Li Zefan
2009-12-08  7:43   ` Frederic Weisbecker
2009-12-08  7:49     ` Li Zefan
2009-12-08  8:11       ` Frederic Weisbecker
2009-12-14  9:46   ` [tip:tracing/urgent] " tip-bot for Li Zefan
2009-12-08  3:15 ` [PATCH 04/13] ftrace: Return EINVAL when writing invalid val to set_ftrace_filter Li Zefan
2009-12-14  9:46   ` [tip:tracing/urgent] " tip-bot for Li Zefan
2009-12-08  3:15 ` [PATCH 05/13] ftrace: Call trace_parser_clear() properly Li Zefan
2009-12-08  9:48   ` Frederic Weisbecker
2009-12-08 10:03     ` Li Zefan
2009-12-08 11:43       ` Frederic Weisbecker
2009-12-08 13:28       ` Steven Rostedt
2009-12-09  5:52   ` Steven Rostedt
2009-12-14  9:46   ` [tip:tracing/urgent] " tip-bot for Li Zefan
2009-12-08  3:15 ` [PATCH 06/13] function-graph: Allow writing the same val to set_graph_function Li Zefan
2009-12-14  9:46   ` [tip:tracing/urgent] " tip-bot for Li Zefan
2009-12-08  3:15 ` [PATCH 07/13] tracing: Use seq file for trace_options Li Zefan
2009-12-14  9:47   ` [tip:tracing/urgent] " tip-bot for Li Zefan
2009-12-08  3:16 ` [PATCH 08/13] tracing: Use seq file for trace_clock Li Zefan
2009-12-14  9:47   ` [tip:tracing/urgent] " tip-bot for Li Zefan
2009-12-08  3:16 ` [PATCH 09/13] tracing: Remove useless trace option Li Zefan
2009-12-14  9:47   ` [tip:tracing/urgent] " tip-bot for Li Zefan
2009-12-08  3:17 ` Li Zefan [this message]
2009-12-14  9:47   ` [tip:tracing/urgent] tracing: Simplify trace_option_write() tip-bot for Li Zefan
2009-12-08  3:17 ` [PATCH 11/13] tracing: Change event->profile_count to be int type Li Zefan
2009-12-14  9:48   ` [tip:tracing/urgent] " tip-bot for Li Zefan
2009-12-08  3:17 ` [PATCH 12/13] tracing/power: Remove two exports Li Zefan
2009-12-14  9:48   ` [tip:tracing/urgent] " tip-bot for Li Zefan
2009-12-08  3:18 ` [PATCH 13/13] ksym_tracer: Fix compile warnings Li Zefan
2009-12-14  9:48   ` [tip:tracing/urgent] ksym_tracer: Fix bad cast tip-bot for Li Zefan
2009-12-08 12:23 ` [PATCH 00/13] tracing: various cleanups and small fixes (updated) Frederic Weisbecker
2009-12-08 13:29   ` Steven Rostedt
2009-12-08 13:41     ` Frederic Weisbecker
2009-12-09  5:53 ` Steven Rostedt
  -- strict thread matches above, loose matches on Subject: below --
2009-12-13 13:08 [GIT PULL] tracing updates Frederic Weisbecker
2009-12-13 13:08 ` [PATCH 10/13] tracing: Simplify trace_option_write() Frederic Weisbecker
2009-12-07  7:39 [PATCH 0/13] tracing: various cleanups and small fixes Li Zefan
2009-12-07  7:43 ` [PATCH 10/13] tracing: Simplify trace_option_write() Li Zefan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B1DC532.9010802@cn.fujitsu.com \
    --to=lizf@cn.fujitsu.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox