Skip to content

Commit df47f38

Browse files
tracing: Switch trace_osnoise.c code over to use guard() and __free()
JIRA: https://issues.redhat.com/browse/RHEL-117873 commit 930d2b3 Author: Steven Rostedt <rostedt@goodmis.org> Date: Wed Dec 25 17:25:41 2024 -0500 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 <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/20241225222931.517329690@goodmis.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Tomas Glozar <tglozar@redhat.com>
1 parent 3934997 commit df47f38

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
@@ -2066,26 +2066,21 @@ static void osnoise_hotplug_workfn(struct work_struct *dummy)
20662066
{
20672067
unsigned int cpu = smp_processor_id();
20682068

2069-
mutex_lock(&trace_types_lock);
2069+
guard(mutex)(&trace_types_lock);
20702070

20712071
if (!osnoise_has_registered_instances())
2072-
goto out_unlock_trace;
2072+
return;
20732073

2074-
mutex_lock(&interface_lock);
2075-
cpus_read_lock();
2074+
guard(mutex)(&interface_lock);
2075+
guard(cpus_read_lock)();
20762076

20772077
if (!cpu_online(cpu))
2078-
goto out_unlock;
2078+
return;
2079+
20792080
if (!cpumask_test_cpu(cpu, &osnoise_cpumask))
2080-
goto out_unlock;
2081+
return;
20812082

20822083
start_kthread(cpu);
2083-
2084-
out_unlock:
2085-
cpus_read_unlock();
2086-
mutex_unlock(&interface_lock);
2087-
out_unlock_trace:
2088-
mutex_unlock(&trace_types_lock);
20892084
}
20902085

20912086
static DECLARE_WORK(osnoise_hotplug_work, osnoise_hotplug_workfn);
@@ -2283,31 +2278,22 @@ static ssize_t
22832278
osnoise_cpus_read(struct file *filp, char __user *ubuf, size_t count,
22842279
loff_t *ppos)
22852280
{
2286-
char *mask_str;
2281+
char *mask_str __free(kfree) = NULL;
22872282
int len;
22882283

2289-
mutex_lock(&interface_lock);
2284+
guard(mutex)(&interface_lock);
22902285

22912286
len = snprintf(NULL, 0, "%*pbl\n", cpumask_pr_args(&osnoise_cpumask)) + 1;
22922287
mask_str = kmalloc(len, GFP_KERNEL);
2293-
if (!mask_str) {
2294-
count = -ENOMEM;
2295-
goto out_unlock;
2296-
}
2288+
if (!mask_str)
2289+
return -ENOMEM;
22972290

22982291
len = snprintf(mask_str, len, "%*pbl\n", cpumask_pr_args(&osnoise_cpumask));
2299-
if (len >= count) {
2300-
count = -EINVAL;
2301-
goto out_free;
2302-
}
2292+
if (len >= count)
2293+
return -EINVAL;
23032294

23042295
count = simple_read_from_buffer(ubuf, count, ppos, mask_str, len);
23052296

2306-
out_free:
2307-
kfree(mask_str);
2308-
out_unlock:
2309-
mutex_unlock(&interface_lock);
2310-
23112297
return count;
23122298
}
23132299

0 commit comments

Comments
 (0)