Re: [PATCH v2] usbip: tools: Add usbip host driver availability check

From: Zongmin Zhou

Date: Wed Mar 25 2026 - 23:10:39 EST



On 2026/3/25 16:58, Greg KH wrote:
On Wed, Mar 25, 2026 at 10:26:34AM +0800, Zongmin Zhou wrote:
From: Zongmin Zhou <zhouzongmin@xxxxxxxxxx>

Currently, usbip_generic_driver_open() doesn't verify that the required
kernel module (usbip-host or usbip-vudc) is actually loaded.
The function returns success even when no driver is present,
leading to usbipd daemon run success without driver loaded.

So add a check function to ensure usbip host driver has been loaded.

Suggested-by: Shuah Khan <skhan@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Zongmin Zhou <zhouzongmin@xxxxxxxxxx>
---
Changes in v2:
- Use system calls directly instead of checking sysfs dir.

tools/usb/usbip/libsrc/usbip_device_driver.c | 7 +++++--
tools/usb/usbip/libsrc/usbip_host_driver.c | 8 ++++++--
2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/tools/usb/usbip/libsrc/usbip_device_driver.c b/tools/usb/usbip/libsrc/usbip_device_driver.c
index 927a151fa9aa..45ab647ef241 100644
--- a/tools/usb/usbip/libsrc/usbip_device_driver.c
+++ b/tools/usb/usbip/libsrc/usbip_device_driver.c
@@ -136,10 +136,13 @@ static int usbip_device_driver_open(struct usbip_host_driver *hdriver)
hdriver->ndevs = 0;
INIT_LIST_HEAD(&hdriver->edev_list);
- ret = usbip_generic_driver_open(hdriver);
- if (ret)
+ if (system("/sbin/lsmod | grep -q usbip_vudc")){
What happens if the module is built into the kernel?

err("please load " USBIP_CORE_MOD_NAME ".ko and "
USBIP_DEVICE_DRV_NAME ".ko!");
+ return -1;
+ }
+
+ ret = usbip_generic_driver_open(hdriver);
return ret;
}
diff --git a/tools/usb/usbip/libsrc/usbip_host_driver.c b/tools/usb/usbip/libsrc/usbip_host_driver.c
index 573e73ec36bd..f0ac941d4f6e 100644
--- a/tools/usb/usbip/libsrc/usbip_host_driver.c
+++ b/tools/usb/usbip/libsrc/usbip_host_driver.c
@@ -31,10 +31,14 @@ static int usbip_host_driver_open(struct usbip_host_driver *hdriver)
hdriver->ndevs = 0;
INIT_LIST_HEAD(&hdriver->edev_list);
- ret = usbip_generic_driver_open(hdriver);
- if (ret)
+ if (system("/sbin/lsmod | grep -q usbip_host")){
Same here, what happens if it is built in?
Thank you for pointing this out.
I apologize for not considering the built-in module case.

You are right that using lsmod | grep would incorrectly fail when usbip_host is built into the kernel (CONFIG_USBIP_HOST=y).
Usbip has always been built as a loadable module (.ko) by default, which led to this oversight.

To address this issue, would the following approach be acceptable?
1. Uses /sys/module/usbip_host to check wehther had been loaded, which exists for both loadable modules and built-in drivers.
2. Attempts to load the module via modprobe if it is not already loaded.

for example:
static int probe_usbip_host_driver(void)
{
     struct stat st;
     return !stat("/sys/module/usbip_host", &st);
}

static int usbip_host_driver_open(struct usbip_host_driver *hdriver)
{
     // 1. Check if driver is already loaded/built-in
     if (!probe_usbip_host_driver()) {
         // 2. Try to load the module
         system("/sbin/modprobe usbip-host > /dev/null 2>&1");
        // 3. Check again
          if (!probe_usbip_host_driver()) {
              err("please load " USBIP_CORE_MOD_NAME ".ko and "
                  USBIP_HOST_DRV_NAME ".ko!");
              return -1;
}
}

      // Continue with normal flow...
      ret = usbip_generic_driver_open(hdriver);
      return ret;
}

Does this look reasonable to you? I would be happy to submit a v3 patch with this approach if you agree.

thanks,

greg k-h