]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: usb: pegasus: replace simple_strtoul with kstrtouint
authorSajal Gupta <sajal2005gupta@gmail.com>
Sat, 9 May 2026 09:51:48 +0000 (15:21 +0530)
committerJakub Kicinski <kuba@kernel.org>
Thu, 14 May 2026 01:06:56 +0000 (18:06 -0700)
simple_strtoul() is deprecated as it has no error checking. Replace it
with kstrtouint() which returns an error code on invalid input, and add
appropriate error handling.

Also add a NULL check before parsing flags, since strsep() can set id
to NULL if the input has fewer tokens than expected.

Preserve the original behavior for a trailing colon by checking *id
before parsing flags, so an empty string results in flags = 0 rather
than an error.

Signed-off-by: Sajal Gupta <sajal2005gupta@gmail.com>
Link: https://patch.msgid.link/20260509095518.2640-1-sajal2005gupta@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/usb/pegasus.c

index db85f40734d7b8cd6382029dbbfb7b27fb059589..8700eeb8e22d07cc7c6c1c471a553a87820355c3 100644 (file)
@@ -1328,14 +1328,18 @@ static void __init parse_id(char *id)
        unsigned int vendor_id = 0, device_id = 0, flags = 0, i = 0;
        char *token, *name = NULL;
 
-       if ((token = strsep(&id, ":")) != NULL)
+       token = strsep(&id, ":");
+       if (token)
                name = token;
        /* name now points to a null terminated string*/
-       if ((token = strsep(&id, ":")) != NULL)
-               vendor_id = simple_strtoul(token, NULL, 16);
-       if ((token = strsep(&id, ":")) != NULL)
-               device_id = simple_strtoul(token, NULL, 16);
-       flags = simple_strtoul(id, NULL, 16);
+       token = strsep(&id, ":");
+       if (token && kstrtouint(token, 16, &vendor_id))
+               return;
+       token = strsep(&id, ":");
+       if (token && kstrtouint(token, 16, &device_id))
+               return;
+       if (id && *id && kstrtouint(id, 16, &flags))
+               return;
        pr_info("%s: new device %s, vendor ID 0x%04x, device ID 0x%04x, flags: 0x%x\n",
                driver_name, name, vendor_id, device_id, flags);