platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] platform/x86: surfacepro3_button: replace deprecated strcpy() with strscpy()
@ 2025-07-24  7:45 Miguel García
  2025-07-27 20:32 ` Ilpo Järvinen
  2025-07-28  5:30 ` Krzysztof Kozlowski
  0 siblings, 2 replies; 8+ messages in thread
From: Miguel García @ 2025-07-24  7:45 UTC (permalink / raw)
  To: platform-driver-x86
  Cc: linux-kernel, yu.c.chen, hansg, ilpo.jarvinen, luzmaximilian,
	skhan, Miguel García

strcpy() is deprecated for NUL-terminated strings. Replace it with
strscpy() to guarantee NUL-termination. 'name' is a fixed-size local
buffer.

Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com>
---
 drivers/platform/surface/surfacepro3_button.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/surface/surfacepro3_button.c b/drivers/platform/surface/surfacepro3_button.c
index 2755601f979c..9616548283a1 100644
--- a/drivers/platform/surface/surfacepro3_button.c
+++ b/drivers/platform/surface/surfacepro3_button.c
@@ -211,7 +211,7 @@ static int surface_button_add(struct acpi_device *device)
 	}
 
 	name = acpi_device_name(device);
-	strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
+	strscpy(name, SURFACE_BUTTON_DEVICE_NAME, sizeof(name));
 	snprintf(button->phys, sizeof(button->phys), "%s/buttons", hid);
 
 	input->name = name;
-- 
2.34.1


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

* Re: [PATCH] platform/x86: surfacepro3_button: replace deprecated strcpy() with strscpy()
  2025-07-24  7:45 [PATCH] platform/x86: surfacepro3_button: replace deprecated strcpy() with strscpy() Miguel García
@ 2025-07-27 20:32 ` Ilpo Järvinen
  2025-07-28  1:47   ` Chen, Yu C
  2025-07-28  5:30 ` Krzysztof Kozlowski
  1 sibling, 1 reply; 8+ messages in thread
From: Ilpo Järvinen @ 2025-07-27 20:32 UTC (permalink / raw)
  To: Miguel García, Andy Shevchenko
  Cc: platform-driver-x86, LKML, yu.c.chen, hansg, luzmaximilian, skhan

[-- Attachment #1: Type: text/plain, Size: 985 bytes --]

On Thu, 24 Jul 2025, Miguel García wrote:

> strcpy() is deprecated for NUL-terminated strings. Replace it with
> strscpy() to guarantee NUL-termination. 'name' is a fixed-size local
> buffer.
> 
> Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com>
> ---
>  drivers/platform/surface/surfacepro3_button.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/surface/surfacepro3_button.c b/drivers/platform/surface/surfacepro3_button.c
> index 2755601f979c..9616548283a1 100644
> --- a/drivers/platform/surface/surfacepro3_button.c
> +++ b/drivers/platform/surface/surfacepro3_button.c
> @@ -211,7 +211,7 @@ static int surface_button_add(struct acpi_device *device)
>  	}
>  
>  	name = acpi_device_name(device);
> -	strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
> +	strscpy(name, SURFACE_BUTTON_DEVICE_NAME, sizeof(name));

strscpy() should nowadays support 2 args variant through clever macro 
trickery.

-- 
 i.

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

* Re: [PATCH] platform/x86: surfacepro3_button: replace deprecated strcpy() with strscpy()
  2025-07-27 20:32 ` Ilpo Järvinen
@ 2025-07-28  1:47   ` Chen, Yu C
  0 siblings, 0 replies; 8+ messages in thread
From: Chen, Yu C @ 2025-07-28  1:47 UTC (permalink / raw)
  To: Ilpo Järvinen, Miguel García
  Cc: platform-driver-x86, LKML, hansg, luzmaximilian, skhan,
	Andy Shevchenko

On 7/28/2025 4:32 AM, Ilpo Järvinen wrote:
> On Thu, 24 Jul 2025, Miguel García wrote:
> 
>> strcpy() is deprecated for NUL-terminated strings. Replace it with
>> strscpy() to guarantee NUL-termination. 'name' is a fixed-size local
>> buffer.
>>
>> Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com>
>> ---
>>   drivers/platform/surface/surfacepro3_button.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/platform/surface/surfacepro3_button.c b/drivers/platform/surface/surfacepro3_button.c
>> index 2755601f979c..9616548283a1 100644
>> --- a/drivers/platform/surface/surfacepro3_button.c
>> +++ b/drivers/platform/surface/surfacepro3_button.c
>> @@ -211,7 +211,7 @@ static int surface_button_add(struct acpi_device *device)
>>   	}
>>   
>>   	name = acpi_device_name(device);
>> -	strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
>> +	strscpy(name, SURFACE_BUTTON_DEVICE_NAME, sizeof(name));
> 
> strscpy() should nowadays support 2 args variant through clever macro
> trickery.
> 

Yup,  something like
strscpy(name, SURFACE_BUTTON_DEVICE_NAME);
should be fine, because
name is a array, and SURFACE_BUTTON_DEVICE_NAME is smaller than
the size of name.

thanks,
Chenyu

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

* Re: [PATCH] platform/x86: surfacepro3_button: replace deprecated strcpy() with strscpy()
  2025-07-24  7:45 [PATCH] platform/x86: surfacepro3_button: replace deprecated strcpy() with strscpy() Miguel García
  2025-07-27 20:32 ` Ilpo Järvinen
@ 2025-07-28  5:30 ` Krzysztof Kozlowski
  2025-07-28 19:49   ` [PATCH v2] " Miguel García
  2025-07-29  7:38   ` [PATCH] " Miguel García Román
  1 sibling, 2 replies; 8+ messages in thread
From: Krzysztof Kozlowski @ 2025-07-28  5:30 UTC (permalink / raw)
  To: Miguel García, platform-driver-x86
  Cc: linux-kernel, yu.c.chen, hansg, ilpo.jarvinen, luzmaximilian,
	skhan

On 24/07/2025 09:45, Miguel García wrote:
> strcpy() is deprecated for NUL-terminated strings. Replace it with
> strscpy() to guarantee NUL-termination. 'name' is a fixed-size local
> buffer.
> 
> Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com>
> ---
>  drivers/platform/surface/surfacepro3_button.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/surface/surfacepro3_button.c b/drivers/platform/surface/surfacepro3_button.c
> index 2755601f979c..9616548283a1 100644
> --- a/drivers/platform/surface/surfacepro3_button.c
> +++ b/drivers/platform/surface/surfacepro3_button.c
> @@ -211,7 +211,7 @@ static int surface_button_add(struct acpi_device *device)
>  	}
>  
>  	name = acpi_device_name(device);
> -	strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
> +	strscpy(name, SURFACE_BUTTON_DEVICE_NAME, sizeof(name));


Why are you copying four/eight characters if the string is around 16?

How did you test it (and I doubt you did since you change multiple
different files from different architectures)?


Best regards,
Krzysztof

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

* [PATCH v2] platform/x86: surfacepro3_button: replace deprecated strcpy() with strscpy()
  2025-07-28  5:30 ` Krzysztof Kozlowski
@ 2025-07-28 19:49   ` Miguel García
  2025-07-28 20:11     ` [PATCH v3] " Miguel García
  2025-07-29  7:38   ` [PATCH] " Miguel García Román
  1 sibling, 1 reply; 8+ messages in thread
From: Miguel García @ 2025-07-28 19:49 UTC (permalink / raw)
  To: platform-driver-x86; +Cc: linux-kernel, ilpo.jarvinen, krzk, Miguel García

Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com>
---
 drivers/platform/surface/surfacepro3_button.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/surface/surfacepro3_button.c b/drivers/platform/surface/surfacepro3_button.c
index 2755601f979c..772e107151f6 100644
--- a/drivers/platform/surface/surfacepro3_button.c
+++ b/drivers/platform/surface/surfacepro3_button.c
@@ -211,7 +211,7 @@ static int surface_button_add(struct acpi_device *device)
 	}
 
 	name = acpi_device_name(device);
-	strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
+	strscpy(name, SURFACE_BUTTON_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);
 	snprintf(button->phys, sizeof(button->phys), "%s/buttons", hid);
 
 	input->name = name;
-- 
2.34.1


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

* [PATCH v3] platform/x86: surfacepro3_button: replace deprecated strcpy() with strscpy()
  2025-07-28 19:49   ` [PATCH v2] " Miguel García
@ 2025-07-28 20:11     ` Miguel García
  2025-08-19 10:00       ` Ilpo Järvinen
  0 siblings, 1 reply; 8+ messages in thread
From: Miguel García @ 2025-07-28 20:11 UTC (permalink / raw)
  To: platform-driver-x86; +Cc: linux-kernel, ilpo.jarvinen, krzk, Miguel García

Replace strcpy() with strscpy() when copying SURFACE_BUTTON_DEVICE_NAME
into the device’s embedded name buffer returned by acpi_device_name().
Bound the copy with MAX_ACPI_DEVICE_NAME_LEN to guarantee NUL-termination
and avoid pointer-sized sizeof() mistakes.

This is a mechanical safety improvement; functional behavior is unchanged.

Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com>
---
v2:
 - Use MAX_ACPI_DEVICE_NAME_LEN instead of sizeof(name).

v3:
 - Add full commit message (v2 was sent without message).

Testing:
 - Build-tested on x86_64 (defconfig, allmodconfig, W=1).
 - No runtime testing on Surface hardware

 drivers/platform/surface/surfacepro3_button.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/surface/surfacepro3_button.c b/drivers/platform/surface/surfacepro3_button.c
index 2755601f979c..772e107151f6 100644
--- a/drivers/platform/surface/surfacepro3_button.c
+++ b/drivers/platform/surface/surfacepro3_button.c
@@ -211,7 +211,7 @@ static int surface_button_add(struct acpi_device *device)
 	}
 
 	name = acpi_device_name(device);
-	strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
+	strscpy(name, SURFACE_BUTTON_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);
 	snprintf(button->phys, sizeof(button->phys), "%s/buttons", hid);
 
 	input->name = name;
-- 
2.34.1


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

* Re: [PATCH] platform/x86: surfacepro3_button: replace deprecated strcpy() with strscpy()
  2025-07-28  5:30 ` Krzysztof Kozlowski
  2025-07-28 19:49   ` [PATCH v2] " Miguel García
@ 2025-07-29  7:38   ` Miguel García Román
  1 sibling, 0 replies; 8+ messages in thread
From: Miguel García Román @ 2025-07-29  7:38 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: platform-driver-x86, linux-kernel, yu.c.chen, hansg,
	ilpo.jarvinen, luzmaximilian, skhan

Hi all,

thanks for the review. You were right about sizeof(name) being the pointer size.
I’ve sent v3 bounding with MAX_ACPI_DEVICE_NAME_LEN. Compile-tested only (x86_64
defconfig/allmodconfig, W=1); no Surface hardware. Apologies for the noise.

Best regards,

El lun, 28 jul 2025 a las 7:30, Krzysztof Kozlowski
(<krzk@kernel.org>) escribió:
>
> On 24/07/2025 09:45, Miguel García wrote:
> > strcpy() is deprecated for NUL-terminated strings. Replace it with
> > strscpy() to guarantee NUL-termination. 'name' is a fixed-size local
> > buffer.
> >
> > Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com>
> > ---
> >  drivers/platform/surface/surfacepro3_button.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/platform/surface/surfacepro3_button.c b/drivers/platform/surface/surfacepro3_button.c
> > index 2755601f979c..9616548283a1 100644
> > --- a/drivers/platform/surface/surfacepro3_button.c
> > +++ b/drivers/platform/surface/surfacepro3_button.c
> > @@ -211,7 +211,7 @@ static int surface_button_add(struct acpi_device *device)
> >       }
> >
> >       name = acpi_device_name(device);
> > -     strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
> > +     strscpy(name, SURFACE_BUTTON_DEVICE_NAME, sizeof(name));
>
>
> Why are you copying four/eight characters if the string is around 16?
>
> How did you test it (and I doubt you did since you change multiple
> different files from different architectures)?
>
>
> Best regards,
> Krzysztof

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

* Re: [PATCH v3] platform/x86: surfacepro3_button: replace deprecated strcpy() with strscpy()
  2025-07-28 20:11     ` [PATCH v3] " Miguel García
@ 2025-08-19 10:00       ` Ilpo Järvinen
  0 siblings, 0 replies; 8+ messages in thread
From: Ilpo Järvinen @ 2025-08-19 10:00 UTC (permalink / raw)
  To: Miguel García; +Cc: platform-driver-x86, LKML, krzk

[-- Attachment #1: Type: text/plain, Size: 1617 bytes --]

On Mon, 28 Jul 2025, Miguel García wrote:

> Replace strcpy() with strscpy() when copying SURFACE_BUTTON_DEVICE_NAME
> into the device’s embedded name buffer returned by acpi_device_name().
> Bound the copy with MAX_ACPI_DEVICE_NAME_LEN to guarantee NUL-termination
> and avoid pointer-sized sizeof() mistakes.
> 
> This is a mechanical safety improvement; functional behavior is unchanged.
> 
> Signed-off-by: Miguel García <miguelgarciaroman8@gmail.com>
> ---
> v2:
>  - Use MAX_ACPI_DEVICE_NAME_LEN instead of sizeof(name).
> 
> v3:
>  - Add full commit message (v2 was sent without message).
> 
> Testing:
>  - Build-tested on x86_64 (defconfig, allmodconfig, W=1).
>  - No runtime testing on Surface hardware
> 
>  drivers/platform/surface/surfacepro3_button.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/surface/surfacepro3_button.c b/drivers/platform/surface/surfacepro3_button.c
> index 2755601f979c..772e107151f6 100644
> --- a/drivers/platform/surface/surfacepro3_button.c
> +++ b/drivers/platform/surface/surfacepro3_button.c
> @@ -211,7 +211,7 @@ static int surface_button_add(struct acpi_device *device)
>  	}
>  
>  	name = acpi_device_name(device);
> -	strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
> +	strscpy(name, SURFACE_BUTTON_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);

As mentioned earlier, I'd prefer this to use the two argument version of 
strscpy():

	strscpy(acpi_device_name(device), SURFACE_BUTTON_DEVICE_NAME);

...Changing to that may mean changes to name variable as well (remove 
it?).

-- 
 i.

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

end of thread, other threads:[~2025-08-19 10:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-24  7:45 [PATCH] platform/x86: surfacepro3_button: replace deprecated strcpy() with strscpy() Miguel García
2025-07-27 20:32 ` Ilpo Järvinen
2025-07-28  1:47   ` Chen, Yu C
2025-07-28  5:30 ` Krzysztof Kozlowski
2025-07-28 19:49   ` [PATCH v2] " Miguel García
2025-07-28 20:11     ` [PATCH v3] " Miguel García
2025-08-19 10:00       ` Ilpo Järvinen
2025-07-29  7:38   ` [PATCH] " Miguel García Román

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).