]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
tools: usbip: detach: avoid calling strlen() at each iteration
authorEric Curtin <ericcurtin17@gmail.com>
Tue, 15 Sep 2015 20:27:20 +0000 (21:27 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Sep 2015 19:07:45 +0000 (12:07 -0700)
Instead of calling strlen on every iteration of the for loop, just call it
once and cache the result in a temporary local variable which will be used
in the for loop instead.

Signed-off-by: Eric Curtin <ericcurtin17@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/usb/usbip/src/usbip_detach.c

index 05c6d15856eb649d1b1e46e685988ebb1accdb46..9db9d21bb2ecee75c89c027ccb07cfdeb21062de 100644 (file)
@@ -47,7 +47,9 @@ static int detach_port(char *port)
        uint8_t portnum;
        char path[PATH_MAX+1];
 
-       for (unsigned int i = 0; i < strlen(port); i++)
+       unsigned int port_len = strlen(port);
+
+       for (unsigned int i = 0; i < port_len; i++)
                if (!isdigit(port[i])) {
                        err("invalid port %s", port);
                        return -1;