public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kdb: Remove optional size arguments from strscpy() calls
@ 2025-03-19 16:33 Thorsten Blum
  2025-03-19 21:11 ` Justin Stitt
  2025-03-20 14:28 ` Doug Anderson
  0 siblings, 2 replies; 3+ messages in thread
From: Thorsten Blum @ 2025-03-19 16:33 UTC (permalink / raw)
  To: Jason Wessel, Daniel Thompson, Douglas Anderson, Justin Stitt,
	Arnd Bergmann
  Cc: Thorsten Blum, Daniel Thompson, kgdb-bugreport, linux-kernel

If the destination buffer has a fixed length, strscpy() automatically
determines the size of the destination buffer using sizeof() if the
argument is omitted. This makes the explicit sizeof() unnecessary.

Furthermore, CMD_BUFLEN is equal to sizeof(kdb_prompt_str) and can also
be removed. Remove them to shorten and simplify the code.

No functional changes intended.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 kernel/debug/kdb/kdb_io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
index 6a77f1c779c4..9b11b10b120c 100644
--- a/kernel/debug/kdb/kdb_io.c
+++ b/kernel/debug/kdb/kdb_io.c
@@ -334,7 +334,7 @@ static char *kdb_read(char *buffer, size_t bufsize)
 		*cp = '\0';
 		p_tmp = strrchr(buffer, ' ');
 		p_tmp = (p_tmp ? p_tmp + 1 : buffer);
-		strscpy(tmpbuffer, p_tmp, sizeof(tmpbuffer));
+		strscpy(tmpbuffer, p_tmp);
 		*cp = tmp;
 
 		len = strlen(tmpbuffer);
@@ -452,7 +452,7 @@ static char *kdb_read(char *buffer, size_t bufsize)
 char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt)
 {
 	if (prompt && kdb_prompt_str != prompt)
-		strscpy(kdb_prompt_str, prompt, CMD_BUFLEN);
+		strscpy(kdb_prompt_str, prompt);
 	kdb_printf("%s", kdb_prompt_str);
 	kdb_nextline = 1;	/* Prompt and input resets line number */
 	return kdb_read(buffer, bufsize);

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

* Re: [PATCH] kdb: Remove optional size arguments from strscpy() calls
  2025-03-19 16:33 [PATCH] kdb: Remove optional size arguments from strscpy() calls Thorsten Blum
@ 2025-03-19 21:11 ` Justin Stitt
  2025-03-20 14:28 ` Doug Anderson
  1 sibling, 0 replies; 3+ messages in thread
From: Justin Stitt @ 2025-03-19 21:11 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Jason Wessel, Daniel Thompson, Douglas Anderson, Arnd Bergmann,
	Daniel Thompson, kgdb-bugreport, linux-kernel

On Wed, Mar 19, 2025 at 9:35 AM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> If the destination buffer has a fixed length, strscpy() automatically
> determines the size of the destination buffer using sizeof() if the
> argument is omitted. This makes the explicit sizeof() unnecessary.
>
> Furthermore, CMD_BUFLEN is equal to sizeof(kdb_prompt_str) and can also
> be removed. Remove them to shorten and simplify the code.
>
> No functional changes intended.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  kernel/debug/kdb/kdb_io.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
> index 6a77f1c779c4..9b11b10b120c 100644
> --- a/kernel/debug/kdb/kdb_io.c
> +++ b/kernel/debug/kdb/kdb_io.c
> @@ -334,7 +334,7 @@ static char *kdb_read(char *buffer, size_t bufsize)
>                 *cp = '\0';
>                 p_tmp = strrchr(buffer, ' ');
>                 p_tmp = (p_tmp ? p_tmp + 1 : buffer);
> -               strscpy(tmpbuffer, p_tmp, sizeof(tmpbuffer));
> +               strscpy(tmpbuffer, p_tmp);
>                 *cp = tmp;
>
>                 len = strlen(tmpbuffer);
> @@ -452,7 +452,7 @@ static char *kdb_read(char *buffer, size_t bufsize)
>  char *kdb_getstr(char *buffer, size_t bufsize, const char *prompt)
>  {
>         if (prompt && kdb_prompt_str != prompt)
> -               strscpy(kdb_prompt_str, prompt, CMD_BUFLEN);
> +               strscpy(kdb_prompt_str, prompt);
>         kdb_printf("%s", kdb_prompt_str);
>         kdb_nextline = 1;       /* Prompt and input resets line number */
>         return kdb_read(buffer, bufsize);

This matches the pattern of replacements I've done in the past, all looks good.

Reviewed-by: Justin Stitt <justinstitt@google.com>

Justin

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

* Re: [PATCH] kdb: Remove optional size arguments from strscpy() calls
  2025-03-19 16:33 [PATCH] kdb: Remove optional size arguments from strscpy() calls Thorsten Blum
  2025-03-19 21:11 ` Justin Stitt
@ 2025-03-20 14:28 ` Doug Anderson
  1 sibling, 0 replies; 3+ messages in thread
From: Doug Anderson @ 2025-03-20 14:28 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Jason Wessel, Daniel Thompson, Justin Stitt, Arnd Bergmann,
	Daniel Thompson, kgdb-bugreport, linux-kernel

Hi,

On Wed, Mar 19, 2025 at 9:35 AM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> If the destination buffer has a fixed length, strscpy() automatically
> determines the size of the destination buffer using sizeof() if the
> argument is omitted. This makes the explicit sizeof() unnecessary.
>
> Furthermore, CMD_BUFLEN is equal to sizeof(kdb_prompt_str) and can also
> be removed. Remove them to shorten and simplify the code.
>
> No functional changes intended.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  kernel/debug/kdb/kdb_io.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Douglas Anderson <dianders@chromium.org>

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

end of thread, other threads:[~2025-03-20 14:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-19 16:33 [PATCH] kdb: Remove optional size arguments from strscpy() calls Thorsten Blum
2025-03-19 21:11 ` Justin Stitt
2025-03-20 14:28 ` Doug Anderson

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