Skip to contentSkip to conversation

kdb: Remove optional size arguments from strscpy() calls

PATCH In review Thorsten Blum 3 participants 3 messages Mar 19, 2025 – Mar 20, 2025 KGDB / KDB /debug_core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kdb: Remove optional size arguments from strscpy() calls

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.

---
 kernel/debug/kdb/kdb_io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/debug/kdb/kdb_io.c +2 -2
index 6a77f1c779c4..9b11b10b120c 100644
@@ -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);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Thorsten Blum

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.

---
 kernel/debug/kdb/kdb_io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/debug/kdb/kdb_io.c +1 -1
index 6a77f1c779c4..9b11b10b120c 100644
@@ -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);

kernel/debug/kdb/kdb_io.c static char *kdb_read(char *buffer, size_t bufsize) · line 458

Quoted 8 lines
kernel/debug/kdb/kdb_io.c +1 -1
@@ -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.

Justin

reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Thorsten Blum

Hi,

Quoted 8 lines · Thorsten Blum

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.

Quoted 6 lines

No functional changes intended.

---
 kernel/debug/kdb/kdb_io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)