All of lore.kernel.org
 help / color / mirror / Atom feed
From: Justin Stitt <justinstitt@google.com>
To: Robert Moore <robert.moore@intel.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org,
	acpica-devel@lists.linuxfoundation.org,
	linux-kernel@vger.kernel.org,
	Nick Desaulniers <ndesaulniers@google.com>,
	Kees Cook <keescook@chromium.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Justin Stitt <justinstitt@google.com>
Subject: [PATCH RFC] ACPICA: remove acpi_ut_safe_strncpy in favor of strscpy
Date: Thu, 24 Aug 2023 22:02:02 +0000	[thread overview]
Message-ID: <20230824-strncpy-drivers-acpi-acpica-v1-1-d027ba183b66@google.com> (raw)

I wanted to gather some thoughts on removing `acpi_ut_safe_strncpy` (and
potentially other `acpi...safe...()` interfaces) in favor of
pre-existing interfaces in the kernel (like strscpy).

Running a git blame shows these functions were implemented 10 years ago
and their implementations generally mirror the _newer_ and more robust
stuff in lib/string.h -- Let's just use these, right?

I appreciate any comments and whether or not I should stop at just
`strncpy`.

Thanks

Signed-off-by: Justin Stitt <justinstitt@google.com>
---
 drivers/acpi/acpica/acutils.h   | 2 --
 drivers/acpi/acpica/dbfileio.c  | 2 +-
 drivers/acpi/acpica/psutils.c   | 2 +-
 drivers/acpi/acpica/utnonansi.c | 8 --------
 drivers/acpi/acpica/uttrack.c   | 2 +-
 5 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index edfdbbef81c1..4d5c401a14b4 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -626,8 +626,6 @@ void acpi_ut_repair_name(char *name);
 #if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION) || defined (ACPI_DEBUG_OUTPUT)
 u8 acpi_ut_safe_strcpy(char *dest, acpi_size dest_size, char *source);
 
-void acpi_ut_safe_strncpy(char *dest, char *source, acpi_size dest_size);
-
 u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source);
 
 u8
diff --git a/drivers/acpi/acpica/dbfileio.c b/drivers/acpi/acpica/dbfileio.c
index e1b6e54a96ac..197e1ff1f72c 100644
--- a/drivers/acpi/acpica/dbfileio.c
+++ b/drivers/acpi/acpica/dbfileio.c
@@ -63,7 +63,7 @@ void acpi_db_open_debug_file(char *name)
 	}
 
 	acpi_os_printf("Debug output file %s opened\n", name);
-	acpi_ut_safe_strncpy(acpi_gbl_db_debug_filename, name,
+	strscpy(acpi_gbl_db_debug_filename, name,
 			     sizeof(acpi_gbl_db_debug_filename));
 	acpi_gbl_db_output_to_file = TRUE;
 }
diff --git a/drivers/acpi/acpica/psutils.c b/drivers/acpi/acpica/psutils.c
index d550c4af4702..95af2c74e00b 100644
--- a/drivers/acpi/acpica/psutils.c
+++ b/drivers/acpi/acpica/psutils.c
@@ -60,7 +60,7 @@ void acpi_ps_init_op(union acpi_parse_object *op, u16 opcode)
 	op->common.descriptor_type = ACPI_DESC_TYPE_PARSER;
 	op->common.aml_opcode = opcode;
 
