Skip to content

Commit a2e27e1

Browse files
committed
tracing: Switch trace_events_synth.c code over to use guard()
There are a couple functions in trace_events_synth.c that have "goto out" or equivalent on error in order to release locks that were taken. This can be error prone or just simply make the code more complex. Switch every location that ends with unlocking a mutex on error over to using the guard(mutex)() infrastructure to let the compiler worry about releasing locks. This makes the code easier to read and understand. 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 076796f commit a2e27e1

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

kernel/trace/trace_events_synth.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,11 @@ static char *last_cmd;
4949

5050
static int errpos(const char *str)
5151
{
52-
int ret = 0;
53-
54-
mutex_lock(&lastcmd_mutex);
52+
guard(mutex)(&lastcmd_mutex);
5553
if (!str || !last_cmd)
56-
goto out;
54+
return 0;
5755

58-
ret = err_pos(last_cmd, str);
59-
out:
60-
mutex_unlock(&lastcmd_mutex);
61-
return ret;
56+
return err_pos(last_cmd, str);
6257
}
6358

6459
static void last_cmd_set(const char *str)
@@ -74,14 +69,12 @@ static void last_cmd_set(const char *str)
7469

7570
static void synth_err(u8 err_type, u16 err_pos)
7671
{
77-
mutex_lock(&lastcmd_mutex);
72+
guard(mutex)(&lastcmd_mutex);
7873
if (!last_cmd)
79-
goto out;
74+
return;
8075

8176
tracing_log_err(NULL, "synthetic_events", last_cmd, err_text,
8277
err_type, err_pos);
83-
out:
84-
mutex_unlock(&lastcmd_mutex);
8578
}
8679

8780
static int create_synth_event(const char *raw_command);

0 commit comments

Comments
 (0)