Skip to contentSkip to conversation

watchdog: cpwd: replace simple_strtoul to kstrtoul

PATCH In review Hongbo Li 2 participants 3 messages Aug 30, 2024 – Aug 31, 2024 Watchdog device drivers

lore
Share & tools
lore

Hongbo Li

author
#0 lore raw

PATCH 1/1 watchdog: cpwd: replace simple_strtoul to kstrtoul

The function simple_strtoul performs no error checking in scenarios where the input value overflows the intended output variable.

We can replace the use of the simple_strtoul with the safer alternatives kstrtoul. For fail case, we also print the extra message.

---
 drivers/watchdog/cpwd.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/watchdog/cpwd.c +8 -2
index 901b94d456db..978bc6c87a35 100644
@@ -550,8 +550,14 @@ static int cpwd_probe(struct platform_device *op)
 	p->reboot = (prop_val ? true : false);
 
 	str_prop = of_get_property(options, "watchdog-timeout", NULL);
-	if (str_prop)
-		p->timeout = simple_strtoul(str_prop, NULL, 10);
+	if (str_prop) {
+		err = kstrtoul(str_prop, 10, &p->timeout);
+		if (err != 0) {
+			pr_err("Unable to parse watchdog-timeout\n");
+			of_node_put(options);
+			goto out_iounmap;
+		}
+	}
 
 	of_node_put(options);
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 8 lines · Hongbo Li

The function simple_strtoul performs no error checking in scenarios where the input value overflows the intended output variable.

We can replace the use of the simple_strtoul with the safer alternatives kstrtoul. For fail case, we also print the extra message.

I really don't see value in this patch, sorry. If the driver is still in use somewhere, it would be much more valuable to convert it to use the watchdog subsystem API, which would also address the above.

In general people should refrain from "improving" old watchdog drivers unless they are also converted to use the watchdog subsystem API, or unless a real bug is fixed.

Guenter

author
#2 lore raw
Quoted 10 lines · Guenter Roeck
Quoted 8 lines · Hongbo Li

The function simple_strtoul performs no error checking in scenarios where the input value overflows the intended output variable.

We can replace the use of the simple_strtoul with the safer alternatives kstrtoul. For fail case, we also print the extra message.

Quoted 7 lines

I really don't see value in this patch, sorry. If the driver is still in use somewhere, it would be much more valuable to convert it to use the watchdog subsystem API, which would also address the above.

In general people should refrain from "improving" old watchdog drivers unless they are also converted to use the watchdog subsystem API, or unless a real bug is fixed.

Sorry, I haven't noticed this.

Thanks,
Hongbo

Quoted 2 lines

Guenter