-	ACPI_DISASM_ONLY_MEMBERS(acpi_ut_safe_strncpy(op->common.aml_op_name,
+	ACPI_DISASM_ONLY_MEMBERS(strscpy(op->common.aml_op_name,
 						      (acpi_ps_get_opcode_info
 						       (opcode))->name,
 						      sizeof(op->common.
diff --git a/drivers/acpi/acpica/utnonansi.c b/drivers/acpi/acpica/utnonansi.c
index ff0802ace19b..a465e5a1d309 100644
--- a/drivers/acpi/acpica/utnonansi.c
+++ b/drivers/acpi/acpica/utnonansi.c
@@ -164,12 +164,4 @@ acpi_ut_safe_strncat(char *dest,
 	return (FALSE);
 }
 
-void acpi_ut_safe_strncpy(char *dest, char *source, acpi_size dest_size)
-{
-	/* Always terminate destination string */
-
-	strncpy(dest, source, dest_size);
-	dest[dest_size - 1] = 0;
-}
-
 #endif
diff --git a/drivers/acpi/acpica/uttrack.c b/drivers/acpi/acpica/uttrack.c
index f5f5da441458..a96a86bc5781 100644
--- a/drivers/acpi/acpica/uttrack.c
+++ b/drivers/acpi/acpica/uttrack.c
@@ -368,7 +368,7 @@ acpi_ut_track_allocation(struct acpi_debug_mem_block *allocation,
 	allocation->component = component;
 	allocation->line = line;
 
-	acpi_ut_safe_strncpy(allocation->module, (char *)module,
+	strscpy(allocation->module, (char *)module,
 			     ACPI_MAX_MODULE_NAME);
 
 	if (!element) {

---
base-commit: f9604036a3fb6149badf346994b46b03f9292db7
change-id: 20230824-strncpy-drivers-acpi-acpica-321af3eb414e

Best regards,
--
Justin Stitt <justinstitt@google.com>


WARNING: multiple messages have this Message-ID (diff)
From: Justin Stitt <justinstitt@google.com>
To: Robert Moore <robert.moore@intel.com>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Len Brown <lenb@kernel.org>
Cc: Kees Cook <keescook@chromium.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	linux-kernel@vger.kernel.org,
	Nathan Chancellor <nathan@kernel.org>,
	linux-acpi@vger.kernel.org, Justin Stitt <justinstitt@google.com>,
	acpica-devel@lists.linuxfoundation.org
Subject: [Acpica-devel] [PATCH RFC] ACPICA: remove acpi_ut_safe_strncpy in favor of strscpy
Date: Thu, 24 Aug 2023 22:02:07 -0000	[thread overview]
Message-ID: <20230824-strncpy-drivers-acpi-acpica-v1-1-d027ba183b66@google.com> (raw)

I wanted to gather some thoughts on removing `acpi_ut_safe_strncpy` (and
potentially other `acpi...safe...()` interfaces) in favor of
pre-existing interfaces in the kernel (like strscpy).

Running a git blame shows these functions were implemented 10 years ago
and their implementations generally mirror the _newer_ and more robust
stuff in lib/string.h -- Let's just use these, right?

I appreciate any comments and whether or not I should stop at just
`strncpy`.

Thanks

Signed-off-by: Justin Stitt <justinstitt@google.com>
---
 drivers/acpi/acpica/acutils.h   | 2 --
 drivers/acpi/acpica/dbfileio.c  | 2 +-
 drivers/acpi/acpica/psutils.c   | 2 +-
 drivers/acpi/acpica/utnonansi.c | 8 --------
 drivers/acpi/acpica/uttrack.c   | 2 +-
 5 files changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index edfdbbef81c1..4d5c401a14b4 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -626,8 +626,6 @@ void acpi_ut_repair_name(char *name);
 #if defined (ACPI_DEBUGGER) || defined (ACPI_APPLICATION) || defined (ACPI_DEBUG_OUTPUT)
 u8 acpi_ut_safe_strcpy(char *dest, acpi_size dest_size, char *source);
 
-void acpi_ut_safe_strncpy(char *dest, char *source, acpi_size dest_size);
-
 u8 acpi_ut_safe_strcat(char *dest, acpi_size dest_size, char *source);
 
 u8
diff --git a/drivers/acpi/acpica/dbfileio.c b/drivers/acpi/acpica/dbfileio.c
index e1b6e54a96ac..197e1ff1f72c 100644
--- a/drivers/acpi/acpica/dbfileio.c
+++ b/drivers/acpi/acpica/dbfileio.c
@@ -63,7 +63,7 @@ void acpi_db_open_debug_file(char *name)
 	}
 
 	acpi_os_printf("Debug output file %s opened\n", name);
-	acpi_ut_safe_strncpy(acpi_gbl_db_debug_filename, name,
+	strscpy(acpi_gbl_db_debug_filename, name,
 			     sizeof(acpi_gbl_db_debug_filename));
 	acpi_gbl_db_output_to_file = TRUE;
 }
diff --git a/drivers/acpi/acpica/psutils.c b/drivers/acpi/acpica/psutils.c
index d550c4af4702..95af2c74e00b 100644
--- a/drivers/acpi/acpica/psutils.c
+++ b/drivers/acpi/acpica/psutils.c
@@ -60,7 +60,7 @@ void acpi_ps_init_op(union acpi_parse_object *op, u16 opcode)
 	op->common.descriptor_type = ACPI_DESC_TYPE_PARSER;
 	op->common.aml_opcode = opcode;
 
-	ACPI_DISASM_ONLY_MEMBERS(acpi_ut_safe_strncpy(op->common.aml_op_name,
+	ACPI_DISASM_ONLY_MEMBERS(strscpy(op->common.aml_op_name,
 						      (acpi_ps_get_opcode_info
 						       (opcode))->name,
 						      sizeof(op->common.
diff --git a/drivers/acpi/acpica/utnonansi.c b/drivers/acpi/acpica/utnonansi.c
index ff0802ace19b..a465e5a1d309 100644
--- a/drivers/acpi/acpica/utnonansi.c
+++ b/drivers/acpi/acpica/utnonansi.c
@@ -164,12 +164,4 @@ acpi_ut_safe_strncat(char *dest,
 	return (FALSE);
 }
 
-void acpi_ut_safe_strncpy(char *dest, char *source, acpi_size dest_size)
-{
-	/* Always terminate destination string */
-
-	strncpy(dest, source, dest_size);
-	dest[dest_size - 1] = 0;
-}
-
 #endif
diff --git a/drivers/acpi/acpica/uttrack.c b/drivers/acpi/acpica/uttrack.c
index f5f5da441458..a96a86bc5781 100644
--- a/drivers/acpi/acpica/uttrack.c
+++ b/drivers/acpi/acpica/uttrack.c
@@ -368,7 +368,7 @@ acpi_ut_track_allocation(struct acpi_debug_mem_block *allocation,
 	allocation->component = component;
 	allocation->line = line;
 
-	acpi_ut_safe_strncpy(allocation->module, (char *)module,
+	strscpy(allocation->module, (char *)module,
 			     ACPI_MAX_MODULE_NAME);
 
 	if (!element) {

---
base-commit: f9604036a3fb6149badf346994b46b03f9292db7
change-id: 20230824-strncpy-drivers-acpi-acpica-321af3eb414e

Best regards,
--
Justin Stitt <justinstitt@google.com>


             reply	other threads:[~2023-08-24 22:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24 22:02 Justin Stitt [this message]
2023-08-24 22:02 ` [Acpica-devel] [PATCH RFC] ACPICA: remove acpi_ut_safe_strncpy in favor of strscpy Justin Stitt
2023-08-24 23:21 ` Kees Cook
2023-08-24 23:21   ` [Acpica-devel] " Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230824-strncpy-drivers-acpi-acpica-v1-1-d027ba183b66@google.com \
    --to=justinstitt@google.com \
    --cc=acpica-devel@lists.linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=robert.moore@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.