2009-06-19 17:25:38

by K.Prasad

[permalink] [raw]
Subject: [Patch 2/3] ksym_tracer: Allow bulk removal using empty or wildcard string input

Accept an empty string or wildcard input (of the form *:---) as input for
ksym_trace_filter to perform bulk removal of all monitored entries.

Signed-off-by: K.Prasad <[email protected]>
---
kernel/trace/trace_ksym.c | 75 +++++++++++++++++++++++++---------------------
1 file changed, 42 insertions(+), 33 deletions(-)

Index: linux-2.6-tip.hbkpt/kernel/trace/trace_ksym.c
===================================================================
--- linux-2.6-tip.hbkpt.orig/kernel/trace/trace_ksym.c
+++ linux-2.6-tip.hbkpt/kernel/trace/trace_ksym.c
@@ -138,6 +138,34 @@ static int ksym_trace_get_access_type(ch
return access;
}

+static void ksym_trace_reset(struct trace_array *tr)
+{
+ struct trace_ksym *entry;
+ struct hlist_node *node, *node1;
+
+ ksym_tracing_enabled = 0;
+
+ mutex_lock(&ksym_tracer_mutex);
+ hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
+ ksym_hlist) {
+ unregister_kernel_hw_breakpoint(entry->ksym_hbp);
+ ksym_filter_entry_count--;
+ hlist_del_rcu(&(entry->ksym_hlist));
+ synchronize_rcu();
+ /* Free the 'input_string' only if reset
+ * after startup self-test
+ */
+#ifdef CONFIG_FTRACE_SELFTEST
+ if (strncmp(entry->ksym_hbp->info.name, KSYM_SELFTEST_ENTRY,
+ strlen(KSYM_SELFTEST_ENTRY)) != 0)
+#endif /* CONFIG_FTRACE_SELFTEST*/
+ kfree(entry->ksym_hbp->info.name);
+ kfree(entry->ksym_hbp);
+ kfree(entry);
+ }
+ mutex_unlock(&ksym_tracer_mutex);
+}
+
/*
* There can be several possible malformed requests and we attempt to capture
* all of them. We enumerate some of the rules
@@ -163,7 +191,7 @@ static int parse_ksym_trace_str(char *in
/* Check for malformed request: (2), (1) and (5) */
if ((!input_string) ||
(strlen(input_string) != (KSYM_TRACER_OP_LEN + 1)) ||
- (*addr == 0))
+ ((*addr == 0) && strncmp(*ksymname, "*", strlen("*"))))
goto return_code;
ret = ksym_trace_get_access_type(input_string);

@@ -211,6 +239,7 @@ int process_new_ksym_entry(char *ksymnam
}
hlist_add_head_rcu(&(entry->ksym_hlist), &ksym_filter_head);
ksym_filter_entry_count++;
+ ksym_tracing_enabled = 1;

