Skip to content

Commit a2d375e

Browse files
jimcgregkh
authored andcommitted
dyndbg: refine export, rename to dynamic_debug_exec_queries()
commit 4c0d778 ("dyndbg: export ddebug_exec_queries") had a few problems: - broken non DYNAMIC_DEBUG_CORE configs, sparse warning - the exported function modifies query string, breaks on RO strings. - func name follows internal convention, shouldn't be exposed as is. 1st is fixed in header with ifdefd function prototype or stub defn. Also remove an obsolete HAVE-symbol ifdef-comment, and add others. Fix others by wrapping existing internal function with a new one, named in accordance with module-prefix naming convention, before export hits v5.9.0. In new function, copy query string to a local buffer, so users can pass hard-coded/RO queries, and internal function can be used unchanged. Fixes: 4c0d778 ("dyndbg: export ddebug_exec_queries") Signed-off-by: Jim Cromie <jim.cromie@gmail.com> Link: https://lore.kernel.org/r/20200831182210.850852-3-jim.cromie@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b52a95e commit a2d375e

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

include/linux/dynamic_debug.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ struct _ddebug {
4949

5050

5151
#if defined(CONFIG_DYNAMIC_DEBUG_CORE)
52+
53+
/* exported for module authors to exercise >control */
54+
int dynamic_debug_exec_queries(const char *query, const char *modname);
55+
5256
int ddebug_add_module(struct _ddebug *tab, unsigned int n,
5357
const char *modname);
5458
extern int ddebug_remove_module(const char *mod_name);
@@ -105,7 +109,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
105109
static_branch_unlikely(&descriptor.key.dd_key_false)
106110
#endif
107111

108-
#else /* !HAVE_JUMP_LABEL */
112+
#else /* !CONFIG_JUMP_LABEL */
109113

110114
#define _DPRINTK_KEY_INIT
111115

@@ -117,7 +121,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
117121
unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)
118122
#endif
119123

120-
#endif
124+
#endif /* CONFIG_JUMP_LABEL */
121125

122126
#define __dynamic_func_call(id, fmt, func, ...) do { \
123127
DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \
@@ -172,10 +176,11 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
172176
KERN_DEBUG, prefix_str, prefix_type, \
173177
rowsize, groupsize, buf, len, ascii)
174178

175-
#else
179+
#else /* !CONFIG_DYNAMIC_DEBUG_CORE */
176180

177181
#include <linux/string.h>
178182
#include <linux/errno.h>
183+
#include <linux/printk.h>
179184

180185
static inline int ddebug_add_module(struct _ddebug *tab, unsigned int n,
181186
const char *modname)
@@ -210,6 +215,13 @@ static inline int ddebug_dyndbg_module_param_cb(char *param, char *val,
210215
print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, \
211216
rowsize, groupsize, buf, len, ascii); \
212217
} while (0)
213-
#endif
218+
219+
static inline int dynamic_debug_exec_queries(const char *query, const char *modname)
220+
{
221+
pr_warn("kernel not built with CONFIG_DYNAMIC_DEBUG_CORE\n");
222+
return 0;
223+
}
224+
225+
#endif /* !CONFIG_DYNAMIC_DEBUG_CORE */
214226

215227
#endif

lib/dynamic_debug.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ static int ddebug_exec_query(char *query_string, const char *modname)
525525
last error or number of matching callsites. Module name is either
526526
in param (for boot arg) or perhaps in query string.
527527
*/
528-
int ddebug_exec_queries(char *query, const char *modname)
528+
static int ddebug_exec_queries(char *query, const char *modname)
529529
{
530530
char *split;
531531
int i, errs = 0, exitcode = 0, rc, nfound = 0;
@@ -557,7 +557,30 @@ int ddebug_exec_queries(char *query, const char *modname)
557557
return exitcode;
558558
return nfound;
559559
}
560-
EXPORT_SYMBOL_GPL(ddebug_exec_queries);
560+
561+
/**
562+
* dynamic_debug_exec_queries - select and change dynamic-debug prints
563+
* @query: query-string described in admin-guide/dynamic-debug-howto
564+
* @modname: string containing module name, usually &module.mod_name
565+
*
566+
* This uses the >/proc/dynamic_debug/control reader, allowing module
567+
* authors to modify their dynamic-debug callsites. The modname is
568+
* canonically struct module.mod_name, but can also be null or a
569+
* module-wildcard, for example: "drm*".
570+
*/
571+
int dynamic_debug_exec_queries(const char *query, const char *modname)
572+
{
573+
int rc;
574+
char *qry = kstrndup(query, PAGE_SIZE, GFP_KERNEL);
575+
576+
if (!query)
577+
return -ENOMEM;
578+
579+
rc = ddebug_exec_queries(qry, modname);
580+
kfree(qry);
581+
return rc;
582+
}
583+
EXPORT_SYMBOL_GPL(dynamic_debug_exec_queries);
561584

562585
#define PREFIX_SIZE 64
563586

0 commit comments

Comments
 (0)