]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - lib/dynamic_debug.c
sparc: fix bad merge of sparc Kconfig
[karo-tx-linux.git] / lib / dynamic_debug.c
index 8fba401793056fc77db087da2384f502ac9f42cc..7ca29a0a3019685291e33a8b3df86669f9378dea 100644 (file)
@@ -338,7 +338,7 @@ static int check_set(const char **dest, char *src, char *name)
  * Returns 0 on success, <0 on error.
  */
 static int ddebug_parse_query(char *words[], int nwords,
-                              struct ddebug_query *query)
+                       struct ddebug_query *query, const char *modname)
 {
        unsigned int i;
        int rc;
@@ -348,6 +348,10 @@ static int ddebug_parse_query(char *words[], int nwords,
                return -EINVAL;
        memset(query, 0, sizeof(*query));
 
+       if (modname)
+               /* support $modname.dyndbg=<multiple queries> */
+               query->module = modname;
+
        for (i = 0 ; i < nwords ; i += 2) {
                if (!strcmp(words[i], "func"))
                        rc = check_set(&query->function, words[i+1], "func");
@@ -444,7 +448,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
        return 0;
 }
 
-static int ddebug_exec_query(char *query_string)
+static int ddebug_exec_query(char *query_string, const char *modname)
 {
        unsigned int flags = 0, mask = 0;
        struct ddebug_query query;
@@ -455,7 +459,7 @@ static int ddebug_exec_query(char *query_string)
        nwords = ddebug_tokenize(query_string, words, MAXWORDS);
        if (nwords <= 0)
                return -EINVAL;
-       if (ddebug_parse_query(words, nwords-1, &query))
+       if (ddebug_parse_query(words, nwords-1, &query, modname))
                return -EINVAL;
        if (ddebug_parse_flags(words[nwords-1], &flags, &mask))
                return -EINVAL;
@@ -471,7 +475,7 @@ static int ddebug_exec_query(char *query_string)
    last error or number of matching callsites.  Module name is either
    in param (for boot arg) or perhaps in query string.
 */
-static int ddebug_exec_queries(char *query)
+static int ddebug_exec_queries(char *query, const char *modname)
 {
        char *split;
        int i, errs = 0, exitcode = 0, rc, nfound = 0;
@@ -487,7 +491,7 @@ static int ddebug_exec_queries(char *query)
 
                vpr_info("query %d: \"%s\"\n", i, query);
 
-               rc = ddebug_exec_query(query);
+               rc = ddebug_exec_query(query, modname);
                if (rc < 0) {
                        errs++;
                        exitcode = rc;
@@ -652,7 +656,7 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
        tmpbuf[len] = '\0';
        vpr_info("read %d bytes from userspace\n", (int)len);
 
-       ret = ddebug_exec_queries(tmpbuf);
+       ret = ddebug_exec_queries(tmpbuf, NULL);
        kfree(tmpbuf);
        if (ret < 0)
                return ret;
@@ -862,39 +866,44 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
 }
 EXPORT_SYMBOL_GPL(ddebug_add_module);
 
-/* handle both dyndbg=".." and $module.dyndbg=".." params at boot */
-static int ddebug_dyndbg_boot_param_cb(char *param, char *val,
-                               const char *unused)
+/* helper for ddebug_dyndbg_(boot|module)_param_cb */
+static int ddebug_dyndbg_param_cb(char *param, char *val,
+                               const char *modname, int on_err)
 {
-       const char *modname = NULL;
        char *sep;
 
        sep = strchr(param, '.');
        if (sep) {
+               /* needed only for ddebug_dyndbg_boot_param_cb */
                *sep = '\0';
                modname = param;
                param = sep + 1;
        }
        if (strcmp(param, "dyndbg"))
-               return 0; /* skip all other params w/o error */
+               return on_err; /* determined by caller */
 
-       vpr_info("module: %s %s=\"%s\"\n", modname, param, val);
+       ddebug_exec_queries((val ? val : "+p"), modname);
 
-       ddebug_exec_queries(val ? val : "+p");
        return 0; /* query failure shouldnt stop module load */
 }
 
-/* handle dyndbg args to modprobe */
-int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *doing)
+/* handle both dyndbg and $module.dyndbg params at boot */
+static int ddebug_dyndbg_boot_param_cb(char *param, char *val,
+                               const char *unused)
 {
-       if (strcmp(param, "dyndbg"))
-               return -ENOENT;
-
-       vpr_info("module: %s %s=\"%s\"\n", doing, param, val);
-
-       ddebug_exec_queries((val ? val : "+p"));
+       vpr_info("%s=\"%s\"\n", param, val);
+       return ddebug_dyndbg_param_cb(param, val, NULL, 0);
+}
 
-       return 0; /* query failure shouldnt stop module load */
+/*
+ * modprobe foo finds foo.params in boot-args, strips "foo.", and
+ * passes them to load_module().  This callback gets unknown params,
+ * processes dyndbg params, rejects others.
+ */
+int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *module)
+{
+       vpr_info("module: %s %s=\"%s\"\n", module, param, val);
+       return ddebug_dyndbg_param_cb(param, val, module, -ENOENT);
 }
 
 static void ddebug_table_free(struct ddebug_table *dt)
@@ -966,7 +975,8 @@ static int __init dynamic_debug_init(void)
        const char *modname = NULL;
        char *cmdline;
        int ret = 0;
-       int n = 0;
+       int n = 0, entries = 0, modct = 0;
+       int verbose_bytes = 0;
 
        if (__start___verbose == __stop___verbose) {
                pr_warn("_ddebug table is empty in a "
@@ -977,10 +987,15 @@ static int __init dynamic_debug_init(void)
        modname = iter->modname;
        iter_start = iter;
        for (; iter < __stop___verbose; iter++) {
+               entries++;
+               verbose_bytes += strlen(iter->modname) + strlen(iter->function)
+                       + strlen(iter->filename) + strlen(iter->format);
+
                if (strcmp(modname, iter->modname)) {
+                       modct++;
                        ret = ddebug_add_module(iter_start, n, modname);
                        if (ret)
-                               goto out_free;
+                               goto out_err;
                        n = 0;
                        modname = iter->modname;
                        iter_start = iter;
@@ -989,19 +1004,24 @@ static int __init dynamic_debug_init(void)
        }
        ret = ddebug_add_module(iter_start, n, modname);
        if (ret)
-               goto out_free;
+               goto out_err;
 
-       /* ddebug_query boot param got passed -> set it up */
+       ddebug_init_success = 1;
+       vpr_info("%d modules, %d entries and %d bytes in ddebug tables,"
+               " %d bytes in (readonly) verbose section\n",
+               modct, entries, (int)( modct * sizeof(struct ddebug_table)),
+               verbose_bytes + (int)(__stop___verbose - __start___verbose));
+
+       /* apply ddebug_query boot param, dont unload tables on err */
        if (ddebug_setup_string[0] != '\0') {
-               ret = ddebug_exec_queries(ddebug_setup_string);
+               pr_warn("ddebug_query param name is deprecated,"
+                       " change it to dyndbg\n");
+               ret = ddebug_exec_queries(ddebug_setup_string, NULL);
                if (ret < 0)
                        pr_warn("Invalid ddebug boot param %s",
                                ddebug_setup_string);
                else
                        pr_info("%d changes by ddebug_query\n", ret);
-
-               /* keep tables even on ddebug_query parse error */
-               ret = 0;
        }
        /* now that ddebug tables are loaded, process all boot args
         * again to find and activate queries given in dyndbg params.
@@ -1015,16 +1035,14 @@ static int __init dynamic_debug_init(void)
        parse_args("dyndbg params", cmdline, NULL,
                   0, 0, 0, &ddebug_dyndbg_boot_param_cb);
        kfree(cmdline);
+       return 0;
 
-out_free:
-       if (ret)
-               ddebug_remove_all_tables();
-       else
-               ddebug_init_success = 1;
+out_err:
+       ddebug_remove_all_tables();
        return 0;
 }
 /* Allow early initialization for boot messages via boot param */
-arch_initcall(dynamic_debug_init);
+early_initcall(dynamic_debug_init);
 
 /* Debugfs setup must be done later */
-module_init(dynamic_debug_init_debugfs);
+fs_initcall(dynamic_debug_init_debugfs);