* [PATCH] brd: replace simple_strtol with kstrtoul in ramdisk_size
@ 2025-12-20 23:59 Thorsten Blum
2025-12-28 16:27 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-12-20 23:59 UTC (permalink / raw)
To: Jens Axboe; +Cc: Thorsten Blum, linux-block, linux-kernel
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>
---
drivers/block/brd.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 9778259b30d4..a5104cf96609 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -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
--
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] brd: replace simple_strtol with kstrtoul in ramdisk_size
2025-12-20 23:59 [PATCH] brd: replace simple_strtol with kstrtoul in ramdisk_size Thorsten Blum
@ 2025-12-28 16:27 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2025-12-28 16:27 UTC (permalink / raw)
To: Thorsten Blum; +Cc: linux-block, linux-kernel
On Sun, 21 Dec 2025 00:59:23 +0100, Thorsten Blum wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] brd: replace simple_strtol with kstrtoul in ramdisk_size
commit: 44b8a74a16101bd710f97c46a8f1d3078e0518f5
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-12-28 16:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-20 23:59 [PATCH] brd: replace simple_strtol with kstrtoul in ramdisk_size Thorsten Blum
2025-12-28 16:27 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).