Skip to content

Commit 930d2b3

Browse files
committed
tracing: Switch trace_osnoise.c code over to use guard() and __free()
The osnoise_hotplug_workfn() grabs two mutexes and cpu_read_lock(). It has various gotos to handle unlocking them. Switch them over to guard() and let the compiler worry about it. The osnoise_cpus_read() has a temporary mask_str allocated and there's some gotos to make sure it gets freed on error paths. Switch that over to __free() to let the compiler worry about it. Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent a2e27e1 commit 930d2b3

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

kernel/trace/trace_osnoise.c

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,26 +2083,21 @@ static void osnoise_hotplug_workfn(struct work_struct *dummy)
20832083
{
20842084
unsigned int cpu = smp_processor_id();
20852085

2086-
mutex_lock(&trace_types_lock);
2086+
guard(mutex)(&trace_types_lock);
20872087

20882088
if (!osnoise_has_registered_instances())
2089-
goto out_unlock_trace;
2089+
return;
20902090

2091-
mutex_lock(&interface_lock);
2092-
cpus_read_lock();
2091+
guard(mutex)(&interface_lock);
2092+
guard(cpus_read_lock)();
20932093

20942094
if (!cpu_online(cpu))
2095-
goto out_unlock;
2095+
return;
2096+
20962097
if (!cpumask_test_cpu(cpu, &osnoise_cpumask))
2097-
goto out_unlock;
2098+
return;
20982099

20992100
start_kthread(cpu);
2100-
2101-
out_unlock:
2102-
cpus_read_unlock();
2103-
mutex_unlock(&interface_lock);
2104-
out_unlock_trace:
2105-
mutex_unlock(&trace_types_lock);
21062101
}
21072102

21082103
static DECLARE_WORK(osnoise_hotplug_work, osnoise_hotplug_workfn);
@@ -2300,31 +2295,22 @@ static ssize_t
23002295
osnoise_cpus_read(struct file *filp, char __user *ubuf, size_t count,
23012296
loff_t *ppos)
23022297
{
2303-
char *mask_str;
2298+
char *mask_str __free(kfree) = NULL;
23042299
int len;
23052300

2306-
mutex_lock(&interface_lock);
2301+
guard(mutex)(&interface_lock);
23072302

23082303
len = snprintf(NULL, 0, "%*pbl\n", cpumask_pr_args(&osnoise_cpumask)) + 1;
23092304
mask_str = kmalloc(len, GFP_KERNEL);
2310-
if (!mask_str) {
2311-
count = -ENOMEM;
2312-
goto out_unlock;
2313-
}
2305+
if (!mask_str)
2306+
return -ENOMEM;
23142307

23152308
len = snprintf(mask_str, len, "%*pbl\n", cpumask_pr_args(&osnoise_cpumask));
2316-
if (len >= count) {
2317-
count = -EINVAL;
2318-
goto out_free;
2319-
}
2309+
if (len >= count)
2310+
return -EINVAL;
23202311

23212312
count = simple_read_from_buffer(ubuf, count, ppos, mask_str, len);
23222313

2323-
out_free:
2324-
kfree(mask_str);
2325-
out_unlock:
2326-
mutex_unlock(&interface_lock);
2327-
23282314
return count;
23292315
}
23302316

0 commit comments

Comments
 (0)