return 0;
}
@@ -220,7 +249,7 @@ static ssize_t ksym_trace_filter_read(st
{
struct trace_ksym *entry;
struct hlist_node *node;
- char buf[KSYM_FILTER_ENTRY_LEN * KSYM_TRACER_MAX];
+ char buf[KSYM_FILTER_ENTRY_LEN * KSYM_TRACER_MAX] = "\0";
ssize_t ret, cnt = 0;

mutex_lock(&ksym_tracer_mutex);
@@ -251,9 +280,11 @@ static ssize_t ksym_trace_filter_write(s
unsigned long ksym_addr = 0;
int ret, op, changed = 0;

- /* Ignore echo "" > ksym_trace_filter */
- if (count == 0)
- return 0;
+ /* Clear all breakpoint requests if echo "" > ksym_trace_filter */
+ if (count == 1) {
+ ksym_trace_reset(NULL);
+ return count;
+ }

input_string = kzalloc(count, GFP_KERNEL);
if (!input_string)
@@ -269,6 +300,12 @@ static ssize_t ksym_trace_filter_write(s
kfree(input_string);
return ret;
}
+ /* Clear all breakpoints if echo "*:---" > ksym_trace_filter */
+ if ((strncmp(ksymname, "*", strlen("*")) == 0) && (op == 0)) {
+ ksym_trace_reset(NULL);
+ kfree(input_string);
+ return count;
+ }

mutex_lock(&ksym_tracer_mutex);

@@ -325,34 +362,6 @@ static const struct file_operations ksym
.write = ksym_trace_filter_write,
};

-static void ksym_trace_reset(struct trace_array *tr)
-{
- struct trace_ksym *entry;
- struct hlist_node *node, *node1;
-
- ksym_tracing_enabled = 0;
-
- mutex_lock(&ksym_tracer_mutex);
- hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
- ksym_hlist) {
- unregister_kernel_hw_breakpoint(entry->ksym_hbp);
- ksym_filter_entry_count--;
- hlist_del_rcu(&(entry->ksym_hlist));
- synchronize_rcu();
- /* Free the 'input_string' only if reset
- * after startup self-test
- */
-#ifdef CONFIG_FTRACE_SELFTEST
- if (strncmp(entry->ksym_hbp->info.name, KSYM_SELFTEST_ENTRY,
- strlen(KSYM_SELFTEST_ENTRY)) != 0)
-#endif /* CONFIG_FTRACE_SELFTEST*/
- kfree(entry->ksym_hbp->info.name);
- kfree(entry->ksym_hbp);
- kfree(entry);
- }
- mutex_unlock(&ksym_tracer_mutex);
-}
-
static int ksym_trace_init(struct trace_array *tr)
{
int cpu, ret = 0;


2009-06-19 23:16:50

by Frederic Weisbecker

[permalink] [raw]
Subject: Re: [Patch 2/3] ksym_tracer: Allow bulk removal using empty or wildcard string input

On Fri, Jun 19, 2009 at 10:55:12PM +0530, K.Prasad wrote:
> Accept an empty string or wildcard input (of the form *:---) as input for
> ksym_trace_filter to perform bulk removal of all monitored entries.
>
> Signed-off-by: K.Prasad <[email protected]>
> ---
> kernel/trace/trace_ksym.c | 75 +++++++++++++++++++++++++---------------------
> 1 file changed, 42 insertions(+), 33 deletions(-)
>
> Index: linux-2.6-tip.hbkpt/kernel/trace/trace_ksym.c
> ===================================================================
> --- linux-2.6-tip.hbkpt.orig/kernel/trace/trace_ksym.c
> +++ linux-2.6-tip.hbkpt/kernel/trace/trace_ksym.c
> @@ -138,6 +138,34 @@ static int ksym_trace_get_access_type(ch
> return access;
> }
>
> +static void ksym_trace_reset(struct trace_array *tr)
> +{
> + struct trace_ksym *entry;
> + struct hlist_node *node, *node1;
> +
> + ksym_tracing_enabled = 0;
> +
> + mutex_lock(&ksym_tracer_mutex);
> + hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
> + ksym_hlist) {
> + unregister_kernel_hw_breakpoint(entry->ksym_hbp);
> + ksym_filter_entry_count--;
> + hlist_del_rcu(&(entry->ksym_hlist));
> + synchronize_rcu();
> + /* Free the 'input_string' only if reset
> + * after startup self-test
> + */
> +#ifdef CONFIG_FTRACE_SELFTEST
> + if (strncmp(entry->ksym_hbp->info.name, KSYM_SELFTEST_ENTRY,
> + strlen(KSYM_SELFTEST_ENTRY)) != 0)
> +#endif /* CONFIG_FTRACE_SELFTEST*/
> + kfree(entry->ksym_hbp->info.name);
> + kfree(entry->ksym_hbp);
> + kfree(entry);
> + }
> + mutex_unlock(&ksym_tracer_mutex);
> +}
> +
> /*
> * There can be several possible malformed requests and we attempt to capture
> * all of them. We enumerate some of the rules
> @@ -163,7 +191,7 @@ static int parse_ksym_trace_str(char *in
> /* Check for malformed request: (2), (1) and (5) */
> if ((!input_string) ||
> (strlen(input_string) != (KSYM_TRACER_OP_LEN + 1)) ||
> - (*addr == 0))
> + ((*addr == 0) && strncmp(*ksymname, "*", strlen("*"))))



I guess you can just use strcmp() here, no? As in other use
of this same strncmp() in this patch.



