Skip to contentSkip to conversation

zorro: fix checkpatch error by avoiding assignment in if-statement.

PATCH In review Dishank Jogi 4 participants 6 messages Jul 28, 2025 – Jul 29, 2025 m68k architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zorro: fix checkpatch error by avoiding assignment in if-statement.

These changes improve code readability and bring the file in line with the Linux kernel coding style.

No functional changes.

---
 drivers/zorro/gen-devlist.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/zorro/gen-devlist.c +4 -2
index e325c5ce995b..ff4515e02409 100644
@@ -44,7 +44,8 @@ main(void)
 
 	while (fgets(line, sizeof(line)-1, stdin)) {
 		lino++;
-		if ((c = strchr(line, '\n')))
+		c = strchr(line, '\n')
+		if (c)
 			*c = 0;
 		if (!line[0] || line[0] == '#')
 			continue;
@@ -68,7 +69,8 @@ main(void)
 					fprintf(devf, "\tPRODUCT(%s,%s,\"", manuf, line+1);
 					pq(devf, c);
 					fputs("\")\n", devf);
-				} else goto err;
+				} else
+					goto err;
 				break;
 			default:
 				goto err;
Signature · 1 line
2.43.0
#1 lore raw

Le 28/07/2025 à 11:34, Dishank Jogi a écrit :

Quoted 15 lines

These changes improve code readability and bring the file in line with the Linux kernel coding style.

No functional changes.

---
  drivers/zorro/gen-devlist.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/zorro/gen-devlist.c +0 -0
index e325c5ce995b..ff4515e02409 100644

drivers/zorro/gen-devlist.c main(void) · line 47

Quoted 5 lines
drivers/zorro/gen-devlist.c +1 -1
@@ -44,7 +44,8 @@ main(void)
 
  	while (fgets(line, sizeof(line)-1, stdin)) {
  		lino++;
-		if ((c = strchr(line, '\n')))
+		c = strchr(line, '\n')

Looks like a trailing ; is missing.

Was this patch compile-tested?

No change is trivial, even if they look so.
Please always compile test your changes.

CJ

Quoted 14 lines
drivers/zorro/gen-devlist.c +3 -1
+		if (c)
  			*c = 0;
  		if (!line[0] || line[0] == '#')
  			continue;
@@ -68,7 +69,8 @@ main(void)
  					fprintf(devf, "\tPRODUCT(%s,%s,\"", manuf, line+1);
  					pq(devf, c);
  					fputs("\")\n", devf);
-				} else goto err;
+				} else
+					goto err;
  				break;
  			default:
  				goto err;
#2 lore raw
In reply to Dishank Jogi

Hi Dishank,

Quoted 6 lines · Dishank Jogi

These changes improve code readability and bring the file in line with the Linux kernel coding style.

No functional changes.

Thanks for your patch!

drivers/zorro/gen-devlist.c main(void) · line 47

Quoted 8 lines
drivers/zorro/gen-devlist.c +1 -1
@@ -44,7 +44,8 @@ main(void)
 
        while (fgets(line, sizeof(line)-1, stdin)) {
                lino++;
-               if ((c = strchr(line, '\n')))
+               c = strchr(line, '\n')

As Christophe pointed out, this line lacks a semicolon. Please do not submit untested patches.

drivers/zorro/gen-devlist.c main(void) · line 73

Quoted 11 lines
drivers/zorro/gen-devlist.c +3 -1
+               if (c)
                        *c = 0;
                if (!line[0] || line[0] == '#')
                        continue;
@@ -68,7 +69,8 @@ main(void)
                                        fprintf(devf, "\tPRODUCT(%s,%s,\"", manuf, line+1);
                                        pq(devf, c);
                                        fputs("\")\n", devf);
-                               } else goto err;
+                               } else
+                                       goto err;

This does not comply with Linux kernel coding style: please use braces in both branches.

However, in this case I'd rather invert the logic, remove the braces, and reduce indentation for the big block:

    if (strlen(line) <= 5 || line[5] != ' ')
            goto err;

    [...]

drivers/zorro/gen-devlist.c main(void) · line 76

Quoted 3 lines
drivers/zorro/gen-devlist.c +0 -0
                                break;
                        default:
                                goto err;

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#3 lore raw

Hi,

Thank you for the suggestion.

Additionally, the conditional logic is inverted to reduce indentation and improve readability, aligning with kernel coding style.

---
 drivers/zorro/gen-devlist.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)
