watchdog: use kstrtouint to parse softlockup_panic=
Subsystems (3)
PATCH 1/2 watchdog: use kstrtouint to parse softlockup_panic=
simple_strtoul() is deprecated. Replace it with kstrtouint(), which also reports parse errors back to the boot process instead of silently accepting garbage.
--- kernel/watchdog.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/watchdog.c +5 -2
@@ -17,6 +17,7 @@#include <linux/irq.h> #include <linux/irqdesc.h> #include <linux/kernel_stat.h> +#include <linux/kstrtox.h> #include <linux/kvm_para.h> #include <linux/math64.h> #include <linux/mm.h>
@@ -422,8 +423,10 @@ static unsigned long soft_lockup_nmi_warn;static int __init softlockup_panic_setup (char *str) { - softlockup_panic =simple_strtoul (str,NULL ,0 ); -return 1 ; +int ret; + + ret =kstrtouint (str,0 , &softlockup_panic); +return ret ? ret :1 ; }__setup ("softlockup_panic=" , softlockup_panic_setup);
Signature · 1 line
2.53.0
Guenter Roeck
maintainerQuoted 23 lines · 林濬哲
simple_strtoul()is deprecated. Replace it withkstrtouint(), which also reports parse errors back to the boot process instead of silently accepting garbage.Signed-off-by 林濬哲 <[email protected]>Assisted-by AI coding assistant (disclosed per kernel AI guidelines)--- kernel/watchdog.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/watchdog.c +1
-0@@ -17,6 +17,7 @@#include <linux/irq.h> #include <linux/irqdesc.h> #include <linux/kernel_stat.h> +#include <linux/kstrtox.h> #include <linux/kvm_para.h> #include <linux/math64.h> #include <linux/mm.h>
kernel/watchdog.c static unsigned long soft_lockup_nmi_warn; · line 429
Quoted 9 lines
kernel/watchdog.c +4
-2@@ -422,8 +423,10 @@ static unsigned long soft_lockup_nmi_warn;static int __init softlockup_panic_setup (char *str) { - softlockup_panic =simple_strtoul (str,NULL ,0 ); -return 1 ; +int ret; + + ret =kstrtouint (str,0 , &softlockup_panic); +return ret ? ret :1 ;
Please read the documentation (or ask your AI to do it).
/*
* NOTE: __setup functions return values:
* @fn returns 1 (or non-zero) if the option argument is "handled"
* and returns 0 if the option argument is "not handled". */
There is no means to "reports parse errors back to the boot process" from __setup functions.
Guenter
PATCH v2 1/2 watchdog: use kstrtouint to parse softlockup_panic=
simple_strtoul() is deprecated. Replace it with kstrtouint(). A bad value now leaves the variable unchanged and produces a warning, instead of being silently clamped.
__setup() handlers return whether they handled the option; there is no way to propagate parse errors, so the handler simply returns 1.
v2: warn on a bad value and return 1 instead of returning the parse
error, which __setup() handlers cannot do (Guenter Roeck).
--- kernel/watchdog.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/watchdog.c +6 -1
@@ -17,6 +17,7 @@#include <linux/irq.h> #include <linux/irqdesc.h> #include <linux/kernel_stat.h> +#include <linux/kstrtox.h> #include <linux/kvm_para.h> #include <linux/math64.h> #include <linux/mm.h>
@@ -422,7 +423,11 @@ static unsigned long soft_lockup_nmi_warn;static int __init softlockup_panic_setup (char *str) { - softlockup_panic =simple_strtoul (str,NULL ,0 ); +int ret; + + ret =kstrtouint (str,0 , &softlockup_panic); +if (ret) +pr_warn ("softlockup_panic: bad option string '%s'\n" , str);return 1 ; }__setup ("softlockup_panic=" , softlockup_panic_setup);
Signature · 1 line
2.54.0.windows.1
Guenter Roeck
maintainerQuoted 30 lines · 林濬哲
simple_strtoul()is deprecated. Replace it withkstrtouint(). A bad value now leaves the variable unchanged and produces a warning, instead of being silently clamped.
__setup()handlers return whether they handled the option; there is no way to propagate parse errors, so the handler simply returns 1.v2: warn on a bad value and return 1 instead of returning the parse
error, which__setup()handlers cannot do (Guenter Roeck).Signed-off-by Lin Junzhe <[email protected]>Assisted-by AI coding assistant (disclosed per kernel AI guidelines)--- kernel/watchdog.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)kernel/watchdog.c +1
-0@@ -17,6 +17,7 @@#include <linux/irq.h> #include <linux/irqdesc.h> #include <linux/kernel_stat.h> +#include <linux/kstrtox.h> #include <linux/kvm_para.h> #include <linux/math64.h> #include <linux/mm.h>
kernel/watchdog.c static unsigned long soft_lockup_nmi_warn; · line 430
Quoted 9 lines
kernel/watchdog.c +5
-1@@ -422,7 +423,11 @@ static unsigned long soft_lockup_nmi_warn;static int __init softlockup_panic_setup (char *str) { - softlockup_panic =simple_strtoul (str,NULL ,0 ); +int ret; + + ret =kstrtouint (str,0 , &softlockup_panic); +if (ret) +pr_warn ("softlockup_panic: bad option string '%s'\n" , str);
Hardly any other __setup function warns here, and I do not see the point adding it here.
Guenter
Quoted 7 lines
kernel/watchdog.c +0
-0return 1 ; }__setup ("softlockup_panic=" , softlockup_panic_setup);Signature · 1 line
2.54.0.windows.1
PATCH v3 1/2 PM: hibernate: use kstrtouint to parse resume= device numbers
simple_strtoul() is deprecated. Replace the base-16 parse with kstrtouint(); the explicit trailing-character check the old code needed is provided by kstrtouint() itself. As a side effect, values wider than 32 bits are now rejected instead of being silently truncated before the dev_t conversion.
--- kernel/power/hibernate.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
kernel/power/hibernate.c +7 -3
@@ -14,6 +14,7 @@#include <crypto/acompress.h> #include <linux/blkdev.h> #include <linux/export.h> +#include <linux/kstrtox.h> #include <linux/suspend.h> #include <linux/reboot.h> #include <linux/string.h>
@@ -1278,7 +1279,7 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr, error =lookup_bdev (name, &dev);if (error) {unsigned maj, min, offset; -char *p, dummy; +char dummy; error =0 ; if (sscanf(name, "%u:%u%c", &maj, &min, &dummy) == 2 ||
@@ -1288,9 +1289,12 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,if (maj !=MAJOR (dev) || min !=MINOR (dev)) error = -EINVAL ; }else { - dev =new_decode_dev (simple_strtoul (name, &p,16 )); -if (*p) +unsigned int val; + +if (kstrtouint (name,16 , &val)) error = -EINVAL ; +else + dev =new_decode_dev (val); } }kfree (name);
Signature · 1 line
2.54.0.windows.1
PATCH v3 2/2 watchdog: use kstrtouint to parse softlockup_panic=
In reply to Guenter Roecksimple_strtoul() is deprecated. Use kstrtouint() instead; on a parse error the variable is now left unchanged instead of being silently clamped.
__setup() handlers return whether they handled the option and cannot propagate parse errors, so the handler simply returns 1.
v3: do not warn on parse errors (Guenter Roeck).
--- kernel/watchdog.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/watchdog.c +4 -3
@@ -423,10 +423,11 @@ static unsigned long soft_lockup_nmi_warn;static int __init softlockup_panic_setup (char *str) { -int ret; +unsigned int val; - ret =kstrtouint (str,0 , &softlockup_panic); -return ret ? ret :1 ; +if (!kstrtouint (str,0 , &val)) + softlockup_panic = val; +return 1 ; }__setup ("softlockup_panic=" , softlockup_panic_setup);
Signature · 1 line
2.54.0.windows.1
Guenter Roeck
maintainerQuoted 22 lines · 林濬哲
simple_strtoul()is deprecated. Usekstrtouint()instead; on a parse error the variable is now left unchanged instead of being silently clamped.
__setup()handlers return whether they handled the option and cannot propagate parse errors, so the handler simply returns 1.v3: do not warn on parse errors (Guenter Roeck).
Signed-off-by Lin Junzhe <[email protected]>Assisted-by AI coding assistant (per kernel AI guidelines)--- kernel/watchdog.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)kernel/watchdog.c +0
-0@@ -423,10 +423,11 @@ static unsigned long soft_lockup_nmi_warn;
kernel/watchdog.c static unsigned long soft_lockup_nmi_warn; · line 430
Quoted 10 lines
kernel/watchdog.c +4
-3static int __init softlockup_panic_setup (char *str) { -int ret; +unsigned int val; - ret =kstrtouint (str,0 , &softlockup_panic); -return ret ? ret :1 ; +if (!kstrtouint (str,0 , &val)) + softlockup_panic = val; +return 1 ;
This is not v3, it is a patch applied on top of a previous version, and it unnecessarily introduces a temporary variable.
Guenter
PATCH v2 2/2 PM: hibernate: use kstrtouint to parse resume= device numbers
In reply to Guenter Roecksimple_strtoul() is deprecated. Replace the base-16 parse with kstrtouint(); the explicit trailing-character check the old code needed is provided by kstrtouint() itself. As a side effect, values wider than 32 bits are now rejected instead of being silently truncated before the dev_t conversion.
--- kernel/power/hibernate.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
kernel/power/hibernate.c +7 -3
@@ -14,6 +14,7 @@#include <crypto/acompress.h> #include <linux/blkdev.h> #include <linux/export.h> +#include <linux/kstrtox.h> #include <linux/suspend.h> #include <linux/reboot.h> #include <linux/string.h>
@@ -1278,7 +1279,7 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr, error =lookup_bdev (name, &dev);if (error) {unsigned maj, min, offset; -char *p, dummy; +char dummy; error =0 ; if (sscanf(name, "%u:%u%c", &maj, &min, &dummy) == 2 ||
@@ -1288,9 +1289,12 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,if (maj !=MAJOR (dev) || min !=MINOR (dev)) error = -EINVAL ; }else { - dev =new_decode_dev (simple_strtoul (name, &p,16 )); -if (*p) +unsigned int val; + +if (kstrtouint (name,16 , &val)) error = -EINVAL ; +else + dev =new_decode_dev (val); } }kfree (name);
Signature · 1 line
2.54.0.windows.1