diff mbox series

[v2,1/1] mtd: slram: insert break after errors in parsing the map

Message ID 20240711234319.637824-1-mtodorovac69@gmail.com
State Accepted
Headers show
Series [v2,1/1] mtd: slram: insert break after errors in parsing the map | expand

Commit Message

Mirsad Todorovac July 11, 2024, 11:43 p.m. UTC
GCC 12.3.0 compiler on linux-next next-20240709 tree found the execution
path in which, due to lazy evaluation, devlength isn't initialised with the
parsed string:

   289		while (map) {
   290			devname = devstart = devlength = NULL;
   291
   292			if (!(devname = strsep(&map, ","))) {
   293				E("slram: No devicename specified.\n");
   294				break;
   295			}
   296			T("slram: devname = %s\n", devname);
   297			if ((!map) || (!(devstart = strsep(&map, ",")))) {
   298				E("slram: No devicestart specified.\n");
   299			}
   300			T("slram: devstart = %s\n", devstart);
 → 301			if ((!map) || (!(devlength = strsep(&map, ",")))) {
   302				E("slram: No devicelength / -end specified.\n");
   303			}
 → 304			T("slram: devlength = %s\n", devlength);
   305			if (parse_cmdline(devname, devstart, devlength) != 0) {
   306				return(-EINVAL);
   307			}

Parsing should be finished after map == NULL, so a break is best inserted after
each E("slram: ... \n") error message.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Vignesh Raghavendra <vigneshr@ti.com>
Cc: linux-mtd@lists.infradead.org
Signed-off-by: Mirsad Todorovac <mtodorovac69@gmail.com>
---
v1:
 initial patch proposal.

v2:
 re-sent using git send-email + oauth2 (fixing T-Bird TAB problem).

 drivers/mtd/devices/slram.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Miquel Raynal Aug. 23, 2024, 5:33 p.m. UTC | #1
On Thu, 2024-07-11 at 23:43:20 UTC, Mirsad Todorovac wrote:
> GCC 12.3.0 compiler on linux-next next-20240709 tree found the execution
> path in which, due to lazy evaluation, devlength isn't initialised with the
> parsed string:
> 
>    289		while (map) {
>    290			devname = devstart = devlength = NULL;
>    291
>    292			if (!(devname = strsep(&map, ","))) {
>    293				E("slram: No devicename specified.\n");
>    294				break;
>    295			}
>    296			T("slram: devname = %s\n", devname);
>    297			if ((!map) || (!(devstart = strsep(&map, ",")))) {
>    298				E("slram: No devicestart specified.\n");
>    299			}
>    300			T("slram: devstart = %s\n", devstart);
>  → 301			if ((!map) || (!(devlength = strsep(&map, ",")))) {
>    302				E("slram: No devicelength / -end specified.\n");
>    303			}
>  → 304			T("slram: devlength = %s\n", devlength);
>    305			if (parse_cmdline(devname, devstart, devlength) != 0) {
>    306				return(-EINVAL);
>    307			}
> 
> Parsing should be finished after map == NULL, so a break is best inserted after
> each E("slram: ... \n") error message.
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: Miquel Raynal <miquel.raynal@bootlin.com>
> Cc: Richard Weinberger <richard@nod.at>
> Cc: Vignesh Raghavendra <vigneshr@ti.com>
> Cc: linux-mtd@lists.infradead.org
> Signed-off-by: Mirsad Todorovac <mtodorovac69@gmail.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel
diff mbox series

Patch

diff --git a/drivers/mtd/devices/slram.c b/drivers/mtd/devices/slram.c
index 28131a127d06..8297b366a066 100644
--- a/drivers/mtd/devices/slram.c
+++ b/drivers/mtd/devices/slram.c
@@ -296,10 +296,12 @@  static int __init init_slram(void)
 		T("slram: devname = %s\n", devname);
 		if ((!map) || (!(devstart = strsep(&map, ",")))) {
 			E("slram: No devicestart specified.\n");
+			break;
 		}
 		T("slram: devstart = %s\n", devstart);
 		if ((!map) || (!(devlength = strsep(&map, ",")))) {
 			E("slram: No devicelength / -end specified.\n");
+			break;
 		}
 		T("slram: devlength = %s\n", devlength);
 		if (parse_cmdline(devname, devstart, devlength) != 0) {