linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] block: Replaced simple_strtol() with kstrtoint()/kstrtoul()
@ 2021-05-24 12:08 Liu Shixin
  0 siblings, 0 replies; only message in thread
From: Liu Shixin @ 2021-05-24 12:08 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, linux-kernel, Liu Shixin

The simple_strtol() function is deprecated in some situation since
it does not check for the range overflow. Use kstrtoint()/kstrtoul()
instead.
Attention, if the end of the input string isn't '\n', simple_strtol() will
ignore following characters and return the value but kstrtoint()/kstrtoul()
will return an error code.

Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
 drivers/block/brd.c  | 3 +--
 drivers/block/loop.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 7562cf30b14e..5b43f6b2d506 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -358,8 +358,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);
 }
 __setup("ramdisk_size=", ramdisk_size);
 #endif
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index d58d68f3c7cd..9fe595afa9cf 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -2415,8 +2415,7 @@ module_exit(loop_exit);
 #ifndef MODULE
 static int __init max_loop_setup(char *str)
 {
-	max_loop = simple_strtol(str, NULL, 0);
-	return 1;
+	return !kstrtoint(str, 0, &max_loop);
 }
 
 __setup("max_loop=", max_loop_setup);
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-24 11:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-24 12:08 [PATCH -next] block: Replaced simple_strtol() with kstrtoint()/kstrtoul() Liu Shixin

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).