[PATCH 11/13] kdb: Abstract out parsing for mdWcN

Douglas Anderson posted 13 patches 1 year, 6 months ago
[PATCH 11/13] kdb: Abstract out parsing for mdWcN
Posted by Douglas Anderson 1 year, 6 months ago
We'd like to use the "WcN" parsing for some other "md"
variants. Abstract it out.

Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

 kernel/debug/kdb/kdb_main.c | 55 +++++++++++++++++++++++++++++++------
 1 file changed, 46 insertions(+), 9 deletions(-)

diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
index 6dcbf4ea4bcd..1a37c9bb505c 100644
--- a/kernel/debug/kdb/kdb_main.c
+++ b/kernel/debug/kdb/kdb_main.c
@@ -1591,6 +1591,49 @@ static void kdb_md_line(const char *fmtstr, unsigned long addr,
 
 #define KDB_MD_BYTES_PER_LINE	16
 
+/**
+ * kdb_md_parse_arg0() - Parse argv[0] for "md" command
+ *
+ * @cmd:         The name of the command, like "md"
+ * @arg0:        The value of argv[0].
+ * @repeat:      If argv0 modifies repeat count we'll adjust here.
+ * @bytesperword Ifargv0 modifies bytesperword we'll adjust here.
+ *
+ * Return: true if this was a valid cmd; false otherwise.
+ */
+static bool kdb_md_parse_arg0(const char *cmd, const char *arg0,
+			      int *repeat, int *bytesperword)
+{
+	int cmdlen = strlen(cmd);
+
+	/* arg0 must _start_ with the command string or it's a no-go. */
+	if (strncmp(cmd, arg0, cmdlen) != 0)
+		return false;
+
+	/* If it's just the base command, we're done and it's good. */
+	if (arg0[cmdlen] == '\0')
+		return true;
+
+	/*
+	 * The first byte after the base command must be bytes per word, a
+	 * digit. The actual value of bytesperword will be validated later.
+	 */
+	if (!isdigit(arg0[cmdlen]))
+		return false;
+	*bytesperword = (int)(arg0[cmdlen] - '0');
+	cmdlen++;
+
+	/* After the bytes per word must be end of string or a 'c'. */
+	if (arg0[cmdlen] == '\0')
+		return true;
+	if (arg0[cmdlen] != 'c')
+		return false;
+	cmdlen++;
+
+	/* After the "c" is the repeat. */
+	return kstrtouint(arg0 + cmdlen, 10, repeat) == 0;
+}
+
 static int kdb_md(int argc, const char **argv)
 {
 	static unsigned long last_addr;
@@ -1608,19 +1651,13 @@ static int kdb_md(int argc, const char **argv)
 	kdbgetintenv("RADIX", &radix);
 	kdbgetintenv("BYTESPERWORD", &bytesperword);
 
-	if (isdigit(argv[0][2])) {
-		bytesperword = (int)(argv[0][2] - '0');
-		if (!argv[0][3])
-			valid = true;
-		else if (argv[0][3] == 'c' && argv[0][4])
-			valid = kstrtouint(argv[0] + 4, 10, &repeat) == 0;
-	} else if (strcmp(argv[0], "md") == 0)
+	if (kdb_md_parse_arg0("md", argv[0], &repeat, &bytesperword))
 		valid = true;
 	else if (strcmp(argv[0], "mds") == 0)
 		valid = true;
-	else if (strcmp(argv[0], "mdp") == 0) {
+	else if (strcmp(argv[0], "mdp") == 0)
 		phys = valid = true;
-	}
+
 	if (!valid)
 		return KDB_NOTFOUND;
 
-- 
2.45.2.627.g7a2c4fd464-goog
Re: [PATCH 11/13] kdb: Abstract out parsing for mdWcN
Posted by kernel test robot 1 year, 6 months ago
Hi Douglas,

kernel test robot noticed the following build warnings:

[auto build test WARNING on v6.10-rc4]
[also build test WARNING on linus/master next-20240618]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Douglas-Anderson/kdb-Get-rid-of-minlen-for-the-md-command/20240618-084245
base:   v6.10-rc4
patch link:    https://lore.kernel.org/r/20240617173426.11.I899d035485269f5110a3323fbb1680fbba718e4c%40changeid
patch subject: [PATCH 11/13] kdb: Abstract out parsing for mdWcN
config: arc-randconfig-001-20240619 (https://download.01.org/0day-ci/archive/20240619/202406190433.U3alc3Xi-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240619/202406190433.U3alc3Xi-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202406190433.U3alc3Xi-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> kernel/debug/kdb/kdb_main.c:1606: warning: Function parameter or struct member 'bytesperword' not described in 'kdb_md_parse_arg0'


vim +1606 kernel/debug/kdb/kdb_main.c

  1593	
  1594	/**
  1595	 * kdb_md_parse_arg0() - Parse argv[0] for "md" command
  1596	 *
  1597	 * @cmd:         The name of the command, like "md"
  1598	 * @arg0:        The value of argv[0].
  1599	 * @repeat:      If argv0 modifies repeat count we'll adjust here.
  1600	 * @bytesperword Ifargv0 modifies bytesperword we'll adjust here.
  1601	 *
  1602	 * Return: true if this was a valid cmd; false otherwise.
  1603	 */
  1604	static bool kdb_md_parse_arg0(const char *cmd, const char *arg0,
  1605				      int *repeat, int *bytesperword)
> 1606	{
  1607		int cmdlen = strlen(cmd);
  1608	
  1609		/* arg0 must _start_ with the command string or it's a no-go. */
  1610		if (strncmp(cmd, arg0, cmdlen) != 0)
  1611			return false;
  1612	
  1613		/* If it's just the base command, we're done and it's good. */
  1614		if (arg0[cmdlen] == '\0')
  1615			return true;
  1616	
  1617		/*
  1618		 * The first byte after the base command must be bytes per word, a
  1619		 * digit. The actual value of bytesperword will be validated later.
  1620		 */
  1621		if (!isdigit(arg0[cmdlen]))
  1622			return false;
  1623		*bytesperword = (int)(arg0[cmdlen] - '0');
  1624		cmdlen++;
  1625	
  1626		/* After the bytes per word must be end of string or a 'c'. */
  1627		if (arg0[cmdlen] == '\0')
  1628			return true;
  1629		if (arg0[cmdlen] != 'c')
  1630			return false;
  1631		cmdlen++;
  1632	
  1633		/* After the "c" is the repeat. */
  1634		return kstrtouint(arg0 + cmdlen, 10, repeat) == 0;
  1635	}
  1636	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki