dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/modes: Replace deprecated simple_strtol with kstrtol
@ 2024-02-01  7:02 Cong Liu
  2024-02-01 10:03 ` Jani Nikula
  0 siblings, 1 reply; 3+ messages in thread
From: Cong Liu @ 2024-02-01  7:02 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Daniel Vetter
  Cc: Cong Liu, linux-kernel, dri-devel

This patch replaces the use of the deprecated simple_strtol [1] function
in the drm_modes.c file with the recommended kstrtol function. This change
improves error handling and boundary checks.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull

Signed-off-by: Cong Liu <liucong2@kylinos.cn>
---
 drivers/gpu/drm/drm_modes.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index 893f52ee4926..fce0fb1df9b2 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -1942,7 +1942,7 @@ static int drm_mode_parse_cmdline_bpp(const char *str, char **end_ptr,
 		return -EINVAL;
 
 	str++;
-	bpp = simple_strtol(str, end_ptr, 10);
+	bpp = kstrtol(str, end_ptr, 10);
 	if (*end_ptr == str)
 		return -EINVAL;
 
@@ -1961,7 +1961,7 @@ static int drm_mode_parse_cmdline_refresh(const char *str, char **end_ptr,
 		return -EINVAL;
 
 	str++;
-	refresh = simple_strtol(str, end_ptr, 10);
+	refresh = kstrtol(str, end_ptr, 10);
 	if (*end_ptr == str)
 		return -EINVAL;
 
@@ -2033,7 +2033,7 @@ static int drm_mode_parse_cmdline_res_mode(const char *str, unsigned int length,
 	int remaining, i;
 	char *end_ptr;
 
-	xres = simple_strtol(str, &end_ptr, 10);
+	xres = kstrtol(str, &end_ptr, 10);
 	if (end_ptr == str)
 		return -EINVAL;
 
@@ -2042,7 +2042,7 @@ static int drm_mode_parse_cmdline_res_mode(const char *str, unsigned int length,
 	end_ptr++;
 
 	str = end_ptr;
-	yres = simple_strtol(str, &end_ptr, 10);
+	yres = kstrtol(str, &end_ptr, 10);
 	if (end_ptr == str)
 		return -EINVAL;
 
@@ -2100,7 +2100,7 @@ static int drm_mode_parse_cmdline_int(const char *delim, unsigned int *int_ret)
 		return -EINVAL;
 
 	value = delim + 1;
-	*int_ret = simple_strtol(value, &endp, 10);
+	*int_ret = kstrtol(value, &endp, 10);
 
 	/* Make sure we have parsed something */
 	if (endp == value)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/modes: Replace deprecated simple_strtol with kstrtol
  2024-02-01  7:02 [PATCH] drm/modes: Replace deprecated simple_strtol with kstrtol Cong Liu
@ 2024-02-01 10:03 ` Jani Nikula
  2024-02-02  8:56   ` Cong Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Jani Nikula @ 2024-02-01 10:03 UTC (permalink / raw)
  To: Cong Liu, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Daniel Vetter
  Cc: Cong Liu, linux-kernel, dri-devel

On Thu, 01 Feb 2024, Cong Liu <liucong2@kylinos.cn> wrote:
> This patch replaces the use of the deprecated simple_strtol [1] function
> in the drm_modes.c file with the recommended kstrtol function. This change
> improves error handling and boundary checks.
>
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull
>
> Signed-off-by: Cong Liu <liucong2@kylinos.cn>

This is completely wrong, and obviously not tested at all.

The recommended replacements are *not* drop-in replacements. Look into
the documentation of the functions.

BR,
Jani.

> ---
>  drivers/gpu/drm/drm_modes.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> index 893f52ee4926..fce0fb1df9b2 100644
> --- a/drivers/gpu/drm/drm_modes.c
> +++ b/drivers/gpu/drm/drm_modes.c
> @@ -1942,7 +1942,7 @@ static int drm_mode_parse_cmdline_bpp(const char *str, char **end_ptr,
>  		return -EINVAL;
>  
>  	str++;
> -	bpp = simple_strtol(str, end_ptr, 10);
> +	bpp = kstrtol(str, end_ptr, 10);
>  	if (*end_ptr == str)
>  		return -EINVAL;
>  
> @@ -1961,7 +1961,7 @@ static int drm_mode_parse_cmdline_refresh(const char *str, char **end_ptr,
>  		return -EINVAL;
>  
>  	str++;
> -	refresh = simple_strtol(str, end_ptr, 10);
> +	refresh = kstrtol(str, end_ptr, 10);
>  	if (*end_ptr == str)
>  		return -EINVAL;
>  
> @@ -2033,7 +2033,7 @@ static int drm_mode_parse_cmdline_res_mode(const char *str, unsigned int length,
>  	int remaining, i;
>  	char *end_ptr;
>  
> -	xres = simple_strtol(str, &end_ptr, 10);
> +	xres = kstrtol(str, &end_ptr, 10);
>  	if (end_ptr == str)
>  		return -EINVAL;
>  
> @@ -2042,7 +2042,7 @@ static int drm_mode_parse_cmdline_res_mode(const char *str, unsigned int length,
>  	end_ptr++;
>  
>  	str = end_ptr;
> -	yres = simple_strtol(str, &end_ptr, 10);
> +	yres = kstrtol(str, &end_ptr, 10);
>  	if (end_ptr == str)
>  		return -EINVAL;
>  
> @@ -2100,7 +2100,7 @@ static int drm_mode_parse_cmdline_int(const char *delim, unsigned int *int_ret)
>  		return -EINVAL;
>  
>  	value = delim + 1;
> -	*int_ret = simple_strtol(value, &endp, 10);
> +	*int_ret = kstrtol(value, &endp, 10);
>  
>  	/* Make sure we have parsed something */
>  	if (endp == value)

-- 
Jani Nikula, Intel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/modes: Replace deprecated simple_strtol with kstrtol
  2024-02-01 10:03 ` Jani Nikula