> goto return_code;
> ret = ksym_trace_get_access_type(input_string);
>
> @@ -211,6 +239,7 @@ int process_new_ksym_entry(char *ksymnam
> }
> hlist_add_head_rcu(&(entry->ksym_hlist), &ksym_filter_head);
> ksym_filter_entry_count++;
> + ksym_tracing_enabled = 1;
>
> return 0;
> }
> @@ -220,7 +249,7 @@ static ssize_t ksym_trace_filter_read(st
> {
> struct trace_ksym *entry;
> struct hlist_node *node;
> - char buf[KSYM_FILTER_ENTRY_LEN * KSYM_TRACER_MAX];
> + char buf[KSYM_FILTER_ENTRY_LEN * KSYM_TRACER_MAX] = "\0";
> ssize_t ret, cnt = 0;
>
> mutex_lock(&ksym_tracer_mutex);
> @@ -251,9 +280,11 @@ static ssize_t ksym_trace_filter_write(s
> unsigned long ksym_addr = 0;
> int ret, op, changed = 0;
>
> - /* Ignore echo "" > ksym_trace_filter */
> - if (count == 0)
> - return 0;
> + /* Clear all breakpoint requests if echo "" > ksym_trace_filter */
> + if (count == 1) {
> + ksym_trace_reset(NULL);
> + return count;
> + }


And then if I do:

echo -n 1 > ksym_trace_filter

That would also clean these breakpoints?

Frederic.



>
> input_string = kzalloc(count, GFP_KERNEL);
> if (!input_string)
> @@ -269,6 +300,12 @@ static ssize_t ksym_trace_filter_write(s
> kfree(input_string);
> return ret;
> }
> + /* Clear all breakpoints if echo "*:---" > ksym_trace_filter */
> + if ((strncmp(ksymname, "*", strlen("*")) == 0) && (op == 0)) {
> + ksym_trace_reset(NULL);
> + kfree(input_string);
> + return count;
> + }
>
> mutex_lock(&ksym_tracer_mutex);
>
> @@ -325,34 +362,6 @@ static const struct file_operations ksym
> .write = ksym_trace_filter_write,
> };
>
> -static void ksym_trace_reset(struct trace_array *tr)
> -{
> - struct trace_ksym *entry;
> - struct hlist_node *node, *node1;
> -
> - ksym_tracing_enabled = 0;
> -
> - mutex_lock(&ksym_tracer_mutex);
> - hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
> - ksym_hlist) {
> - unregister_kernel_hw_breakpoint(entry->ksym_hbp);
> - ksym_filter_entry_count--;
> - hlist_del_rcu(&(entry->ksym_hlist));
> - synchronize_rcu();
> - /* Free the 'input_string' only if reset
> - * after startup self-test
> - */
> -#ifdef CONFIG_FTRACE_SELFTEST
> - if (strncmp(entry->ksym_hbp->info.name, KSYM_SELFTEST_ENTRY,
> - strlen(KSYM_SELFTEST_ENTRY)) != 0)
> -#endif /* CONFIG_FTRACE_SELFTEST*/
> - kfree(entry->ksym_hbp->info.name);
> - kfree(entry->ksym_hbp);
> - kfree(entry);
> - }
> - mutex_unlock(&ksym_tracer_mutex);
> -}
> -
> static int ksym_trace_init(struct trace_array *tr)
> {
> int cpu, ret = 0;
>

2009-06-20 13:35:34

by K.Prasad

[permalink] [raw]
Subject: [Patch 2/3] ksym_tracer: Allow bulk removal using empty or wildcard string input - ver II

Accept an empty string or wildcard input (of the form *:---) as input for
ksym_trace_filter to perform bulk removal of all monitored entries.

Signed-off-by: K.Prasad <[email protected]>
---
kernel/trace/trace_ksym.c | 77 +++++++++++++++++++++++++---------------------
1 file changed, 43 insertions(+), 34 deletions(-)

Index: linux-2.6-tip.hbkpt/kernel/trace/trace_ksym.c
===================================================================
--- linux-2.6-tip.hbkpt.orig/kernel/trace/trace_ksym.c
+++ linux-2.6-tip.hbkpt/kernel/trace/trace_ksym.c
@@ -23,6 +23,7 @@
#include <linux/debugfs.h>
#include <linux/ftrace.h>
#include <linux/module.h>
+#include <linux/ctype.h>
#include <linux/fs.h>

#include "trace_output.h"
@@ -138,6 +139,34 @@ static int ksym_trace_get_access_type(ch
return access;
}

+static void ksym_trace_reset(struct trace_array *tr)
+{
+ struct trace_ksym *entry;
+ struct hlist_node *node, *node1;
+
+ ksym_tracing_enabled = 0;
+
+ mutex_lock(&ksym_tracer_mutex);
+ hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
+ ksym_hlist) {
+ unregister_kernel_hw_breakpoint(entry->ksym_hbp);
+ ksym_filter_entry_count--;
+ hlist_del_rcu(&(entry->ksym_hlist));
+ synchronize_rcu();
+ /* Free the 'input_string' only if reset
+ * after startup self-test
+ */
+#ifdef CONFIG_FTRACE_SELFTEST
+ if (strncmp(entry->ksym_hbp->info.name, KSYM_SELFTEST_ENTRY,
+ strlen(KSYM_SELFTEST_ENTRY)) != 0)
+#endif /* CONFIG_FTRACE_SELFTEST*/
+ kfree(entry->ksym_hbp->info.name);
+ kfree(entry->ksym_hbp);
+ kfree(entry);
+ }
+ mutex_unlock(&ksym_tracer_mutex);
+}
+
/*
* There can be several possible malformed requests and we attempt to capture
* all of them. We enumerate some of the rules
@@ -163,7 +192,7 @@ static int parse_ksym_trace_str(char *in
/* Check for malformed request: (2), (1) and (5) */
if ((!input_string) ||
(strlen(input_string) != (KSYM_TRACER_OP_LEN + 1)) ||
- (*addr == 0))
+ ((*addr == 0) && strncmp(*ksymname, "*", strlen("*"))))
goto return_code;
ret = ksym_trace_get_access_type(input_string);

