diff mbox

[U-Boot,v3,07/12] cmd: bootvx: Avoid strlen() calls when constructing VxWorks bootline

Message ID 1444274360-30189-8-git-send-email-bmeng.cn@gmail.com
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Bin Meng Oct. 8, 2015, 3:19 a.m. UTC
Remember the position in the VxWorks bootline buffer to avoid the call
to strlen() each time.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

---

Changes in v3:
- New patch to avoid strlen() calls when constructing VxWorks bootline

Changes in v2: None

 common/cmd_elf.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

Comments

Simon Glass Oct. 8, 2015, 4:09 p.m. UTC | #1
On 8 October 2015 at 04:19, Bin Meng <bmeng.cn@gmail.com> wrote:
> Remember the position in the VxWorks bootline buffer to avoid the call
> to strlen() each time.
>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>
> ---
>
> Changes in v3:
> - New patch to avoid strlen() calls when constructing VxWorks bootline
>
> Changes in v2: None
>
>  common/cmd_elf.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Simon Glass Oct. 18, 2015, 9:37 p.m. UTC | #2
On 8 October 2015 at 10:09, Simon Glass <sjg@chromium.org> wrote:
> On 8 October 2015 at 04:19, Bin Meng <bmeng.cn@gmail.com> wrote:
>> Remember the position in the VxWorks bootline buffer to avoid the call
>> to strlen() each time.
>>
>> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>>
>> ---
>>
>> Changes in v3:
>> - New patch to avoid strlen() calls when constructing VxWorks bootline
>>
>> Changes in v2: None
>>
>>  common/cmd_elf.c | 20 ++++++++++----------
>>  1 file changed, 10 insertions(+), 10 deletions(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-x86, thanks!
diff mbox

Patch

diff --git a/common/cmd_elf.c b/common/cmd_elf.c
index 62863df..6c95851 100644
--- a/common/cmd_elf.c
+++ b/common/cmd_elf.c
@@ -213,6 +213,7 @@  int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	char *bootline; /* Text of the bootline */
 	char *tmp; /* Temporary char pointer */
 	char build_buf[128]; /* Buffer for building the bootline */
+	int ptr = 0;
 
 	/*
 	 * Check the loadaddr variable.
@@ -277,30 +278,29 @@  int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		       max(strlen(bootline), (size_t)255));
 		flush_cache(bootaddr, max(strlen(bootline), (size_t)255));
 	} else {
-		sprintf(build_buf, CONFIG_SYS_VXWORKS_BOOT_DEVICE);
+		ptr = sprintf(build_buf, CONFIG_SYS_VXWORKS_BOOT_DEVICE);
 		tmp = getenv("bootfile");
 		if (tmp)
-			sprintf(&build_buf[strlen(build_buf)],
-				"%s:%s ", CONFIG_SYS_VXWORKS_SERVERNAME, tmp);
+			ptr += sprintf(build_buf + ptr, "%s:%s ",
+				       CONFIG_SYS_VXWORKS_SERVERNAME, tmp);
 		else
-			sprintf(&build_buf[strlen(build_buf)],
-				"%s:file ", CONFIG_SYS_VXWORKS_SERVERNAME);
+			ptr += sprintf(build_buf + ptr, "%s:file ",
+				       CONFIG_SYS_VXWORKS_SERVERNAME);
 
 		tmp = getenv("ipaddr");
 		if (tmp)
-			sprintf(&build_buf[strlen(build_buf)], "e=%s ", tmp);
+			ptr += sprintf(build_buf + ptr, "e=%s ", tmp);
 
 		tmp = getenv("serverip");
 		if (tmp)
-			sprintf(&build_buf[strlen(build_buf)], "h=%s ", tmp);
+			ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
 
 		tmp = getenv("hostname");
 		if (tmp)
-			sprintf(&build_buf[strlen(build_buf)], "tn=%s ", tmp);
+			ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
 
 #ifdef CONFIG_SYS_VXWORKS_ADD_PARAMS
-		sprintf(&build_buf[strlen(build_buf)],
-			CONFIG_SYS_VXWORKS_ADD_PARAMS);
+		ptr += sprintf(build_buf + ptr, CONFIG_SYS_VXWORKS_ADD_PARAMS);
 #endif
 
 		memcpy((void *)bootaddr, build_buf,