]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
tracepoint: Optimize the critical region of mutex_lock in tracepoint_module_coming()
authorZhen Lei <thunder.leizhen@huawei.com>
Wed, 14 Sep 2022 06:14:16 +0000 (14:14 +0800)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Mon, 26 Sep 2022 17:01:18 +0000 (13:01 -0400)
The memory allocation of 'tp_mod' does not require mutex_lock()
protection, move it out.

Link: https://lkml.kernel.org/r/20220914061416.1630-1-thunder.leizhen@huawei.com
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/tracepoint.c

index ef42c1a1192053cc05b45ccb61358a4996453add..f23144af5743048ead3c3c800ce596f4cb050ae9 100644 (file)
@@ -640,7 +640,6 @@ static void tp_module_going_check_quiescent(struct tracepoint *tp, void *priv)
 static int tracepoint_module_coming(struct module *mod)
 {
        struct tp_module *tp_mod;
-       int ret = 0;
 
        if (!mod->num_tracepoints)
                return 0;
@@ -652,19 +651,18 @@ static int tracepoint_module_coming(struct module *mod)
         */
        if (trace_module_has_bad_taint(mod))
                return 0;
-       mutex_lock(&tracepoint_module_list_mutex);
+
        tp_mod = kmalloc(sizeof(struct tp_module), GFP_KERNEL);
-       if (!tp_mod) {
-               ret = -ENOMEM;
-               goto end;
-       }
+       if (!tp_mod)
+               return -ENOMEM;
        tp_mod->mod = mod;
+
+       mutex_lock(&tracepoint_module_list_mutex);
        list_add_tail(&tp_mod->list, &tracepoint_module_list);
        blocking_notifier_call_chain(&tracepoint_notify_list,
                        MODULE_STATE_COMING, tp_mod);
-end:
        mutex_unlock(&tracepoint_module_list_mutex);
-       return ret;
+       return 0;
 }
 
 static void tracepoint_module_going(struct module *mod)