drivers/zorro/gen-devlist.c +9 -5
index e325c5ce995b..853619ab27df 100644
@@ -44,31 +44,32 @@ main(void)
 
        while (fgets(line, sizeof(line)-1, stdin)) {
                lino++;
-               if ((c = strchr(line, '\n')))
+               c = strchr(line, '\n');
+               if (c)
                        *c = 0;
                if (!line[0] || line[0] == '#')
                        continue;
                if (line[0] == '\t') {
                        switch (mode) {
                        case 1:
-                               if (strlen(line) > 5 && line[5] == ' ') {
-                                       c = line + 5;
-                                       while (*c == ' ')
-                                               *c++ = 0;
+                               if (strlen(line) <= 5 || line[5] != ' ')
+                                       goto err;
+                               c = line + 5;
+                               while (*c == ' ')
+                                       *c++ = 0;
+                               if (manuf_len + strlen(c) + 1 > MAX_NAME_SIZE) {
+                                       /* Too long, try cutting off

long description */
+ bra = strchr(c, '[');
+ if (bra && bra > c && bra[-1] == ' ')
+ bra[-1] = 0;
if (manuf_len + strlen(c) + 1

Quoted 1 line

MAX_NAME_SIZE) {

- /* Too long, try
cutting off long description */
- bra = strchr(c, '[');
- if (bra && bra > c &&
bra[-1] == ' ')
- bra[-1] = 0;
- if (manuf_len +
strlen(c) + 1 > MAX_NAME_SIZE) {
-
fprintf(stderr, "Line %d: Product name too long\n", lino);
- return 1;
- }
+ fprintf(stderr, "Line
%d: Product name too long\n", lino);

+                                               return 1;
                                        }

- fprintf(devf,
"\tPRODUCT(%s,%s,\"", manuf, line+1);
- pq(devf, c);
- fputs("\")\n", devf);

-                               } else goto err;
+                               }
+                               fprintf(devf, "\tPRODUCT(%s,%s,\"",
manuf, line+1);
+                               pq(devf, c);
+                               fputs("\")\n", devf);
                                break;
                        default:
                                goto err;
Quoted 62 lines · Geert Uytterhoeven

Hi Dishank,

Quoted 6 lines · Dishank Jogi

These changes improve code readability and bring the file in line with the Linux kernel coding style.

No functional changes.

Thanks for your patch!

drivers/zorro/gen-devlist.c main(void) · line 47

Quoted 8 lines
drivers/zorro/gen-devlist.c +1 -1
@@ -44,7 +44,8 @@ main(void)
 
        while (fgets(line, sizeof(line)-1, stdin)) {
                lino++;
-               if ((c = strchr(line, '\n')))
+               c = strchr(line, '\n')

As Christophe pointed out, this line lacks a semicolon. Please do not submit untested patches.

drivers/zorro/gen-devlist.c main(void) · line 73

Quoted 11 lines
drivers/zorro/gen-devlist.c +3 -1
+               if (c)
                        *c = 0;
                if (!line[0] || line[0] == '#')
                        continue;
@@ -68,7 +69,8 @@ main(void)
                                        fprintf(devf, "\tPRODUCT(%s,%s,\"", manuf, line+1);
                                        pq(devf, c);
                                        fputs("\")\n", devf);
-                               } else goto err;
+                               } else
+                                       goto err;

This does not comply with Linux kernel coding style: please use braces in both branches.

However, in this case I'd rather invert the logic, remove the braces, and reduce indentation for the big block:

    if (strlen(line) <= 5 || line[5] != ' ')
            goto err;

    [...]

drivers/zorro/gen-devlist.c main(void) · line 76

Quoted 3 lines
drivers/zorro/gen-devlist.c +0 -0
                                break;
                        default:
                                goto err;

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#4 lore raw

Hi Jogi,

Quoted 7 lines · Jogi Dishank

Hi,

Thank you for the suggestion.

Additionally, the conditional logic is inverted to reduce indentation and improve readability, aligning with kernel coding style.

Thanks, but this is not how you send a v2. Please read Documentation/process/submitting-patches.rst.

Quoted 1 line

Unless I am mistaken, Christophe merely pointed out a bug in your first submission, he did not suggest this patch.

Quoted 1 line

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#5 lore raw
In reply to Dishank Jogi
kernel test robot noticed the following build errors:

Hi Dishank,

kernel test robot noticed the following build errors:

[auto build test ERROR on geert-m68k/for-next]
[also build test ERROR on gerg-m68knommu/for-next geert-m68k/for-linus linus/master v6.16 next-20250729] [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/Dishank-Jogi/zorro-fix-checkpatch-error-by-avoiding-assignment-in-if-statement/20250728-173702
base:   https://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git for-next
patch link:    https://lore.kernel.org/r/20250728093412.48065-1-jogidishank503%40gmail.com
patch subject: [PATCH] zorro: fix checkpatch error by avoiding assignment in if-statement.
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20250729/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250729/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/zorro/gen-devlist.c: In function 'main':

>> drivers/zorro/gen-devlist.c:47:39: error: expected ';' before 'if'
      47 |                 c = strchr(line, '\n')
         |                                       ^
         |                                       ;
      48 |                 if (c)
         |                 ~~                     

vim +47 drivers/zorro/gen-devlist.c

    28	
    29	int
    30	main(void)
    31	{
    32		char line[1024], *c, *bra, manuf[8];
    33		int manufs = 0;
    34		int mode = 0;
    35		int lino = 0;
    36		int manuf_len = 0;
    37		FILE *devf;
    38	
    39		devf = fopen("devlist.h", "w");
    40		if (!devf) {
    41			fprintf(stderr, "Cannot create output file!\n");
    42			return 1;
    43		}
    44	
    45		while (fgets(line, sizeof(line)-1, stdin)) {
    46			lino++;
  > 47			c = strchr(line, '\n')
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki