Skip to content

Commit b8ccd5d

Browse files
jimcgregkh
authored andcommitted
dynamic_debug: replace if (verbose) pr_info with macro vpr_info
Use vpr_info to declutter code, reduce indenting, and change one additional pr_info call in ddebug_exec_queries. Signed-off-by: Jim Cromie <jim.cromie@gmail.com> Acked-by: Jason Baron <jbaron@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c0a6720 commit b8ccd5d

1 file changed

Lines changed: 35 additions & 46 deletions

File tree

‎lib/dynamic_debug.c‎

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,22 @@ static char *ddebug_describe_flags(struct _ddebug *dp, char *buf,
107107
return buf;
108108
}
109109

110-
#define vpr_info_dq(q, msg) \
111-
do { \
112-
if (verbose) \
113-
/* trim last char off format print */ \
114-
pr_info("%s: func=\"%s\" file=\"%s\" " \
115-
"module=\"%s\" format=\"%.*s\" " \
116-
"lineno=%u-%u", \
117-
msg, \
118-
q->function ? q->function : "", \
119-
q->filename ? q->filename : "", \
120-
q->module ? q->module : "", \
121-
(int)(q->format ? strlen(q->format) - 1 : 0), \
122-
q->format ? q->format : "", \
123-
q->first_lineno, q->last_lineno); \
110+
#define vpr_info(fmt, ...) \
111+
if (verbose) do { pr_info(fmt, ##__VA_ARGS__); } while (0)
112+
113+
#define vpr_info_dq(q, msg) \
114+
do { \
115+
/* trim last char off format print */ \
116+
vpr_info("%s: func=\"%s\" file=\"%s\" " \
117+
"module=\"%s\" format=\"%.*s\" " \
118+
"lineno=%u-%u", \
119+
msg, \
120+
q->function ? q->function : "", \
121+
q->filename ? q->filename : "", \
122+
q->module ? q->module : "", \
123+
(int)(q->format ? strlen(q->format) - 1 : 0), \
124+
q->format ? q->format : "", \
125+
q->first_lineno, q->last_lineno); \
124126
} while (0)
125127

126128
/*
@@ -180,12 +182,11 @@ static int ddebug_change(const struct ddebug_query *query,
180182
if (newflags == dp->flags)
181183
continue;
182184
dp->flags = newflags;
183-
if (verbose)
184-
pr_info("changed %s:%d [%s]%s =%s\n",
185-
trim_prefix(dp->filename), dp->lineno,
186-
dt->mod_name, dp->function,
187-
ddebug_describe_flags(dp, flagbuf,
188-
sizeof(flagbuf)));
185+
vpr_info("changed %s:%d [%s]%s =%s\n",
186+
trim_prefix(dp->filename), dp->lineno,
187+
dt->mod_name, dp->function,
188+
ddebug_describe_flags(dp, flagbuf,
189+
sizeof(flagbuf)));
189190
}
190191
}
191192
mutex_unlock(&ddebug_lock);
@@ -410,8 +411,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
410411
default:
411412
return -EINVAL;
412413
}
413-
if (verbose)
414-
pr_info("op='%c'\n", op);
414+
vpr_info("op='%c'\n", op);
415415

416416
for ( ; *str ; ++str) {
417417
for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
@@ -423,8 +423,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
423423
if (i < 0)
424424
return -EINVAL;
425425
}
426-
if (verbose)
427-
pr_info("flags=0x%x\n", flags);
426+
vpr_info("flags=0x%x\n", flags);
428427

429428
/* calculate final *flagsp, *maskp according to mask and op */
430429
switch (op) {
@@ -441,8 +440,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
441440
*flagsp = 0;
442441
break;
443442
}
444-
if (verbose)
445-
pr_info("*flagsp=0x%x *maskp=0x%x\n", *flagsp, *maskp);
443+
vpr_info("*flagsp=0x%x *maskp=0x%x\n", *flagsp, *maskp);
446444
return 0;
447445
}
448446

@@ -487,8 +485,7 @@ static int ddebug_exec_queries(char *query)
487485
if (!query || !*query || *query == '#')
488486
continue;
489487

490-
if (verbose)
491-
pr_info("query %d: \"%s\"\n", i, query);
488+
vpr_info("query %d: \"%s\"\n", i, query);
492489

493490
rc = ddebug_exec_query(query);
494491
if (rc < 0) {
@@ -498,7 +495,7 @@ static int ddebug_exec_queries(char *query)
498495
nfound += rc;
499496
i++;
500497
}
501-
pr_info("processed %d queries, with %d matches, %d errs\n",
498+
vpr_info("processed %d queries, with %d matches, %d errs\n",
502499
i, nfound, errs);
503500

504501
if (exitcode)
@@ -653,8 +650,7 @@ static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
653650
return -EFAULT;
654651
}
655652
tmpbuf[len] = '\0';
656-
if (verbose)
657-
pr_info("read %d bytes from userspace\n", (int)len);
653+
vpr_info("read %d bytes from userspace\n", (int)len);
658654

659655
ret = ddebug_exec_queries(tmpbuf);
660656
kfree(tmpbuf);
@@ -717,8 +713,7 @@ static void *ddebug_proc_start(struct seq_file *m, loff_t *pos)
717713
struct _ddebug *dp;
718714
int n = *pos;
719715

720-
if (verbose)
721-
pr_info("called m=%p *pos=%lld\n", m, (unsigned long long)*pos);
716+
vpr_info("called m=%p *pos=%lld\n", m, (unsigned long long)*pos);
722717

723718
mutex_lock(&ddebug_lock);
724719

@@ -742,9 +737,8 @@ static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
742737
struct ddebug_iter *iter = m->private;
743738
struct _ddebug *dp;
744739

745-
if (verbose)
746-
pr_info("called m=%p p=%p *pos=%lld\n",
747-
m, p, (unsigned long long)*pos);
740+
vpr_info("called m=%p p=%p *pos=%lld\n",
741+
m, p, (unsigned long long)*pos);
748742

749743
if (p == SEQ_START_TOKEN)
750744
dp = ddebug_iter_first(iter);
@@ -766,8 +760,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
766760
struct _ddebug *dp = p;
767761
char flagsbuf[10];
768762

769-
if (verbose)
770-
pr_info("called m=%p p=%p\n", m, p);
763+
vpr_info("called m=%p p=%p\n", m, p);
771764

772765
if (p == SEQ_START_TOKEN) {
773766
seq_puts(m,
@@ -791,8 +784,7 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
791784
*/
792785
static void ddebug_proc_stop(struct seq_file *m, void *p)
793786
{
794-
if (verbose)
795-
pr_info("called m=%p p=%p\n", m, p);
787+
vpr_info("called m=%p p=%p\n", m, p);
796788
mutex_unlock(&ddebug_lock);
797789
}
798790

@@ -815,8 +807,7 @@ static int ddebug_proc_open(struct inode *inode, struct file *file)
815807
struct ddebug_iter *iter;
816808
int err;
817809

818-
if (verbose)
819-
pr_info("called\n");
810+
vpr_info("called\n");
820811

821812
iter = kzalloc(sizeof(*iter), GFP_KERNEL);
822813
if (iter == NULL)
@@ -866,8 +857,7 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
866857
list_add_tail(&dt->link, &ddebug_tables);
867858
mutex_unlock(&ddebug_lock);
868859

869-
if (verbose)
870-
pr_info("%u debug prints in module %s\n", n, dt->mod_name);
860+
vpr_info("%u debug prints in module %s\n", n, dt->mod_name);
871861
return 0;
872862
}
873863
EXPORT_SYMBOL_GPL(ddebug_add_module);
@@ -888,8 +878,7 @@ int ddebug_remove_module(const char *mod_name)
888878
struct ddebug_table *dt, *nextdt;
889879
int ret = -ENOENT;
890880

891-
if (verbose)
892-
pr_info("removing module \"%s\"\n", mod_name);
881+
vpr_info("removing module \"%s\"\n", mod_name);
893882

894883
mutex_lock(&ddebug_lock);
895884
list_for_each_entry_safe(dt, nextdt, &ddebug_tables, link) {

0 commit comments

Comments
 (0)