diff mbox series

[-next] sh: intc: replace simple_strtoul to kstrtoul

Message ID 20240830080401.3545399-1-lihongbo22@huawei.com (mailing list archive)
State New
Headers show
Series [-next] sh: intc: replace simple_strtoul to kstrtoul | expand

Commit Message

Hongbo Li Aug. 30, 2024, 8:04 a.m. UTC
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@huawei.com>
---
 drivers/sh/intc/userimask.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

John Paul Adrian Glaubitz Aug. 30, 2024, 8:16 a.m. UTC | #1
Hi Hongbo,

On Fri, 2024-08-30 at 16:04 +0800, Hongbo Li wrote:
> 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@huawei.com>
> ---
>  drivers/sh/intc/userimask.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/sh/intc/userimask.c b/drivers/sh/intc/userimask.c
> index abe9091827cd..c9892338fc22 100644
> --- a/drivers/sh/intc/userimask.c
> +++ b/drivers/sh/intc/userimask.c
> @@ -33,7 +33,8 @@ store_intc_userimask(struct device *dev,
>  {
>  	unsigned long level;
>  
> -	level = simple_strtoul(buf, NULL, 10);
> +	if (kstrtoul(buf, 10, &level))
> +		return -EINVAL;
>  
>  	/*
>  	 * Minimal acceptable IRQ levels are in the 2 - 16 range, but

Thanks for your patch. I will try to review it and the other pending patches
for sh-linux over the weekend.

Adrian
Geert Uytterhoeven Aug. 30, 2024, 8:22 a.m. UTC | #2
Hi Hongbo,

On Fri, Aug 30, 2024 at 9:56 AM Hongbo Li <lihongbo22@huawei.com> wrote:
> 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@huawei.com>

Thanks for your patch!

> --- a/drivers/sh/intc/userimask.c
> +++ b/drivers/sh/intc/userimask.c
> @@ -33,7 +33,8 @@ store_intc_userimask(struct device *dev,
>  {
>         unsigned long level;
>
> -       level = simple_strtoul(buf, NULL, 10);
> +       if (kstrtoul(buf, 10, &level))
> +               return -EINVAL;

Please pass the error code returned by kstrtoul() instead of hardcoding
-EINVAL.

>
>         /*
>          * Minimal acceptable IRQ levels are in the 2 - 16 range, but

Gr{oetje,eeting}s,

                        Geert
Hongbo Li Aug. 31, 2024, 2:03 a.m. UTC | #3
On 2024/8/30 16:22, Geert Uytterhoeven wrote:
> Hi Hongbo,
> 
> On Fri, Aug 30, 2024 at 9:56 AM Hongbo Li <lihongbo22@huawei.com> wrote:
>> 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@huawei.com>
> 
> Thanks for your patch!
> 
>> --- a/drivers/sh/intc/userimask.c
>> +++ b/drivers/sh/intc/userimask.c
>> @@ -33,7 +33,8 @@ store_intc_userimask(struct device *dev,
>>   {
>>          unsigned long level;
>>
>> -       level = simple_strtoul(buf, NULL, 10);
>> +       if (kstrtoul(buf, 10, &level))
>> +               return -EINVAL;
> 
> Please pass the error code returned by kstrtoul() instead of hardcoding
> -EINVAL.
> 
Thanks for reviewing, I'll make a change.

Thanks,
Hongbo
>>
>>          /*
>>           * Minimal acceptable IRQ levels are in the 2 - 16 range, but
> 
> Gr{oetje,eeting}s,
> 
>                          Geert
>
diff mbox series

Patch

diff --git a/drivers/sh/intc/userimask.c b/drivers/sh/intc/userimask.c
index abe9091827cd..c9892338fc22 100644
--- a/drivers/sh/intc/userimask.c
+++ b/drivers/sh/intc/userimask.c
@@ -33,7 +33,8 @@  store_intc_userimask(struct device *dev,
 {
 	unsigned long level;
 
-	level = simple_strtoul(buf, NULL, 10);
+	if (kstrtoul(buf, 10, &level))
+		return -EINVAL;
 
 	/*
 	 * Minimal acceptable IRQ levels are in the 2 - 16 range, but