public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform/surface: Replace deprecated strcpy in surface_button_add
@ 2026-01-05 12:18 Thorsten Blum
  2026-01-05 12:52 ` Chen, Yu C
  0 siblings, 1 reply; 6+ messages in thread
From: Thorsten Blum @ 2026-01-05 12:18 UTC (permalink / raw)
  To: Chen Yu, Hans de Goede, Ilpo Järvinen, Maximilian Luz
  Cc: Thorsten Blum, platform-driver-x86, linux-kernel

strcpy() has been deprecated [1] because it performs no bounds checking
on the destination buffer, which can lead to buffer overflows. Replace
it with the safer strscpy().  No functional changes.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 drivers/platform/surface/surfacepro3_button.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/surface/surfacepro3_button.c b/drivers/platform/surface/surfacepro3_button.c
index 2755601f979c..d027a064a62d 100644
--- a/drivers/platform/surface/surfacepro3_button.c
+++ b/drivers/platform/surface/surfacepro3_button.c
@@ -10,6 +10,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/string.h>
 #include <linux/types.h>
 #include <linux/input.h>
 #include <linux/acpi.h>
@@ -211,7 +212,7 @@ static int surface_button_add(struct acpi_device *device)
 	}
 
 	name = acpi_device_name(device);
-	strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
+	strscpy(acpi_device_name(device), SURFACE_BUTTON_DEVICE_NAME);
 	snprintf(button->phys, sizeof(button->phys), "%s/buttons", hid);
 
 	input->name = name;
-- 
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4


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

* Re: [PATCH] platform/surface: Replace deprecated strcpy in surface_button_add
  2026-01-05 12:18 [PATCH] platform/surface: Replace deprecated strcpy in surface_button_add Thorsten Blum
@ 2026-01-05 12:52 ` Chen, Yu C
  2026-01-05 13:38   ` Thorsten Blum
  0 siblings, 1 reply; 6+ messages in thread
From: Chen, Yu C @ 2026-01-05 12:52 UTC (permalink / raw)
  To: Thorsten Blum, Hans de Goede, Ilpo Järvinen, Maximilian Luz
  Cc: platform-driver-x86, linux-kernel

Hi Thorsten,

On 1/5/2026 8:18 PM, Thorsten Blum wrote:
> strcpy() has been deprecated [1] because it performs no bounds checking
> on the destination buffer, which can lead to buffer overflows. Replace
> it with the safer strscpy().  No functional changes.
> 
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>   drivers/platform/surface/surfacepro3_button.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/surface/surfacepro3_button.c b/drivers/platform/surface/surfacepro3_button.c
> index 2755601f979c..d027a064a62d 100644
> --- a/drivers/platform/surface/surfacepro3_button.c
> +++ b/drivers/platform/surface/surfacepro3_button.c
> @@ -10,6 +10,7 @@
>   #include <linux/kernel.h>
>   #include <linux/module.h>
>   #include <linux/init.h>
> +#include <linux/string.h>
>   #include <linux/types.h>
>   #include <linux/input.h>
>   #include <linux/acpi.h>
> @@ -211,7 +212,7 @@ static int surface_button_add(struct acpi_device *device)
>   	}
>   
>   	name = acpi_device_name(device);
> -	strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
> +	strscpy(acpi_device_name(device), SURFACE_BUTTON_DEVICE_NAME);

Thanks for the fix, a minor question might be why we do not reuse
name by strscpy(name, SURFACE_BUTTON_DEVICE_NAME) ?

thanks,
Chenyu

>   	snprintf(button->phys, sizeof(button->phys), "%s/buttons", hid);
>   
>   	input->name = name;

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

* Re: [PATCH] platform/surface: Replace deprecated strcpy in surface_button_add
  2026-01-05 12:52 ` Chen, Yu C
@ 2026-01-05 13:38   ` Thorsten Blum
  2026-01-05 14:21     ` Ilpo Järvinen
  2026-01-05 14:39     ` Chen, Yu C
  0 siblings, 2 replies; 6+ messages in thread
From: Thorsten Blum @ 2026-01-05 13:38 UTC (permalink / raw)
  To: Chen, Yu C
  Cc: Hans de Goede, Ilpo Järvinen, Maximilian Luz,
	platform-driver-x86, linux-kernel

On 5. Jan 2026, at 13:52, Chen, Yu C wrote:
>> -	strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
>> +	strscpy(acpi_device_name(device), SURFACE_BUTTON_DEVICE_NAME);
> 
> Thanks for the fix, a minor question might be why we do not reuse
> name by strscpy(name, SURFACE_BUTTON_DEVICE_NAME) ?

Because 'name' is a 'char *' from which the size of the destination
buffer cannot be inferred by the 2-argument version of strscpy().

Using 'name' would force us to use strscpy() with 3 arguments:

strscpy(name, SURFACE_BUTTON_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);

Thanks,
Thorsten


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

* Re: [PATCH] platform/surface: Replace deprecated strcpy in surface_button_add
  2026-01-05 13:38   ` Thorsten Blum
