Skip to content

Commit 84da83a

Browse files
jimcgregkh
authored andcommitted
dyndbg: combine flags & mask into a struct, simplify with it
flags & mask are used together everywhere, and are passed around together between multiple functions; they belong together in a struct, call that struct flag_settings. Use struct flag_settings to rework 3 functions: - ddebug_exec_query - declares query and flag-settings, calls other 2, passing flags - ddebug_parse_flags - fills flag_settings and returns - ddebug_change - test all callsites against query, modify passing sites. benefits: - bit-banging always needs flags & mask, best together. - simpler function signatures - 1 less parameter, less stack overhead no functional changes Acked-by: <jbaron@akamai.com> Signed-off-by: Jim Cromie <jim.cromie@gmail.com> Link: https://lore.kernel.org/r/20200719231058.1586423-16-jim.cromie@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 14775b0 commit 84da83a

1 file changed

Lines changed: 24 additions & 21 deletions

File tree

‎lib/dynamic_debug.c‎

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ struct ddebug_iter {
6262
unsigned int idx;
6363
};
6464

65+
struct flag_settings {
66+
unsigned int flags;
67+
unsigned int mask;
68+
};
69+
6570
static DEFINE_MUTEX(ddebug_lock);
6671
static LIST_HEAD(ddebug_tables);
6772
static int verbose;
@@ -141,7 +146,7 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
141146
* logs the changes. Takes ddebug_lock.
142147
*/
143148
static int ddebug_change(const struct ddebug_query *query,
144-
unsigned int flags, unsigned int mask)
149+
struct flag_settings *modifiers)
145150
{
146151
int i;
147152
struct ddebug_table *dt;
@@ -190,14 +195,14 @@ static int ddebug_change(const struct ddebug_query *query,
190195

191196
nfound++;
192197

193-
newflags = (dp->flags & mask) | flags;
198+
newflags = (dp->flags & modifiers->mask) | modifiers->flags;
194199
if (newflags == dp->flags)
195200
continue;
196201
#ifdef CONFIG_JUMP_LABEL
197202
if (dp->flags & _DPRINTK_FLAGS_PRINT) {
198-
if (!(flags & _DPRINTK_FLAGS_PRINT))
203+
if (!(modifiers->flags & _DPRINTK_FLAGS_PRINT))
199204
static_branch_disable(&dp->key.dd_key_true);
200-
} else if (flags & _DPRINTK_FLAGS_PRINT)
205+
} else if (modifiers->flags & _DPRINTK_FLAGS_PRINT)
201206
static_branch_enable(&dp->key.dd_key_true);
202207
#endif
203208
dp->flags = newflags;
@@ -431,11 +436,9 @@ static int ddebug_parse_query(char *words[], int nwords,
431436
* flags fields of matched _ddebug's. Returns 0 on success
432437
* or <0 on error.
433438
*/
434-
static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
435-
unsigned int *maskp)
439+
static int ddebug_parse_flags(const char *str, struct flag_settings *modifiers)
436440
{
437-
unsigned flags = 0;
438-
int op = '=', i;
441+
int op, i;
439442

440443
switch (*str) {
441444
case '+':
@@ -452,7 +455,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
452455
for (; *str ; ++str) {
453456
for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
454457
if (*str == opt_array[i].opt_char) {
455-
flags |= opt_array[i].flag;
458+
modifiers->flags |= opt_array[i].flag;
456459
break;
457460
}
458461
}
@@ -461,30 +464,30 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
461464
return -EINVAL;
462465
}
463466
}
464-
vpr_info("flags=0x%x\n", flags);
467+
vpr_info("flags=0x%x\n", modifiers->flags);
465468

466-
/* calculate final *flagsp, *maskp according to mask and op */
469+
/* calculate final flags, mask based upon op */
467470
switch (op) {
468471
case '=':
469-
*maskp = 0;
470-
*flagsp = flags;
472+
/* modifiers->flags already set */
473+
modifiers->mask = 0;
471474
break;
472475
case '+':
473-
*maskp = ~0U;
474-
*flagsp = flags;
476+
modifiers->mask = ~0U;
475477
break;
476478
case '-':
477-
*maskp = ~flags;
478-
*flagsp = 0;
479+
modifiers->mask = ~modifiers->flags;
480+
modifiers->flags = 0;
479481
break;
480482
}
481-
vpr_info("*flagsp=0x%x *maskp=0x%x\n", *flagsp, *maskp);
483+
vpr_info("*flagsp=0x%x *maskp=0x%x\n", modifiers->flags, modifiers->mask);
484+
482485
return 0;
483486
}
484487

485488
static int ddebug_exec_query(char *query_string, const char *modname)
486489
{
487-
unsigned int flags = 0, mask = 0;
490+
struct flag_settings modifiers = {};
488491
struct ddebug_query query = {};
489492
#define MAXWORDS 9
490493
int nwords, nfound;
@@ -496,7 +499,7 @@ static int ddebug_exec_query(char *query_string, const char *modname)
496499
return -EINVAL;
497500
}
498501
/* check flags 1st (last arg) so query is pairs of spec,val */
499-
if (ddebug_parse_flags(words[nwords-1], &flags, &mask)) {
502+
if (ddebug_parse_flags(words[nwords-1], &modifiers)) {
500503
pr_err("flags parse failed\n");
501504
return -EINVAL;
502505
}
@@ -505,7 +508,7 @@ static int ddebug_exec_query(char *query_string, const char *modname)
505508
return -EINVAL;
506509
}
507510
/* actually go and implement the change */
508-
nfound = ddebug_change(&query, flags, mask);
511+
nfound = ddebug_change(&query, &modifiers);
509512
vpr_info_dq(&query, nfound ? "applied" : "no-match");
510513

511514
return nfound;

0 commit comments

Comments
 (0)