Skip to content

Commit 86303fb

Browse files
tracing: Switch trace_osnoise.c code over to use guard() and __free()
JIRA: https://issues.redhat.com/browse/RHEL-117874 commit 930d2b3 Author: Steven Rostedt <[email protected]> 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 <[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]> Signed-off-by: Tomas Glozar <[email protected]>
1 parent ed1b672 commit 86303fb

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
@@ -2073,26 +2073,21 @@ static void osnoise_hotplug_workfn(struct work_struct *dummy)
20732073
{
20742074
unsigned int cpu = smp_processor_id();
20752075

2076-
mutex_lock(&trace_types_lock);
2076+
guard(mutex)(&trace_types_lock);
20772077

20782078
if (!osnoise_has_registered_instances())
2079-
goto out_unlock_trace;
2079+
return;
20802080

2081-
mutex_lock(&interface_lock);
2082-
cpus_read_lock();
2081+
guard(mutex)(&interface_lock);
2082+
guard(cpus_read_lock)();
20832083

20842084
if (!cpu_online(cpu))
2085-
goto out_unlock;
2085+
return;
2086+
20862087
if (!cpumask_test_cpu(cpu, &osnoise_cpumask))
2087-
goto out_unlock;
2088+
return;
20882089

20892090
start_kthread(cpu);
2090-
2091-
out_unlock:
2092-
cpus_read_unlock();
2093-
mutex_unlock(&interface_lock);
2094-
out_unlock_trace:
2095-
mutex_unlock(&trace_types_lock);
20962091
}
20972092

20982093
static DECLARE_WORK(osnoise_hotplug_work, osnoise_hotplug_workfn);
@@ -2290,31 +2285,22 @@ static ssize_t
22902285
osnoise_cpus_read(struct file *filp, char __user *ubuf, size_t count,
22912286
loff_t *ppos)
22922287
{
2293-
char *mask_str;
2288+
char *mask_str __free(kfree) = NULL;
22942289
int len;
22952290

2296-
mutex_lock(&interface_lock);
2291+
guard(mutex)(&interface_lock);
22972292

22982293
len = snprintf(NULL, 0, "%*pbl\n", cpumask_pr_args(&osnoise_cpumask)) + 1;
22992294
mask_str = kmalloc(len, GFP_KERNEL);
2300-
if (!mask_str) {
2301-
count = -ENOMEM;
2302-
goto out_unlock;
2303-
}
2295+
if (!mask_str)
2296+
return -ENOMEM;
23042297

23052298
len = snprintf(mask_str, len, "%*pbl\n", cpumask_pr_args(&osnoise_cpumask));
2306-
if (len >= count) {
2307-
count = -EINVAL;
2308-
goto out_free;
2309-
}
2299+
if (len >= count)
2300+
return -EINVAL;
23102301

23112302
count = simple_read_from_buffer(ubuf, count, ppos, mask_str, len);
23122303

2313-
out_free:
2314-
kfree(mask_str);
2315-
out_unlock:
2316-
mutex_unlock(&interface_lock);
2317-
23182304
return count;
23192305
}
23202306

0 commit comments

Comments
 (0)