diff mbox series

[U-Boot,RFC,v2,14/20] fastboot: Avoid re-parsing cmd_string for boot/reboot

Message ID 1525077174-6211-15-git-send-email-alex.kiernan@gmail.com
State RFC
Delegated to: Lukasz Majewski
Headers show
Series Add fastboot UDP support | expand

Commit Message

Alex Kiernan April 30, 2018, 8:32 a.m. UTC
When picking up boot/reboot after we've sent our result packet, use
the previously parsed command rather than redoing the strcmp.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

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

Comments

Joe Hershberger May 3, 2018, 9:17 p.m. UTC | #1
On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> When picking up boot/reboot after we've sent our result packet, use
> the previously parsed command rather than redoing the strcmp.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Jocelyn Bohr May 7, 2018, 9:20 p.m. UTC | #2
On Thu, May 3, 2018 at 2:18 PM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
> > When picking up boot/reboot after we've sent our result packet, use
> > the previously parsed command rather than redoing the strcmp.
> >
> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>

Reviewed-by: Jocelyn Bohr <bohr@google.com>
diff mbox series

Patch

diff --git a/net/fastboot.c b/net/fastboot.c
index edf78df..ad8c101 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -141,6 +141,7 @@  static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 	uchar *packet;
 	uchar *packet_base;
 	int len = 0;
+	int cmd = -1;
 	const char *error_msg = "An error occurred.";
 	short tmp;
 	struct fastboot_header fb_response_header = fb_header;
@@ -192,15 +193,13 @@  static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 			if (cmd_parameter)
 				cmd_parameter = strdup(cmd_parameter);
 		} else {
-			int i;
-
-			i = fastboot_lookup_command(cmd_string);
-			if (i >= 0) {
+			cmd = fastboot_lookup_command(cmd_string);
+			if (cmd >= 0) {
 				void (*fb_call)(char *cmd_parameter,
 						char *fastboot_data,
 						unsigned int fastboot_data_len,
 						char *response);
-				fb_call = fb_net_dispatch[i];
+				fb_call = fb_net_dispatch[cmd];
 				if (fb_call) {
 					fb_call(cmd_parameter, fastboot_data,
 						fastboot_data_len, response);
@@ -244,10 +243,10 @@  static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 
 	/* Continue boot process after sending response */
 	if (!strncmp("OKAY", response, 4)) {
-		if (!strcmp("boot", cmd_string)) {
+		if (cmd == FB_CMD_BOOT) {
 			boot_downloaded_image();
-		} else if (!strncmp("reboot", cmd_string, 6)) {
-			/* Matches reboot or reboot-bootloader */
+		} else if (cmd == FB_CMD_REBOOT ||
+			   cmd == FB_CMD_REBOOT_BOOTLOADER) {
 			do_reset(NULL, 0, 0, NULL);
 		}
 	}