* [PATCH net-next v2] net: usb: pegasus: replace simple_strtoul with kstrtouint
@ 2026-05-09 9:51 Sajal Gupta
2026-05-14 1:10 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Sajal Gupta @ 2026-05-09 9:51 UTC (permalink / raw)
To: petkan
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, linux-usb, netdev,
linux-kernel, Sajal Gupta
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>
---
Changes in v2:
- Drop err variable
- Preserve original behavior for trailing colon by checking *id
before parsing flags
v1: https://lore.kernel.org/netdev/20260506152653.52329-1-sajal2005gupta@gmail.com/
drivers/net/usb/pegasus.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/net/usb/pegasus.c b/drivers/net/usb/pegasus.c
index db85f40734d7..8700eeb8e22d 100644
--- a/drivers/net/usb/pegasus.c
+++ b/drivers/net/usb/pegasus.c
@@ -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);
--
2.54.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net-next v2] net: usb: pegasus: replace simple_strtoul with kstrtouint
2026-05-09 9:51 [PATCH net-next v2] net: usb: pegasus: replace simple_strtoul with kstrtouint Sajal Gupta
@ 2026-05-14 1:10 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-05-14 1:10 UTC (permalink / raw)
To: Sajal Gupta
Cc: petkan, andrew+netdev, davem, edumazet, kuba, pabeni, linux-usb,
netdev, linux-kernel
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sat, 9 May 2026 15:21:48 +0530 you wrote:
> 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.
>
> [...]
Here is the summary with links:
- [net-next,v2] net: usb: pegasus: replace simple_strtoul with kstrtouint
https://git.kernel.org/netdev/net-next/c/1f8fd0fe5641
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-14 1:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-09 9:51 [PATCH net-next v2] net: usb: pegasus: replace simple_strtoul with kstrtouint Sajal Gupta
2026-05-14 1:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox