* [PATCH] acpica: Removing deprecated strncpy()
@ 2025-04-14 7:35 Kevin Paul Reddy Janagari
2025-04-14 14:25 ` Rafael J. Wysocki
0 siblings, 1 reply; 2+ messages in thread
From: Kevin Paul Reddy Janagari @ 2025-04-14 7:35 UTC (permalink / raw)
To: robert.moore, rafael.j.wysocki, lenb
Cc: linux-acpi, acpica-devel, linux-kernel, kevinpaul468
This patch suggests the replacement of strncpy with strscpy
as per Documentation/process/deprecated.
The strncpy() fails to guarantee NULL termination,
The function adds zero pads which isn't really convenient for short strings
as it may cause performance issues.
strscpy() is a preferred replacement because
it overcomes the limitations of strncpy mentioned above.
Compile Tested
Signed-off-by: Kevin Paul Reddy Janagari <kevinpaul468@gmail.com>
---
drivers/acpi/acpica/exconvrt.c | 2 +-
drivers/acpi/acpica/tbfind.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/acpi/acpica/exconvrt.c b/drivers/acpi/acpica/exconvrt.c
index bb1be42daee1..648e68a31e1f 100644
--- a/drivers/acpi/acpica/exconvrt.c
+++ b/drivers/acpi/acpica/exconvrt.c
@@ -226,7 +226,7 @@ acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc,
/* Copy the string to the buffer */
new_buf = return_desc->buffer.pointer;
- strncpy((char *)new_buf, (char *)obj_desc->string.pointer,
+ strscpy((char *)new_buf, (char *)obj_desc->string.pointer,
obj_desc->string.length);
break;
diff --git a/drivers/acpi/acpica/tbfind.c b/drivers/acpi/acpica/tbfind.c
index 1c1b2e284bd9..5536d1755188 100644
--- a/drivers/acpi/acpica/tbfind.c
+++ b/drivers/acpi/acpica/tbfind.c
@@ -57,8 +57,8 @@ acpi_tb_find_table(char *signature,
memset(&header, 0, sizeof(struct acpi_table_header));
ACPI_COPY_NAMESEG(header.signature, signature);
- strncpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
- strncpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
+ strscpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
+ strscpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
/* Search for the table */
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] acpica: Removing deprecated strncpy()
2025-04-14 7:35 [PATCH] acpica: Removing deprecated strncpy() Kevin Paul Reddy Janagari
@ 2025-04-14 14:25 ` Rafael J. Wysocki
0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2025-04-14 14:25 UTC (permalink / raw)
To: Kevin Paul Reddy Janagari
Cc: robert.moore, rafael.j.wysocki, lenb, linux-acpi, acpica-devel,
linux-kernel
On Mon, Apr 14, 2025 at 9:35 AM Kevin Paul Reddy Janagari
<kevinpaul468@gmail.com> wrote:
>
> This patch suggests the replacement of strncpy with strscpy
> as per Documentation/process/deprecated.
> The strncpy() fails to guarantee NULL termination,
> The function adds zero pads which isn't really convenient for short strings
> as it may cause performance issues.
>
> strscpy() is a preferred replacement because
> it overcomes the limitations of strncpy mentioned above.
>
> Compile Tested
ACPICA material is primarily handled by the upstream ACPICA project on
GitHub, so ACPICA changes should first be submitted to upstream ACPICA as
indicated on this list for many times, see for instance:
https://lore.kernel.org/linux-acpi/CAJZ5v0gUDxrAn4W+Rf3ifjrg8Z9ZzTTOZjPFSSN5488mPqzXeA@mail.gmail.com/
> Signed-off-by: Kevin Paul Reddy Janagari <kevinpaul468@gmail.com>
> ---
> drivers/acpi/acpica/exconvrt.c | 2 +-
> drivers/acpi/acpica/tbfind.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/acpi/acpica/exconvrt.c b/drivers/acpi/acpica/exconvrt.c
> index bb1be42daee1..648e68a31e1f 100644
> --- a/drivers/acpi/acpica/exconvrt.c
> +++ b/drivers/acpi/acpica/exconvrt.c
> @@ -226,7 +226,7 @@ acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc,
> /* Copy the string to the buffer */
>
> new_buf = return_desc->buffer.pointer;
> - strncpy((char *)new_buf, (char *)obj_desc->string.pointer,
> + strscpy((char *)new_buf, (char *)obj_desc->string.pointer,
> obj_desc->string.length);
> break;
>
> diff --git a/drivers/acpi/acpica/tbfind.c b/drivers/acpi/acpica/tbfind.c
> index 1c1b2e284bd9..5536d1755188 100644
> --- a/drivers/acpi/acpica/tbfind.c
> +++ b/drivers/acpi/acpica/tbfind.c
> @@ -57,8 +57,8 @@ acpi_tb_find_table(char *signature,
>
> memset(&header, 0, sizeof(struct acpi_table_header));
> ACPI_COPY_NAMESEG(header.signature, signature);
> - strncpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
> - strncpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
> + strscpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
> + strscpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
>
> /* Search for the table */
>
> --
> 2.39.5
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-14 14:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-14 7:35 [PATCH] acpica: Removing deprecated strncpy() Kevin Paul Reddy Janagari
2025-04-14 14:25 ` Rafael J. Wysocki
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).