All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Cromie <jim.cromie@gmail.com>
To: jbaron@akamai.com, linux-kernel@vger.kernel.org,
	akpm@linuxfoundation.org, gregkh@linuxfoundation.org
Cc: linux@rasmusvillemoes.dk, Jim Cromie <jim.cromie@gmail.com>
Subject: [PATCH v5 15/18] dyndbg: combine flags & mask into a struct, simplify with it
Date: Sun, 19 Jul 2020 17:10:55 -0600	[thread overview]
Message-ID: <20200719231058.1586423-16-jim.cromie@gmail.com> (raw)
In-Reply-To: <20200719231058.1586423-1-jim.cromie@gmail.com>

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

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 lib/dynamic_debug.c | 45 ++++++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index fad6c34c930d..c983049e986d 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -62,6 +62,11 @@ struct ddebug_iter {
 	unsigned int idx;
 };
 
+struct flag_settings {
+	unsigned int flags;
+	unsigned int mask;
+};
+
 static DEFINE_MUTEX(ddebug_lock);
 static LIST_HEAD(ddebug_tables);
 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.
  */
 static int ddebug_change(const struct ddebug_query *query,
-			unsigned int flags, unsigned int mask)
+			 struct flag_settings *modifiers)
 {
 	int i;
 	struct ddebug_table *dt;
@@ -190,14 +195,14 @@ static int ddebug_change(const struct ddebug_query *query,
 
 			nfound++;
 
-			newflags = (dp->flags & mask) | flags;
+			newflags = (dp->flags & modifiers->mask) | modifiers->flags;
 			if (newflags == dp->flags)
 				continue;
 #ifdef CONFIG_JUMP_LABEL
 			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);
-			} else if (flags & _DPRINTK_FLAGS_PRINT)
+			} else if (modifiers->flags & _DPRINTK_FLAGS_PRINT)
 				static_branch_enable(&dp->key.dd_key_true);
 #endif
 			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
  * or <0 on error.
  */
-static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
-			       unsigned int *maskp)
+static int ddebug_parse_flags(const char *str, struct flag_settings *modifiers)
 {
-	unsigned flags = 0;
-	int op = '=', i;
+	int op, i;
 
 	switch (*str) {
 	case '+':
@@ -452,7 +455,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
 	for (; *str ; ++str) {
 		for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
 			if (*str == opt_array[i].opt_char) {
-				flags |= opt_array[i].flag;
+				modifiers->flags |= opt_array[i].flag;
 				break;
 			}
 		}
@@ -461,30 +464,30 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
 			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) {
 	case '=':
-		*maskp = 0;
-		*flagsp = flags;
+		/* modifiers->flags already set */
+		modifiers->mask = 0;
 		break;
 	case '+':
-		*maskp = ~0U;
-		*flagsp = flags;
+		modifiers->mask = ~0U;
 		break;
 	case '-':
-		*maskp = ~flags;
-		*flagsp = 0;
+		modifiers->mask = ~modifiers->flags;
+		modifiers->flags = 0;
 		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;
 }
 
 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 = {};
 #define MAXWORDS 9
 	int nwords, nfound;
@@ -496,7 +499,7 @@ static int ddebug_exec_query(char *query_string, const char *modname)
 		return -EINVAL;
 	}
 	/* 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");
 		return -EINVAL;
 	}
@@ -505,7 +508,7 @@ static int ddebug_exec_query(char *query_string, const char *modname)
 		return -EINVAL;
 	}
 	/* 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");
 
 	return nfound;
-- 
2.26.2


  parent reply	other threads:[~2020-07-19 23:11 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-19 23:10 [PATCH v5 00/18] dynamic_debug fixes, cleanups, features, export Jim Cromie
2020-07-19 23:10 ` [PATCH v5 01/18] dyndbg-docs: eschew file /full/path query in docs Jim Cromie
2020-07-19 23:10 ` [PATCH v5 02/18] dyndbg-docs: initialization is done early, not arch Jim Cromie
2020-07-19 23:10 ` [PATCH v5 03/18] dyndbg: drop obsolete comment on ddebug_proc_open Jim Cromie
2020-07-19 23:10 ` [PATCH v5 04/18] dyndbg: refine debug verbosity; 1 is basic, 2 more chatty Jim Cromie
2020-07-19 23:10 ` [PATCH v5 05/18] dyndbg: rename __verbose section to __dyndbg Jim Cromie
2020-07-19 23:10 ` [PATCH v5 06/18] dyndbg: fix overcounting of ram used by dyndbg Jim Cromie
2020-07-19 23:10 ` [PATCH v5 07/18] dyndbg: fix a BUG_ON in ddebug_describe_flags Jim Cromie
2020-07-19 23:10 ` [PATCH v5 08/18] dyndbg: fix pr_err with empty string Jim Cromie
2020-07-19 23:10 ` [PATCH v5 09/18] dyndbg: prefer declarative init in caller, to memset in callee Jim Cromie
2020-07-19 23:10 ` [PATCH v5 10/18] dyndbg: make ddebug_tables list LIFO for add/remove_module Jim Cromie
2020-07-19 23:10 ` [PATCH v5 11/18] dyndbg: use gcc ?: to reduce word count Jim Cromie
2020-07-19 23:10 ` [PATCH v5 12/18] dyndbg: refactor parse_linerange out of ddebug_parse_query Jim Cromie
2020-07-19 23:10 ` [PATCH v5 13/18] dyndbg: accept 'file foo.c:func1' and 'file foo.c:10-100' Jim Cromie
2020-07-19 23:10 ` [PATCH v5 14/18] dyndbg: accept query terms like file=bar and module=foo Jim Cromie
2020-07-19 23:10 ` Jim Cromie [this message]
2020-07-19 23:10 ` [PATCH v5 16/18] dyndbg: allow anchored match on format query term Jim Cromie
2020-07-19 23:10 ` [PATCH v5 17/18] dyndbg: shorten our logging prefix, drop __func__ Jim Cromie
2020-07-19 23:10 ` [PATCH v5 18/18] dyndbg: export ddebug_exec_queries Jim Cromie
2020-07-24 13:48 ` [PATCH v5 00/18] dynamic_debug fixes, cleanups, features, export Jason Baron
2020-07-24 14:59   ` Greg KH
2020-07-24 15:00     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200719231058.1586423-16-jim.cromie@gmail.com \
    --to=jim.cromie@gmail.com \
    --cc=akpm@linuxfoundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jbaron@akamai.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.