[PATCH v3 2/2] usbip: apply list options regardless of order
From: Jason Colapietro
Date: Tue Aug 11 2026 - 23:30:53 EST
usbip_list() acts on -r, -l and -d as soon as getopt_long() returns them,
so any option parsed afterwards is never seen. -p therefore only takes
effect when it precedes the mode selector: "usbip list -p -r <host>" is
parsable while "usbip list -r <host> -p" is not, and -l and -d behave the
same way. Nothing in the usage text suggests the order matters.
Record the requested mode during the option loop and run it once parsing
has finished, so -p applies wherever it appears on the command line. When
several mode selectors are given the first one still wins, as before.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Jason Colapietro <jasoncola1@xxxxxxxxx>
---
tools/usb/usbip/src/usbip_list.c | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/tools/usb/usbip/src/usbip_list.c b/tools/usb/usbip/src/usbip_list.c
index b9d60b87e47..632a968a088 100644
--- a/tools/usb/usbip/src/usbip_list.c
+++ b/tools/usb/usbip/src/usbip_list.c
@@ -343,6 +343,8 @@ int usbip_list(int argc, char *argv[])
};
bool parsable = false;
+ char *remote_host = NULL;
+ int action = 0;
int opt;
int ret = -1;
@@ -360,19 +362,36 @@ int usbip_list(int argc, char *argv[])
parsable = true;
break;
case 'r':
- ret = list_exported_devices(optarg, parsable);
- goto out;
+ if (!action) {
+ action = opt;
+ remote_host = optarg;
+ }
+ break;
case 'l':
- ret = list_devices(parsable);
- goto out;
case 'd':
- ret = list_gadget_devices(parsable);
- goto out;
+ if (!action)
+ action = opt;
+ break;
default:
goto err_out;
}
}
+ switch (action) {
+ case 'r':
+ ret = list_exported_devices(remote_host, parsable);
+ break;
+ case 'l':
+ ret = list_devices(parsable);
+ break;
+ case 'd':
+ ret = list_gadget_devices(parsable);
+ break;
+ default:
+ goto err_out;
+ }
+ goto out;
+
err_out:
usbip_list_usage();
out:
--
2.50.1 (Apple Git-155)