Skip to content

Commit

Permalink
tools: usbip: detach: avoid calling strlen() at each iteration
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
ericcurtin authored and gregkh committed Sep 22, 2015
1 parent 1f93e4a commit 0c61814
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tools/usb/usbip/src/usbip_detach.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0c61814

Please sign in to comment.