@ 2026-01-05 14:21     ` Ilpo Järvinen
  2026-01-05 14:41       ` Chen, Yu C
  2026-01-05 14:39     ` Chen, Yu C
  1 sibling, 1 reply; 6+ messages in thread
From: Ilpo Järvinen @ 2026-01-05 14:21 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Chen, Yu C, Hans de Goede, Maximilian Luz, platform-driver-x86,
	LKML

On Mon, 5 Jan 2026, Thorsten Blum wrote:

> On 5. Jan 2026, at 13:52, Chen, Yu C wrote:
> >> -	strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
> >> +	strscpy(acpi_device_name(device), SURFACE_BUTTON_DEVICE_NAME);
> > 
> > Thanks for the fix, a minor question might be why we do not reuse
> > name by strscpy(name, SURFACE_BUTTON_DEVICE_NAME) ?
> 
> Because 'name' is a 'char *' from which the size of the destination
> buffer cannot be inferred by the 2-argument version of strscpy().
> 
> Using 'name' would force us to use strscpy() with 3 arguments:
> 
> strscpy(name, SURFACE_BUTTON_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);

I suggest you just remove 'name' instead. It seems pretty useless to begin 
with but especially after your patch. :-)

Please also add () to the subject line after function names.

-- 
 i.


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

* Re: [PATCH] platform/surface: Replace deprecated strcpy in surface_button_add
  2026-01-05 13:38   ` Thorsten Blum
  2026-01-05 14:21     ` Ilpo Järvinen
@ 2026-01-05 14:39     ` Chen, Yu C
  1 sibling, 0 replies; 6+ messages in thread
From: Chen, Yu C @ 2026-01-05 14:39 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Hans de Goede, Ilpo Järvinen, Maximilian Luz,
	platform-driver-x86, linux-kernel

On 1/5/2026 9:38 PM, Thorsten Blum wrote:
> On 5. Jan 2026, at 13:52, Chen, Yu C wrote:
>>> -	strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
>>> +	strscpy(acpi_device_name(device), SURFACE_BUTTON_DEVICE_NAME);
>>
>> Thanks for the fix, a minor question might be why we do not reuse
>> name by strscpy(name, SURFACE_BUTTON_DEVICE_NAME) ?
> 
> Because 'name' is a 'char *' from which the size of the destination
> buffer cannot be inferred by the 2-argument version of strscpy().
> 
> Using 'name' would force us to use strscpy() with 3 arguments:
> 
> strscpy(name, SURFACE_BUTTON_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);
> 

Thanks for the explanation!

Reviewed-by: Chen Yu <yu.c.chen@intel.com>

thanks,
Chenyu

> Thanks,
> Thorsten
> 

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

* Re: [PATCH] platform/surface: Replace deprecated strcpy in surface_button_add
  2026-01-05 14:21     ` Ilpo Järvinen
@ 2026-01-05 14:41       ` Chen, Yu C
  0 siblings, 0 replies; 6+ messages in thread
From: Chen, Yu C @ 2026-01-05 14:41 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Hans de Goede, Maximilian Luz, platform-driver-x86, LKML,
	Thorsten Blum

On 1/5/2026 10:21 PM, Ilpo Järvinen wrote:
> On Mon, 5 Jan 2026, Thorsten Blum wrote:
> 
>> On 5. Jan 2026, at 13:52, Chen, Yu C wrote:
>>>> -	strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
>>>> +	strscpy(acpi_device_name(device), SURFACE_BUTTON_DEVICE_NAME);
>>>
>>> Thanks for the fix, a minor question might be why we do not reuse
>>> name by strscpy(name, SURFACE_BUTTON_DEVICE_NAME) ?
>>
>> Because 'name' is a 'char *' from which the size of the destination
>> buffer cannot be inferred by the 2-argument version of strscpy().
>>
>> Using 'name' would force us to use strscpy() with 3 arguments:
>>
>> strscpy(name, SURFACE_BUTTON_DEVICE_NAME, MAX_ACPI_DEVICE_NAME_LEN);
> 
> I suggest you just remove 'name' instead. It seems pretty useless to begin
> with but especially after your patch. :-)

It was still used by other places.

thanks,
Chenyu
> 
> Please also add () to the subject line after function names.
> 

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

end of thread, other threads:[~2026-01-05 14:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-05 12:18 [PATCH] platform/surface: Replace deprecated strcpy in surface_button_add Thorsten Blum
2026-01-05 12:52 ` Chen, Yu C
2026-01-05 13:38   ` Thorsten Blum
2026-01-05 14:21     ` Ilpo Järvinen
2026-01-05 14:41       ` Chen, Yu C
2026-01-05 14:39     ` Chen, Yu C

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox