* [PATCH 1/2] watchdog: use kstrtouint to parse softlockup_panic=
@ 2026-09-21 6:41 林濬哲
2026-09-21 14:21 ` Guenter Roeck
0 siblings, 1 reply; 5+ messages in thread
From: 林濬哲 @ 2026-09-21 6:41 UTC (permalink / raw)
To: Wim Van Sebroeck
Cc: Guenter Roeck, linux-watchdog, linux-kernel, m18667909625
simple_strtoul() is deprecated. Replace it with kstrtouint(), which
also reports parse errors back to the boot process instead of
silently accepting garbage.
Signed-off-by: 林濬哲 <m18667909625@163.com>
Assisted-by: AI coding assistant (disclosed per kernel AI guidelines)
---
kernel/watchdog.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index e5134ad7b663..420f08140713 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -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);
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH 1/2] watchdog: use kstrtouint to parse softlockup_panic=
2026-09-21 6:41 [PATCH 1/2] watchdog: use kstrtouint to parse softlockup_panic= 林濬哲
@ 2026-09-21 14:21 ` Guenter Roeck
2026-09-21 6:29 ` [PATCH v2 2/2] PM: hibernate: use kstrtouint to parse resume= device numbers 林濬哲
2026-09-22 5:50 ` [PATCH v2 1/2] watchdog: use kstrtouint to parse softlockup_panic= 林濬哲
0 siblings, 2 replies; 5+ messages in thread
From: Guenter Roeck @ 2026-09-21 14:21 UTC (permalink / raw)
To: 林濬哲; +Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel
On Mon, Sep 21, 2026 at 02:41:43PM +0800, 林濬哲 wrote:
> simple_strtoul() is deprecated. Replace it with kstrtouint(), which
> also reports parse errors back to the boot process instead of
> silently accepting garbage.
>
> Signed-off-by: 林濬哲 <m18667909625@163.com>
> Assisted-by: AI coding assistant (disclosed per kernel AI guidelines)
> ---
> kernel/watchdog.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/watchdog.c b/kernel/watchdog.c
> index e5134ad7b663..420f08140713 100644
> --- a/kernel/watchdog.c
> +++ b/kernel/watchdog.c
> @@ -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;
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
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 2/2] PM: hibernate: use kstrtouint to parse resume= device numbers
2026-09-21 14:21 ` Guenter Roeck
@ 2026-09-21 6:29 ` 林濬哲
2026-09-22 5:50 ` [PATCH v2 1/2] watchdog: use kstrtouint to parse softlockup_panic= 林濬哲
1 sibling, 0 replies; 5+ messages in thread
From: 林濬哲 @ 2026-09-21 6:29 UTC (permalink / raw)
To: Guenter Roeck
Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, m18667909625
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.
Signed-off-by: Lin Junzhe <m18667909625@163.com>
Assisted-by: AI coding assistant (disclosed per kernel AI guidelines)
---
kernel/power/hibernate.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index d2479c69d71a..74f2d20518cc 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -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);
--
2.54.0.windows.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 1/2] watchdog: use kstrtouint to parse softlockup_panic=
2026-09-21 14:21 ` Guenter Roeck
2026-09-21 6:29 ` [PATCH v2 2/2] PM: hibernate: use kstrtouint to parse resume= device numbers 林濬哲
@ 2026-09-22 5:50 ` 林濬哲
2026-09-22 13:28 ` Guenter Roeck
1 sibling, 1 reply; 5+ messages in thread
From: 林濬哲 @ 2026-09-22 5:50 UTC (permalink / raw)
To: Guenter Roeck
Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel, m18667909625
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).
Signed-off-by: Lin Junzhe <m18667909625@163.com>
Assisted-by: AI coding assistant (disclosed per kernel AI guidelines)
---
kernel/watchdog.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kernel/watchdog.c b/kernel/watchdog.c
index e5134ad7b663..7f8c904554a9 100644
--- a/kernel/watchdog.c
+++ b/kernel/watchdog.c
@@ -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);
--
2.54.0.windows.1
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2 1/2] watchdog: use kstrtouint to parse softlockup_panic=
2026-09-22 5:50 ` [PATCH v2 1/2] watchdog: use kstrtouint to parse softlockup_panic= 林濬哲
@ 2026-09-22 13:28 ` Guenter Roeck
0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2026-09-22 13:28 UTC (permalink / raw)
To: 林濬哲; +Cc: Wim Van Sebroeck, linux-watchdog, linux-kernel
On Tue, Sep 22, 2026 at 01:50:40PM +0800, 林濬哲 wrote:
>
> 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).
>
> Signed-off-by: Lin Junzhe <m18667909625@163.com>
> Assisted-by: AI coding assistant (disclosed per kernel AI guidelines)
> ---
> kernel/watchdog.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/watchdog.c b/kernel/watchdog.c
> index e5134ad7b663..7f8c904554a9 100644
> --- a/kernel/watchdog.c
> +++ b/kernel/watchdog.c
> @@ -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);
Hardly any other __setup function warns here, and I do not see the point
adding it here.
Guenter
> return 1;
> }
> __setup("softlockup_panic=", softlockup_panic_setup);
> --
> 2.54.0.windows.1
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-22 13:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-21 6:41 [PATCH 1/2] watchdog: use kstrtouint to parse softlockup_panic= 林濬哲
2026-09-21 14:21 ` Guenter Roeck
2026-09-21 6:29 ` [PATCH v2 2/2] PM: hibernate: use kstrtouint to parse resume= device numbers 林濬哲
2026-09-22 5:50 ` [PATCH v2 1/2] watchdog: use kstrtouint to parse softlockup_panic= 林濬哲
2026-09-22 13:28 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®