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>
This commit is contained in:
parent
14775b0496
commit
84da83a6ff
|
@ -62,6 +62,11 @@ struct ddebug_iter {
|
||||||
unsigned int idx;
|
unsigned int idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct flag_settings {
|
||||||
|
unsigned int flags;
|
||||||
|
unsigned int mask;
|
||||||
|
};
|
||||||
|
|
||||||
static DEFINE_MUTEX(ddebug_lock);
|
static DEFINE_MUTEX(ddebug_lock);
|
||||||
static LIST_HEAD(ddebug_tables);
|
static LIST_HEAD(ddebug_tables);
|
||||||
static int verbose;
|
static int verbose;
|
||||||
|
@ -141,7 +146,7 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
|
||||||
* logs the changes. Takes ddebug_lock.
|
* logs the changes. Takes ddebug_lock.
|
||||||
*/
|
*/
|
||||||
static int ddebug_change(const struct ddebug_query *query,
|
static int ddebug_change(const struct ddebug_query *query,
|
||||||
unsigned int flags, unsigned int mask)
|
struct flag_settings *modifiers)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct ddebug_table *dt;
|
struct ddebug_table *dt;
|
||||||
|
@ -190,14 +195,14 @@ static int ddebug_change(const struct ddebug_query *query,
|
||||||
|
|
||||||
nfound++;
|
nfound++;
|
||||||
|
|
||||||
newflags = (dp->flags & mask) | flags;
|
newflags = (dp->flags & modifiers->mask) | modifiers->flags;
|
||||||
if (newflags == dp->flags)
|
if (newflags == dp->flags)
|
||||||
continue;
|
continue;
|
||||||
#ifdef CONFIG_JUMP_LABEL
|
#ifdef CONFIG_JUMP_LABEL
|
||||||
if (dp->flags & _DPRINTK_FLAGS_PRINT) {
|
if (dp->flags & _DPRINTK_FLAGS_PRINT) {
|
||||||
if (!(flags & _DPRINTK_FLAGS_PRINT))
|
if (!(modifiers->flags & _DPRINTK_FLAGS_PRINT))
|
||||||
static_branch_disable(&dp->key.dd_key_true);
|
static_branch_disable(&dp->key.dd_key_true);
|
||||||
} else if (flags & _DPRINTK_FLAGS_PRINT)
|
} else if (modifiers->flags & _DPRINTK_FLAGS_PRINT)
|
||||||
static_branch_enable(&dp->key.dd_key_true);
|
static_branch_enable(&dp->key.dd_key_true);
|
||||||
#endif
|
#endif
|
||||||
dp->flags = newflags;
|
dp->flags = newflags;
|
||||||
|
@ -431,11 +436,9 @@ static int ddebug_parse_query(char *words[], int nwords,
|
||||||
* flags fields of matched _ddebug's. Returns 0 on success
|
* flags fields of matched _ddebug's. Returns 0 on success
|
||||||
* or <0 on error.
|
* or <0 on error.
|
||||||
*/
|
*/
|
||||||
static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
|
static int ddebug_parse_flags(const char *str, struct flag_settings *modifiers)
|
||||||
unsigned int *maskp)
|
|
||||||
{
|
{
|
||||||
unsigned flags = 0;
|
int op, i;
|
||||||
int op = '=', i;
|
|
||||||
|
|
||||||
switch (*str) {
|
switch (*str) {
|
||||||
case '+':
|
case '+':
|
||||||
|
@ -452,7 +455,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
|
||||||
for (; *str ; ++str) {
|
for (; *str ; ++str) {
|
||||||
for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
|
for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
|
||||||
if (*str == opt_array[i].opt_char) {
|
if (*str == opt_array[i].opt_char) {
|
||||||
flags |= opt_array[i].flag;
|
modifiers->flags |= opt_array[i].flag;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -461,30 +464,30 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vpr_info("flags=0x%x\n", flags);
|
vpr_info("flags=0x%x\n", modifiers->flags);
|
||||||
|
|
||||||
/* calculate final *flagsp, *maskp according to mask and op */
|
/* calculate final flags, mask based upon op */
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case '=':
|
case '=':
|
||||||
*maskp = 0;
|
/* modifiers->flags already set */
|
||||||
*flagsp = flags;
|
modifiers->mask = 0;
|
||||||
break;
|
break;
|
||||||
case '+':
|
case '+':
|
||||||
*maskp = ~0U;
|
modifiers->mask = ~0U;
|
||||||
*flagsp = flags;
|
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
*maskp = ~flags;
|
modifiers->mask = ~modifiers->flags;
|
||||||
*flagsp = 0;
|
modifiers->flags = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
vpr_info("*flagsp=0x%x *maskp=0x%x\n", *flagsp, *maskp);
|
vpr_info("*flagsp=0x%x *maskp=0x%x\n", modifiers->flags, modifiers->mask);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ddebug_exec_query(char *query_string, const char *modname)
|
static int ddebug_exec_query(char *query_string, const char *modname)
|
||||||
{
|
{
|
||||||
unsigned int flags = 0, mask = 0;
|
struct flag_settings modifiers = {};
|
||||||
struct ddebug_query query = {};
|
struct ddebug_query query = {};
|
||||||
#define MAXWORDS 9
|
#define MAXWORDS 9
|
||||||
int nwords, nfound;
|
int nwords, nfound;
|
||||||
|
@ -496,7 +499,7 @@ static int ddebug_exec_query(char *query_string, const char *modname)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
/* check flags 1st (last arg) so query is pairs of spec,val */
|
/* check flags 1st (last arg) so query is pairs of spec,val */
|
||||||
if (ddebug_parse_flags(words[nwords-1], &flags, &mask)) {
|
if (ddebug_parse_flags(words[nwords-1], &modifiers)) {
|
||||||
pr_err("flags parse failed\n");
|
pr_err("flags parse failed\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -505,7 +508,7 @@ static int ddebug_exec_query(char *query_string, const char *modname)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
/* actually go and implement the change */
|
/* actually go and implement the change */
|
||||||
nfound = ddebug_change(&query, flags, mask);
|
nfound = ddebug_change(&query, &modifiers);
|
||||||
vpr_info_dq(&query, nfound ? "applied" : "no-match");
|
vpr_info_dq(&query, nfound ? "applied" : "no-match");
|
||||||
|
|
||||||
return nfound;
|
return nfound;
|
||||||
|
|
Loading…
Reference in New Issue