@ 2024-02-02  8:56   ` Cong Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Cong Liu @ 2024-02-02  8:56 UTC (permalink / raw)
  To: Jani Nikula, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Daniel Vetter
  Cc: linux-kernel, dri-devel

Dear Jani,

I want to apologize for the incorrect patch I submitted. You are right 
that the recommended replacements are not suitable drop-in replacements 
and I clearly did not test the changes thoroughly.
The kstrtol function requires null-terminated strings, so it is not 
appropriate for the conversion needed here. Given the issues, it is best 
to maintain the original implementation for now.

Best Regard.
liucong

On 2024/2/1 18:03, Jani Nikula wrote:
> On Thu, 01 Feb 2024, Cong Liu <liucong2@kylinos.cn> wrote:
>> This patch replaces the use of the deprecated simple_strtol [1] function
>> in the drm_modes.c file with the recommended kstrtol function. This change
>> improves error handling and boundary checks.
>>
>> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull
>>
>> Signed-off-by: Cong Liu <liucong2@kylinos.cn>
> 
> This is completely wrong, and obviously not tested at all.
> 
> The recommended replacements are *not* drop-in replacements. Look into
> the documentation of the functions.
> 
> BR,
> Jani.
> 
>> ---
>>   drivers/gpu/drm/drm_modes.c | 10 +++++-----
>>   1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
>> index 893f52ee4926..fce0fb1df9b2 100644
>> --- a/drivers/gpu/drm/drm_modes.c
>> +++ b/drivers/gpu/drm/drm_modes.c
>> @@ -1942,7 +1942,7 @@ static int drm_mode_parse_cmdline_bpp(const char *str, char **end_ptr,
>>   		return -EINVAL;
>>   
>>   	str++;
>> -	bpp = simple_strtol(str, end_ptr, 10);
>> +	bpp = kstrtol(str, end_ptr, 10);
>>   	if (*end_ptr == str)
>>   		return -EINVAL;
>>   
>> @@ -1961,7 +1961,7 @@ static int drm_mode_parse_cmdline_refresh(const char *str, char **end_ptr,
>>   		return -EINVAL;
>>   
>>   	str++;
>> -	refresh = simple_strtol(str, end_ptr, 10);
>> +	refresh = kstrtol(str, end_ptr, 10);
>>   	if (*end_ptr == str)
>>   		return -EINVAL;
>>   
>> @@ -2033,7 +2033,7 @@ static int drm_mode_parse_cmdline_res_mode(const char *str, unsigned int length,
>>   	int remaining, i;
>>   	char *end_ptr;
>>   
>> -	xres = simple_strtol(str, &end_ptr, 10);
>> +	xres = kstrtol(str, &end_ptr, 10);
>>   	if (end_ptr == str)
>>   		return -EINVAL;
>>   
>> @@ -2042,7 +2042,7 @@ static int drm_mode_parse_cmdline_res_mode(const char *str, unsigned int length,
>>   	end_ptr++;
>>   
>>   	str = end_ptr;
>> -	yres = simple_strtol(str, &end_ptr, 10);
>> +	yres = kstrtol(str, &end_ptr, 10);
>>   	if (end_ptr == str)
>>   		return -EINVAL;
>>   
>> @@ -2100,7 +2100,7 @@ static int drm_mode_parse_cmdline_int(const char *delim, unsigned int *int_ret)
>>   		return -EINVAL;
>>   
>>   	value = delim + 1;
>> -	*int_ret = simple_strtol(value, &endp, 10);
>> +	*int_ret = kstrtol(value, &endp, 10);
>>   
>>   	/* Make sure we have parsed something */
>>   	if (endp == value)
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-02  8:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-01  7:02 [PATCH] drm/modes: Replace deprecated simple_strtol with kstrtol Cong Liu
2024-02-01 10:03 ` Jani Nikula
2024-02-02  8:56   ` Cong Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).