@@ -211,6 +240,7 @@ int process_new_ksym_entry(char *ksymnam
}
hlist_add_head_rcu(&(entry->ksym_hlist), &ksym_filter_head);
ksym_filter_entry_count++;
+ ksym_tracing_enabled = 1;

return 0;
}
@@ -220,7 +250,7 @@ static ssize_t ksym_trace_filter_read(st
{
struct trace_ksym *entry;
struct hlist_node *node;
- char buf[KSYM_FILTER_ENTRY_LEN * KSYM_TRACER_MAX];
+ char buf[KSYM_FILTER_ENTRY_LEN * KSYM_TRACER_MAX] = "\0";
ssize_t ret, cnt = 0;

mutex_lock(&ksym_tracer_mutex);
@@ -251,10 +281,6 @@ static ssize_t ksym_trace_filter_write(s
unsigned long ksym_addr = 0;
int ret, op, changed = 0;

- /* Ignore echo "" > ksym_trace_filter */
- if (count == 0)
- return 0;
-
input_string = kzalloc(count, GFP_KERNEL);
if (!input_string)
return -ENOMEM;
@@ -263,12 +289,23 @@ static ssize_t ksym_trace_filter_write(s
kfree(input_string);
return -EFAULT;
}
+ /* Clear all breakpoint requests if echo "" > ksym_trace_filter */
+ if ((count == 1) && !isalnum(input_string[0])) {
+ ksym_trace_reset(NULL);
+ return count;
+ }

ret = op = parse_ksym_trace_str(input_string, &ksymname, &ksym_addr);
if (ret < 0) {
kfree(input_string);
return ret;
}
+ /* Clear all breakpoints if echo "*:---" > ksym_trace_filter */
+ if ((strncmp(ksymname, "*", strlen("*")) == 0) && (op == 0)) {
+ ksym_trace_reset(NULL);
+ kfree(input_string);
+ return count;
+ }

mutex_lock(&ksym_tracer_mutex);

@@ -325,34 +362,6 @@ static const struct file_operations ksym
.write = ksym_trace_filter_write,
};

-static void ksym_trace_reset(struct trace_array *tr)
-{
- struct trace_ksym *entry;
- struct hlist_node *node, *node1;
-
- ksym_tracing_enabled = 0;
-
- mutex_lock(&ksym_tracer_mutex);
- hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
- ksym_hlist) {
- unregister_kernel_hw_breakpoint(entry->ksym_hbp);
- ksym_filter_entry_count--;
- hlist_del_rcu(&(entry->ksym_hlist));
- synchronize_rcu();
- /* Free the 'input_string' only if reset
- * after startup self-test
- */
-#ifdef CONFIG_FTRACE_SELFTEST
- if (strncmp(entry->ksym_hbp->info.name, KSYM_SELFTEST_ENTRY,
- strlen(KSYM_SELFTEST_ENTRY)) != 0)
-#endif /* CONFIG_FTRACE_SELFTEST*/
- kfree(entry->ksym_hbp->info.name);
- kfree(entry->ksym_hbp);
- kfree(entry);
- }
- mutex_unlock(&ksym_tracer_mutex);
-}
-
static int ksym_trace_init(struct trace_array *tr)
{
int cpu, ret = 0;

2009-06-20 13:38:17

by K.Prasad

[permalink] [raw]
Subject: Re: [Patch 2/3] ksym_tracer: Allow bulk removal using empty or wildcard string input

On Sat, Jun 20, 2009 at 01:16:41AM +0200, Frederic Weisbecker wrote:
> On Fri, Jun 19, 2009 at 10:55:12PM +0530, K.Prasad wrote:
> > Accept an empty string or wildcard input (of the form *:---) as input for
> > ksym_trace_filter to perform bulk removal of all monitored entries.
> >
> > Signed-off-by: K.Prasad <[email protected]>
> > ---
> > kernel/trace/trace_ksym.c | 75 +++++++++++++++++++++++++---------------------
> > 1 file changed, 42 insertions(+), 33 deletions(-)
> >
<snipped>
> > /*
> > * There can be several possible malformed requests and we attempt to capture
> > * all of them. We enumerate some of the rules
> > @@ -163,7 +191,7 @@ static int parse_ksym_trace_str(char *in
> > /* Check for malformed request: (2), (1) and (5) */
> > if ((!input_string) ||
> > (strlen(input_string) != (KSYM_TRACER_OP_LEN + 1)) ||
> > - (*addr == 0))
> > + ((*addr == 0) && strncmp(*ksymname, "*", strlen("*"))))
>
>
> I guess you can just use strcmp() here, no? As in other use
> of this same strncmp() in this patch.
>

I see both functions being used in the kernel at random (what happened
to all the buffer-overflow scare?)! Isn't an strncmp() preferred over
the plain strcmp() (atleast it cannot be the other way round)?

> > @@ -251,9 +280,11 @@ static ssize_t ksym_trace_filter_write(s
> > unsigned long ksym_addr = 0;
> > int ret, op, changed = 0;
> >
> > - /* Ignore echo "" > ksym_trace_filter */
> > - if (count == 0)
> > - return 0;
> > + /* Clear all breakpoint requests if echo "" > ksym_trace_filter */
> > + if (count == 1) {
> > + ksym_trace_reset(NULL);
> > + return count;
> > + }
>
>
> And then if I do:
>
> echo -n 1 > ksym_trace_filter
>
> That would also clean these breakpoints?
>
> Frederic.
>

No, I did not think about this scenario and I am changing the patch to
handle such a case. Also, the value of 'count' cannot be '0' as such
inputs are ignored (e.g. echo -n "" > ksym_trace_filter is simply
ignored) and so I'm removing the check for the same.

Please find a new version of the patch sent here:
http://lkml.org/lkml/2009/6/20/73.

Thanks,
K.Prasad

2009-06-22 07:31:55

by Frederic Weisbecker

[permalink] [raw]
Subject: Re: [Patch 2/3] ksym_tracer: Allow bulk removal using empty or wildcard string input

On Sat, Jun 20, 2009 at 07:07:52PM +0530, K.Prasad wrote:
> On Sat, Jun 20, 2009 at 01:16:41AM +0200, Frederic Weisbecker wrote:
> > On Fri, Jun 19, 2009 at 10:55:12PM +0530, K.Prasad wrote:
> > > Accept an empty string or wildcard input (of the form *:---) as input for
> > > ksym_trace_filter to perform bulk removal of all monitored entries.
> > >
> > > Signed-off-by: K.Prasad <[email protected]>
> > > ---
> > > kernel/trace/trace_ksym.c | 75 +++++++++++++++++++++++++---------------------
> > > 1 file changed, 42 insertions(+), 33 deletions(-)
> > >
> <snipped>
> > > /*
> > > * There can be several possible malformed requests and we attempt to capture
> > > * all of them. We enumerate some of the rules
> > > @@ -163,7 +191,7 @@ static int parse_ksym_trace_str(char *in
> > > /* Check for malformed request: (2), (1) and (5) */
> > > if ((!input_string) ||
> > > (strlen(input_string) != (KSYM_TRACER_OP_LEN + 1)) ||
> > > - (*addr == 0))
> > > + ((*addr == 0) && strncmp(*ksymname, "*", strlen("*"))))
> >
> >
> > I guess you can just use strcmp() here, no? As in other use
> > of this same strncmp() in this patch.
> >
>
> I see both functions being used in the kernel at random (what happened
> to all the buffer-overflow scare?)! Isn't an strncmp() preferred over
> the plain strcmp() (atleast it cannot be the other way round)?


I guess it depends if the string has complicated origins :)
But a plain 1 for the len would be sufficient.
Or here you can just check **ksymname != '*'

