diff mbox series

[v2,06/12] bootm: Use size rather than length for CONSOLE_ARG

Message ID 20201105173349.903603-7-sjg@chromium.org
State Accepted
Commit 6cd92b1a7c62dc808e74f4638a027da3f6a044ce
Delegated to: Tom Rini
Headers show
Series bootm: Support substitions in bootargs and add tests | expand

Commit Message

Simon Glass Nov. 5, 2020, 5:33 p.m. UTC
Use the size (including terminator) for in this function, rather than
the length. This is arguably easier to follow, with the coming
refactor.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 common/bootm.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

Tom Rini Dec. 7, 2020, 10:19 p.m. UTC | #1
On Thu, Nov 05, 2020 at 10:33:42AM -0700, Simon Glass wrote:

> Use the size (including terminator) for in this function, rather than
> the length. This is arguably easier to follow, with the coming
> refactor.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/common/bootm.c b/common/bootm.c
index 9b0c81d6534..9295cf5cd3e 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -465,8 +465,8 @@  ulong bootm_disable_interrupts(void)
 	return iflag;
 }
 
-#define CONSOLE_ARG     "console="
-#define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
+#define CONSOLE_ARG		"console="
+#define CONSOLE_ARG_SIZE	sizeof(CONSOLE_ARG)
 
 int bootm_process_cmdline_env(bool do_silent)
 {
@@ -500,7 +500,7 @@  int bootm_process_cmdline_env(bool do_silent)
 		char *start = strstr(cmdline, CONSOLE_ARG);
 
 		/* Allocate space for maximum possible new command line */
-		buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1);
+		buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_SIZE);
 		if (!buf) {
 			debug("%s: out of memory\n", __func__);
 			return -ENOSPC;
@@ -508,13 +508,14 @@  int bootm_process_cmdline_env(bool do_silent)
 
 		if (start) {
 			char *end = strchr(start, ' ');
-			int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN;
+			int start_bytes;
 
-			strncpy(buf, cmdline, num_start_bytes);
+			start_bytes = start - cmdline + CONSOLE_ARG_SIZE - 1;
+			strncpy(buf, cmdline, start_bytes);
 			if (end)
-				strcpy(buf + num_start_bytes, end);
+				strcpy(buf + start_bytes, end);
 			else
-				buf[num_start_bytes] = '\0';
+				buf[start_bytes] = '\0';
 		} else {
 			sprintf(buf, "%s %s", cmdline, CONSOLE_ARG);
 		}