* [PATCH] usb: misc: cytherm: replace deprecated simple_strtoul with kstrtoint
@ 2026-06-22 12:31 Jad Keskes
2026-07-08 15:12 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Jad Keskes @ 2026-06-22 12:31 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, linux-kernel, Jad Keskes
simple_strtoul() is deprecated in favor of kstrtoint(). The old
function silently accepts garbage input. kstrtoint() returns -EINVAL
so the driver can actually tell the user they typed something stupid
instead of accepting 0 and wondering why the thermometer isn't
responding.
The 0-255 clamping stays the same, just with proper error handling
in front of it now.
Signed-off-by: Jad Keskes <inasj268@gmail.com>
---
drivers/usb/misc/cytherm.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/misc/cytherm.c b/drivers/usb/misc/cytherm.c
index b183df9826bc..81de3fecf3da 100644
--- a/drivers/usb/misc/cytherm.c
+++ b/drivers/usb/misc/cytherm.c
@@ -85,7 +85,9 @@ static ssize_t brightness_store(struct device *dev, struct device_attribute *att
if (!buffer)
return 0;
- cytherm->brightness = simple_strtoul(buf, NULL, 10);
+ retval = kstrtoint(buf, 10, &cytherm->brightness);
+ if (retval < 0)
+ return retval;
if (cytherm->brightness > 0xFF)
cytherm->brightness = 0xFF;
@@ -217,7 +219,9 @@ static ssize_t port0_store(struct device *dev, struct device_attribute *attr, co
if (!buffer)
return 0;
- tmp = simple_strtoul(buf, NULL, 10);
+ retval = kstrtoint(buf, 10, &tmp);
+ if (retval < 0)
+ return retval;
if (tmp > 0xFF)
tmp = 0xFF;
@@ -272,7 +276,9 @@ static ssize_t port1_store(struct device *dev, struct device_attribute *attr, co
if (!buffer)
return 0;
- tmp = simple_strtoul(buf, NULL, 10);
+ retval = kstrtoint(buf, 10, &tmp);
+ if (retval < 0)
+ return retval;
if (tmp > 0xFF)
tmp = 0xFF;
--
2.54.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: misc: cytherm: replace deprecated simple_strtoul with kstrtoint
2026-06-22 12:31 [PATCH] usb: misc: cytherm: replace deprecated simple_strtoul with kstrtoint Jad Keskes
@ 2026-07-08 15:12 ` Greg KH
2026-07-08 15:20 ` Jad Keskes
0 siblings, 1 reply; 4+ messages in thread
From: Greg KH @ 2026-07-08 15:12 UTC (permalink / raw)
To: Jad Keskes; +Cc: linux-usb, linux-kernel
On Mon, Jun 22, 2026 at 01:31:24PM +0100, Jad Keskes wrote:
> simple_strtoul() is deprecated in favor of kstrtoint(). The old
> function silently accepts garbage input. kstrtoint() returns -EINVAL
> so the driver can actually tell the user they typed something stupid
> instead of accepting 0 and wondering why the thermometer isn't
> responding.
>
> The 0-255 clamping stays the same, just with proper error handling
> in front of it now.
>
> Signed-off-by: Jad Keskes <inasj268@gmail.com>
> ---
> drivers/usb/misc/cytherm.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/misc/cytherm.c b/drivers/usb/misc/cytherm.c
> index b183df9826bc..81de3fecf3da 100644
> --- a/drivers/usb/misc/cytherm.c
> +++ b/drivers/usb/misc/cytherm.c
> @@ -85,7 +85,9 @@ static ssize_t brightness_store(struct device *dev, struct device_attribute *att
> if (!buffer)
> return 0;
>
> - cytherm->brightness = simple_strtoul(buf, NULL, 10);
> + retval = kstrtoint(buf, 10, &cytherm->brightness);
> + if (retval < 0)
> + return retval;
This changes the user/kernel functionality, are you sure it is safe to
do so?
What is wrong with leaving the current calls?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: misc: cytherm: replace deprecated simple_strtoul with kstrtoint
2026-07-08 15:12 ` Greg KH
@ 2026-07-08 15:20 ` Jad Keskes
2026-07-10 13:11 ` Greg KH
0 siblings, 1 reply; 4+ messages in thread
From: Jad Keskes @ 2026-07-08 15:20 UTC (permalink / raw)
To: Greg KH; +Cc: linux-usb, linux-kernel
On 07/08, Greg KH wrote:
> This changes the user/kernel functionality, are you sure it is safe to
> do so?
Nobody writes garbage to these on purpose, and if they do by accident
they should get an error, not 0. The only way this breaks is if some
tool depends on "echo foo > brightness" silently setting to 0 — which
would be a bug in that tool.
> What is wrong with leaving the current calls?
simple_strtoul is deprecated per deprecated.rst. It ignores overflows
too — writing -1 wraps to ULONG_MAX then gets clamped to 0xFF instead
of erroring out. kstrtoint returns -EINVAL for both.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: misc: cytherm: replace deprecated simple_strtoul with kstrtoint
2026-07-08 15:20 ` Jad Keskes
@ 2026-07-10 13:11 ` Greg KH
0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2026-07-10 13:11 UTC (permalink / raw)
To: Jad Keskes; +Cc: linux-usb, linux-kernel
On Wed, Jul 08, 2026 at 04:20:03PM +0100, Jad Keskes wrote:
> On 07/08, Greg KH wrote:
> > This changes the user/kernel functionality, are you sure it is safe to
> > do so?
>
> Nobody writes garbage to these on purpose, and if they do by accident
> they should get an error, not 0. The only way this breaks is if some
> tool depends on "echo foo > brightness" silently setting to 0 — which
> would be a bug in that tool.
>
> > What is wrong with leaving the current calls?
>
> simple_strtoul is deprecated per deprecated.rst. It ignores overflows
> too — writing -1 wraps to ULONG_MAX then gets clamped to 0xFF instead
> of erroring out. kstrtoint returns -EINVAL for both.
Sure, it's deprecated, so don't add it to new code, but for existing
stuff, don't change how user/kernel interactions might work.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-10 13:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-22 12:31 [PATCH] usb: misc: cytherm: replace deprecated simple_strtoul with kstrtoint Jad Keskes
2026-07-08 15:12 ` Greg KH
2026-07-08 15:20 ` Jad Keskes
2026-07-10 13:11 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox