2015-12-17 13:11:13

by Corentin Labbe

[permalink] [raw]
Subject: [PATCH v2 0/1] rtc: Replace simple_strtoul by kstrtoul

Hello

Change since v1
- Replaced another simple_strtoul that I missed the first time

LABBE Corentin (1):
rtc: Replace simple_strtoul by kstrtoul

drivers/rtc/rtc-sysfs.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

--
2.4.10


2015-12-17 13:11:34

by Corentin Labbe

[permalink] [raw]
Subject: [PATCH v2 1/1] rtc: Replace simple_strtoul by kstrtoul

The simple_strtoul function is obsolete.
This patch replace it by kstrtoul.

Since kstrtoul is more strict, it permits to filter some invalid input that
simple_strtoul accept. For example:
echo '1022xxx' > /sys/devices/pnp0/00:03/rtc/rtc0/max_user_freq
cat /sys/devices/pnp0/00:03/rtc/rtc0/max_user_freq
1022

Signed-off-by: LABBE Corentin <[email protected]>
---
drivers/rtc/rtc-sysfs.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index 7273855..463e286 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -91,7 +91,12 @@ max_user_freq_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t n)
{
struct rtc_device *rtc = to_rtc_device(dev);
- unsigned long val = simple_strtoul(buf, NULL, 0);
+ unsigned long val;
+ int err;
+
+ err = kstrtoul(buf, 0, &val);
+ if (err)
+ return err;

if (val >= 4096 || val == 0)
return -EINVAL;
@@ -175,7 +180,9 @@ wakealarm_store(struct device *dev, struct device_attribute *attr,
} else
adjust = 1;
}
- alarm = simple_strtoul(buf_ptr, NULL, 0);
+ retval = kstrtoul(buf_ptr, 0, &alarm);
+ if (retval)
+ return retval;
if (adjust) {
alarm += now;
}
--
2.4.10

2015-12-17 13:30:22

by Alexandre Belloni

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] rtc: Replace simple_strtoul by kstrtoul

On 17/12/2015 at 14:11:04 +0100, LABBE Corentin wrote :
> The simple_strtoul function is obsolete.
> This patch replace it by kstrtoul.
>
> Since kstrtoul is more strict, it permits to filter some invalid input that
> simple_strtoul accept. For example:
> echo '1022xxx' > /sys/devices/pnp0/00:03/rtc/rtc0/max_user_freq
> cat /sys/devices/pnp0/00:03/rtc/rtc0/max_user_freq
> 1022
>

Yeah, that is exactly the issue. Existing script that are doing that and
are currently working will then fail which is usually not what we want.
However, I think I'll still apply that patch.

> Signed-off-by: LABBE Corentin <[email protected]>
> ---
> drivers/rtc/rtc-sysfs.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
> index 7273855..463e286 100644
> --- a/drivers/rtc/rtc-sysfs.c
> +++ b/drivers/rtc/rtc-sysfs.c
> @@ -91,7 +91,12 @@ max_user_freq_store(struct device *dev, struct device_attribute *attr,
> const char *buf, size_t n)
> {
> struct rtc_device *rtc = to_rtc_device(dev);
> - unsigned long val = simple_strtoul(buf, NULL, 0);
> + unsigned long val;
> + int err;
> +
> + err = kstrtoul(buf, 0, &val);
> + if (err)
> + return err;
>
> if (val >= 4096 || val == 0)
> return -EINVAL;
> @@ -175,7 +180,9 @@ wakealarm_store(struct device *dev, struct device_attribute *attr,
> } else
> adjust = 1;
> }
> - alarm = simple_strtoul(buf_ptr, NULL, 0);
> + retval = kstrtoul(buf_ptr, 0, &alarm);
> + if (retval)
> + return retval;
> if (adjust) {
> alarm += now;
> }
> --
> 2.4.10
>

--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

2015-12-22 19:02:18

by Alexandre Belloni

[permalink] [raw]
Subject: Re: [PATCH v2 1/1] rtc: Replace simple_strtoul by kstrtoul

On 17/12/2015 at 14:11:04 +0100, LABBE Corentin wrote :
> The simple_strtoul function is obsolete.
> This patch replace it by kstrtoul.
>
> Since kstrtoul is more strict, it permits to filter some invalid input that
> simple_strtoul accept. For example:
> echo '1022xxx' > /sys/devices/pnp0/00:03/rtc/rtc0/max_user_freq
> cat /sys/devices/pnp0/00:03/rtc/rtc0/max_user_freq
> 1022
>
> Signed-off-by: LABBE Corentin <[email protected]>
> ---
> drivers/rtc/rtc-sysfs.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
Applied, thanks.

--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com