Anyway, I'm arguing about neat things that don't matter that much.

Thanks.

> > > @@ -251,9 +280,11 @@ static ssize_t ksym_trace_filter_write(s
> > > unsigned long ksym_addr = 0;
> > > int ret, op, changed = 0;
> > >
> > > - /* Ignore echo "" > ksym_trace_filter */
> > > - if (count == 0)
> > > - return 0;
> > > + /* Clear all breakpoint requests if echo "" > ksym_trace_filter */
> > > + if (count == 1) {
> > > + ksym_trace_reset(NULL);
> > > + return count;
> > > + }
> >
> >
> > And then if I do:
> >
> > echo -n 1 > ksym_trace_filter
> >
> > That would also clean these breakpoints?
> >
> > Frederic.
> >
>
> No, I did not think about this scenario and I am changing the patch to
> handle such a case. Also, the value of 'count' cannot be '0' as such
> inputs are ignored (e.g. echo -n "" > ksym_trace_filter is simply
> ignored) and so I'm removing the check for the same.
>
> Please find a new version of the patch sent here:
> http://lkml.org/lkml/2009/6/20/73.
>
> Thanks,
> K.Prasad
>
>

2009-06-23 14:30:20

by Frederic Weisbecker

[permalink] [raw]
Subject: Re: [Patch 2/3] ksym_tracer: Allow bulk removal using empty or wildcard string input - ver II

On Sat, Jun 20, 2009 at 07:05:07PM +0530, K.Prasad wrote:
> Accept an empty string or wildcard input (of the form *:---) as input for
> ksym_trace_filter to perform bulk removal of all monitored entries.
>
> Signed-off-by: K.Prasad <[email protected]>
> ---
> kernel/trace/trace_ksym.c | 77 +++++++++++++++++++++++++---------------------
> 1 file changed, 43 insertions(+), 34 deletions(-)
>
> Index: linux-2.6-tip.hbkpt/kernel/trace/trace_ksym.c
> ===================================================================
> --- linux-2.6-tip.hbkpt.orig/kernel/trace/trace_ksym.c
> +++ linux-2.6-tip.hbkpt/kernel/trace/trace_ksym.c
> @@ -23,6 +23,7 @@
> #include <linux/debugfs.h>
> #include <linux/ftrace.h>
> #include <linux/module.h>
> +#include <linux/ctype.h>
> #include <linux/fs.h>
>
> #include "trace_output.h"
> @@ -138,6 +139,34 @@ static int ksym_trace_get_access_type(ch
> return access;
> }
>
> +static void ksym_trace_reset(struct trace_array *tr)
> +{
> + struct trace_ksym *entry;
> + struct hlist_node *node, *node1;
> +
> + ksym_tracing_enabled = 0;
> +
> + mutex_lock(&ksym_tracer_mutex);
> + hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
> + ksym_hlist) {
> + unregister_kernel_hw_breakpoint(entry->ksym_hbp);
> + ksym_filter_entry_count--;
> + hlist_del_rcu(&(entry->ksym_hlist));
> + synchronize_rcu();
> + /* Free the 'input_string' only if reset
> + * after startup self-test
> + */
> +#ifdef CONFIG_FTRACE_SELFTEST
> + if (strncmp(entry->ksym_hbp->info.name, KSYM_SELFTEST_ENTRY,
> + strlen(KSYM_SELFTEST_ENTRY)) != 0)
> +#endif /* CONFIG_FTRACE_SELFTEST*/
> + kfree(entry->ksym_hbp->info.name);
> + kfree(entry->ksym_hbp);
> + kfree(entry);
> + }
> + mutex_unlock(&ksym_tracer_mutex);
> +}
> +
> /*
> * There can be several possible malformed requests and we attempt to capture
> * all of them. We enumerate some of the rules
> @@ -163,7 +192,7 @@ static int parse_ksym_trace_str(char *in
> /* Check for malformed request: (2), (1) and (5) */
> if ((!input_string) ||
> (strlen(input_string) != (KSYM_TRACER_OP_LEN + 1)) ||
> - (*addr == 0))
> + ((*addr == 0) && strncmp(*ksymname, "*", strlen("*"))))
> goto return_code;
> ret = ksym_trace_get_access_type(input_string);
>
> @@ -211,6 +240,7 @@ int process_new_ksym_entry(char *ksymnam
> }
> hlist_add_head_rcu(&(entry->ksym_hlist), &ksym_filter_head);
> ksym_filter_entry_count++;
> + ksym_tracing_enabled = 1;
>
> return 0;
> }
> @@ -220,7 +250,7 @@ static ssize_t ksym_trace_filter_read(st
> {
> struct trace_ksym *entry;
> struct hlist_node *node;
> - char buf[KSYM_FILTER_ENTRY_LEN * KSYM_TRACER_MAX];
> + char buf[KSYM_FILTER_ENTRY_LEN * KSYM_TRACER_MAX] = "\0";
> ssize_t ret, cnt = 0;
>
> mutex_lock(&ksym_tracer_mutex);
> @@ -251,10 +281,6 @@ static ssize_t ksym_trace_filter_write(s
> unsigned long ksym_addr = 0;
> int ret, op, changed = 0;
>
> - /* Ignore echo "" > ksym_trace_filter */
> - if (count == 0)
> - return 0;
> -
> input_string = kzalloc(count, GFP_KERNEL);
> if (!input_string)
> return -ENOMEM;
> @@ -263,12 +289,23 @@ static ssize_t ksym_trace_filter_write(s
> kfree(input_string);
> return -EFAULT;
> }
> + /* Clear all breakpoint requests if echo "" > ksym_trace_filter */
> + if ((count == 1) && !isalnum(input_string[0])) {
> + ksym_trace_reset(NULL);
> + return count;
> + }
>
> ret = op = parse_ksym_trace_str(input_string, &ksymname, &ksym_addr);
> if (ret < 0) {
> kfree(input_string);
> return ret;
> }
> + /* Clear all breakpoints if echo "*:---" > ksym_trace_filter */
> + if ((strncmp(ksymname, "*", strlen("*")) == 0) && (op == 0)) {


If you returned -EINVAL above,


if (*ksymname == '*' && !op)

..would be shorter

Also that doesn't check if symname = "*something:---"



> + ksym_trace_reset(NULL);
> + kfree(input_string);
> + return count;
> + }
>
> mutex_lock(&ksym_tracer_mutex);
>
> @@ -325,34 +362,6 @@ static const struct file_operations ksym
> .write = ksym_trace_filter_write,
> };
>
> -static void ksym_trace_reset(struct trace_array *tr)
> -{
> - struct trace_ksym *entry;
> - struct hlist_node *node, *node1;
> -
> - ksym_tracing_enabled = 0;
> -
> - mutex_lock(&ksym_tracer_mutex);
> - hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
> - ksym_hlist) {
> - unregister_kernel_hw_breakpoint(entry->ksym_hbp);
> - ksym_filter_entry_count--;
> - hlist_del_rcu(&(entry->ksym_hlist));
> - synchronize_rcu();
> - /* Free the 'input_string' only if reset
> - * after startup self-test
> - */
> -#ifdef CONFIG_FTRACE_SELFTEST
> - if (strncmp(entry->ksym_hbp->info.name, KSYM_SELFTEST_ENTRY,
> - strlen(KSYM_SELFTEST_ENTRY)) != 0)
> -#endif /* CONFIG_FTRACE_SELFTEST*/
> - kfree(entry->ksym_hbp->info.name);
> - kfree(entry->ksym_hbp);
> - kfree(entry);
> - }
> - mutex_unlock(&ksym_tracer_mutex);
> -}
> -
> static int ksym_trace_init(struct trace_array *tr)
> {
> int cpu, ret = 0;