Skip to content

Commit 567f698

Browse files
committed
tracing: Embed replace_filter_string() helper function
The replace_filter_string() frees the current string and then copies a given string. But in the two locations that it was used, the allocation happened right after the filter was allocated (nothing to replace). There's no need for this to be a helper function. Embedding the allocation in the two places where it was called will make changing the code in the future easier. Also make the variable consistent (always use "filter_string" as the name, as it was used in one instance as "filter_str") Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 404a3ad commit 567f698

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

kernel/trace/trace_events_filter.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -664,17 +664,6 @@ static void remove_filter_string(struct event_filter *filter)
664664
filter->filter_string = NULL;
665665
}
666666

667-
static int replace_filter_string(struct event_filter *filter,
668-
char *filter_string)
669-
{
670-
kfree(filter->filter_string);
671-
filter->filter_string = kstrdup(filter_string, GFP_KERNEL);
672-
if (!filter->filter_string)
673-
return -ENOMEM;
674-
675-
return 0;
676-
}
677-
678667
static void append_filter_err(struct filter_parse_state *ps,
679668
struct event_filter *filter)
680669
{
@@ -1802,9 +1791,8 @@ static int replace_system_preds(struct trace_subsystem_dir *dir,
18021791
if (!filter)
18031792
goto fail_mem;
18041793

1805-
/* Can only fail on no memory */
1806-
err = replace_filter_string(filter, filter_string);
1807-
if (err)
1794+
filter->filter_string = kstrdup(filter_string, GFP_KERNEL);
1795+
if (!filter->filter_string)
18081796
goto fail_mem;
18091797

18101798
err = replace_preds(file->event_call, filter, ps, false);
@@ -1868,7 +1856,7 @@ static int replace_system_preds(struct trace_subsystem_dir *dir,
18681856
return -ENOMEM;
18691857
}
18701858

1871-
static int create_filter_start(char *filter_str, bool set_str,
1859+
static int create_filter_start(char *filter_string, bool set_str,
18721860
struct filter_parse_state **psp,
18731861
struct event_filter **filterp)
18741862
{
@@ -1880,8 +1868,11 @@ static int create_filter_start(char *filter_str, bool set_str,
18801868

18811869
/* allocate everything, and if any fails, free all and fail */
18821870
filter = kzalloc(sizeof(*filter), GFP_KERNEL);
1883-
if (filter && set_str)
1884-
err = replace_filter_string(filter, filter_str);
1871+
if (filter && set_str) {
1872+
filter->filter_string = kstrdup(filter_string, GFP_KERNEL);
1873+
if (!filter->filter_string)
1874+
err = -ENOMEM;
1875+
}
18851876

18861877
ps = kzalloc(sizeof(*ps), GFP_KERNEL);
18871878

@@ -1895,7 +1886,7 @@ static int create_filter_start(char *filter_str, bool set_str,
18951886
*filterp = filter;
18961887
*psp = ps;
18971888

1898-
parse_init(ps, filter_ops, filter_str);
1889+
parse_init(ps, filter_ops, filter_string);
18991890
err = filter_parse(ps);
19001891
if (err && set_str)
19011892
append_filter_err(ps, filter);

0 commit comments

Comments
 (0)