ftrace: Deal with error return code of the ftrace_process_locs() function
authorYuntao Wang <ytcoode@gmail.com>
Thu, 20 Jan 2022 06:59:49 +0000 (06:59 +0000)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Fri, 27 May 2022 01:12:59 +0000 (21:12 -0400)
The ftrace_process_locs() function may return -ENOMEM error code, which
should be handled by the callers.

Link: https://lkml.kernel.org/r/20220120065949.1813231-1-ytcoode@gmail.com
Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
kernel/trace/ftrace.c

index 6c5b126..737e895 100644 (file)
@@ -6864,11 +6864,16 @@ void ftrace_module_enable(struct module *mod)
 
 void ftrace_module_init(struct module *mod)
 {
+       int ret;
+
        if (ftrace_disabled || !mod->num_ftrace_callsites)
                return;
 
-       ftrace_process_locs(mod, mod->ftrace_callsites,
-                           mod->ftrace_callsites + mod->num_ftrace_callsites);
+       ret = ftrace_process_locs(mod, mod->ftrace_callsites,
+                                 mod->ftrace_callsites + mod->num_ftrace_callsites);
+       if (ret)
+               pr_warn("ftrace: failed to allocate entries for module '%s' functions\n",
+                       mod->name);
 }
 
 static void save_ftrace_mod_rec(struct ftrace_mod_map *mod_map,
@@ -7201,15 +7206,19 @@ void __init ftrace_init(void)
        pr_info("ftrace: allocating %ld entries in %ld pages\n",
                count, count / ENTRIES_PER_PAGE + 1);
 
-       last_ftrace_enabled = ftrace_enabled = 1;
-
        ret = ftrace_process_locs(NULL,
                                  __start_mcount_loc,
                                  __stop_mcount_loc);
+       if (ret) {
+               pr_warn("ftrace: failed to allocate entries for functions\n");
+               goto failed;
+       }
 
        pr_info("ftrace: allocated %ld pages with %ld groups\n",
                ftrace_number_of_pages, ftrace_number_of_groups);
 
+       last_ftrace_enabled = ftrace_enabled = 1;
+
        set_ftrace_early_filters();
 
        return;