]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
brd: replace simple_strtol with kstrtoul in ramdisk_size
authorThorsten Blum <thorsten.blum@linux.dev>
Sat, 20 Dec 2025 23:59:23 +0000 (00:59 +0100)
committerJens Axboe <axboe@kernel.dk>
Sun, 28 Dec 2025 22:54:38 +0000 (15:54 -0700)
Replace simple_strtol() with the recommended kstrtoul() for parsing the
'ramdisk_size=' boot parameter. Unlike simple_strtol(), which returns a
long, kstrtoul() converts the string directly to an unsigned long and
avoids implicit casting.

Check the return value of kstrtoul() and reject invalid values. This
adds error handling while preserving behavior for existing values, and
removes use of the deprecated simple_strtol() helper. The current code
silently sets 'rd_size = 0' if parsing fails, instead of leaving the
default value (CONFIG_BLK_DEV_RAM_SIZE) unchanged.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/brd.c

index 9778259b30d4aa3eea63f3204156ef779f3f0e9a..a5104cf96609c2064ef9db7c4123a26100f4133e 100644 (file)
@@ -247,8 +247,7 @@ MODULE_ALIAS("rd");
 /* Legacy boot options - nonmodular */
 static int __init ramdisk_size(char *str)
 {
-       rd_size = simple_strtol(str, NULL, 0);
-       return 1;
+       return kstrtoul(str, 0, &rd_size) == 0;
 }
 __setup("ramdisk_size=", ramdisk_size);
 #endif