Skip to content

Commit 12d5189

Browse files
committed
tracing: Use __free(kfree) in trace.c to remove gotos
There's a couple of locations that have goto out in trace.c for the only purpose of freeing a variable that was allocated. These can be replaced with __free(kfree). Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Link: https://lore.kernel.org/20250801203858.040892777@kernel.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent debe57f commit 12d5189

1 file changed

Lines changed: 12 additions & 24 deletions

File tree

kernel/trace/trace.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5042,7 +5042,7 @@ tracing_cpumask_read(struct file *filp, char __user *ubuf,
50425042
size_t count, loff_t *ppos)
50435043
{
50445044
struct trace_array *tr = file_inode(filp)->i_private;
5045-
char *mask_str;
5045+
char *mask_str __free(kfree) = NULL;
50465046
int len;
50475047

50485048
len = snprintf(NULL, 0, "%*pb\n",
@@ -5053,16 +5053,10 @@ tracing_cpumask_read(struct file *filp, char __user *ubuf,
50535053

50545054
len = snprintf(mask_str, len, "%*pb\n",
50555055
cpumask_pr_args(tr->tracing_cpumask));
5056-
if (len >= count) {
5057-
count = -EINVAL;
5058-
goto out_err;
5059-
}
5060-
count = simple_read_from_buffer(ubuf, count, ppos, mask_str, len);
5061-
5062-
out_err:
5063-
kfree(mask_str);
5056+
if (len >= count)
5057+
return -EINVAL;
50645058

5065-
return count;
5059+
return simple_read_from_buffer(ubuf, count, ppos, mask_str, len);
50665060
}
50675061

50685062
int tracing_set_cpumask(struct trace_array *tr,
@@ -10739,7 +10733,8 @@ ssize_t trace_parse_run_command(struct file *file, const char __user *buffer,
1073910733
size_t count, loff_t *ppos,
1074010734
int (*createfn)(const char *))
1074110735
{
10742-
char *kbuf, *buf, *tmp;
10736+
char *kbuf __free(kfree) = NULL;
10737+
char *buf, *tmp;
1074310738
int ret = 0;
1074410739
size_t done = 0;
1074510740
size_t size;
@@ -10754,10 +10749,9 @@ ssize_t trace_parse_run_command(struct file *file, const char __user *buffer,
1075410749
if (size >= WRITE_BUFSIZE)
1075510750
size = WRITE_BUFSIZE - 1;
1075610751

10757-
if (copy_from_user(kbuf, buffer + done, size)) {
10758-
ret = -EFAULT;
10759-
goto out;
10760-
}
10752+
if (copy_from_user(kbuf, buffer + done, size))
10753+
return -EFAULT;
10754+
1076110755
kbuf[size] = '\0';
1076210756
buf = kbuf;
1076310757
do {
@@ -10773,8 +10767,7 @@ ssize_t trace_parse_run_command(struct file *file, const char __user *buffer,
1077310767
/* This can accept WRITE_BUFSIZE - 2 ('\n' + '\0') */
1077410768
pr_warn("Line length is too long: Should be less than %d\n",
1077510769
WRITE_BUFSIZE - 2);
10776-
ret = -EINVAL;
10777-
goto out;
10770+
return -EINVAL;
1077810771
}
1077910772
}
1078010773
done += size;
@@ -10787,17 +10780,12 @@ ssize_t trace_parse_run_command(struct file *file, const char __user *buffer,
1078710780

1078810781
ret = createfn(buf);
1078910782
if (ret)
10790-
goto out;
10783+
return ret;
1079110784
buf += size;
1079210785

1079310786
} while (done < count);
1079410787
}
10795-
ret = done;
10796-
10797-
out:
10798-
kfree(kbuf);
10799-
10800-
return ret;
10788+
return done;
1080110789
}
1080210790

1080310791
#ifdef CONFIG_TRACER_MAX_TRACE

0 commit comments

Comments
 (0)