[PATCH -next] watchdog: cpwd: replace simple_strtoul to kstrtoul

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Signed-off-by: Hongbo Li <lihongbo22@xxxxxxxxxx>
---
 drivers/watchdog/cpwd.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/watchdog/cpwd.c b/drivers/watchdog/cpwd.c
index 901b94d456db..978bc6c87a35 100644
--- a/drivers/watchdog/cpwd.c
+++ b/drivers/watchdog/cpwd.c
@@ -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);
 
-- 
2.34.1





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux