public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usbip: tools: Add usbip host driver availability check
@ 2026-03-03  8:17 Zongmin Zhou
  2026-03-10 22:28 ` Shuah Khan
  2026-03-11 12:13 ` [PATCH] " Greg KH
  0 siblings, 2 replies; 15+ messages in thread
From: Zongmin Zhou @ 2026-03-03  8:17 UTC (permalink / raw)
  To: valentina.manea.m, shuah, i; +Cc: linux-usb, linux-kernel, Zongmin Zhou

From: Zongmin Zhou <zhouzongmin@kylinos.cn>

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.

Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
---
 tools/usb/usbip/libsrc/usbip_device_driver.c |  2 ++
 tools/usb/usbip/libsrc/usbip_host_common.c   | 31 ++++++++++++++++++++
 tools/usb/usbip/libsrc/usbip_host_common.h   |  2 ++
 tools/usb/usbip/libsrc/usbip_host_driver.c   |  2 ++
 4 files changed, 37 insertions(+)

diff --git a/tools/usb/usbip/libsrc/usbip_device_driver.c b/tools/usb/usbip/libsrc/usbip_device_driver.c
index 927a151fa9aa..6da000fab26d 100644
--- a/tools/usb/usbip/libsrc/usbip_device_driver.c
+++ b/tools/usb/usbip/libsrc/usbip_device_driver.c
@@ -147,6 +147,8 @@ static int usbip_device_driver_open(struct usbip_host_driver *hdriver)
 struct usbip_host_driver device_driver = {
 	.edev_list = LIST_HEAD_INIT(device_driver.edev_list),
 	.udev_subsystem = "udc",
+	.bus_type = "platform",
+	.drv_name = USBIP_DEVICE_DRV_NAME,
 	.ops = {
 		.open = usbip_device_driver_open,
 		.close = usbip_generic_driver_close,
diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c b/tools/usb/usbip/libsrc/usbip_host_common.c
index ca78aa368476..900370095b61 100644
--- a/tools/usb/usbip/libsrc/usbip_host_common.c
+++ b/tools/usb/usbip/libsrc/usbip_host_common.c
@@ -164,6 +164,31 @@ static void usbip_exported_device_destroy(struct list_head *devs)
 	}
 }
 
+/* Check if the usbip host driver is available in sysfs */
+static int check_driver_available(struct usbip_host_driver *hdriver)
+{
+	char driver_path[SYSFS_PATH_MAX];
+	struct stat st;
+	int ret;
+
+	if (!hdriver->drv_name || !hdriver->bus_type)
+		return 0;
+
+	//Check if the usbip-host or usbip-vudc driver directory exists in sysfs.
+	snprintf(driver_path, sizeof(driver_path), "%s/%s/%s/%s/%s",
+		SYSFS_MNT_PATH, SYSFS_BUS_NAME, hdriver->bus_type,
+		SYSFS_DRIVERS_NAME, hdriver->drv_name);
+
+	ret = stat(driver_path, &st);
+	if (ret == 0 && S_ISDIR(st.st_mode)) {
+		dbg("driver '%s' is available", hdriver->drv_name);
+		return 1;
+	}
+
+	return 0;
+}
+
+
 int usbip_generic_driver_open(struct usbip_host_driver *hdriver)
 {
 	int rc;
@@ -174,6 +199,12 @@ int usbip_generic_driver_open(struct usbip_host_driver *hdriver)
 		return -1;
 	}
 
+	//Check if the required driver is actually available.
+	if (!check_driver_available(hdriver)) {
+		err("please load '%s' kernel module", hdriver->drv_name);
+		goto err;
+	}
+
 	rc = refresh_exported_devices(hdriver);
 	if (rc < 0)
 		goto err;
diff --git a/tools/usb/usbip/libsrc/usbip_host_common.h b/tools/usb/usbip/libsrc/usbip_host_common.h
index f46967c0aa18..cf9bd60846cf 100644
--- a/tools/usb/usbip/libsrc/usbip_host_common.h
+++ b/tools/usb/usbip/libsrc/usbip_host_common.h
@@ -40,6 +40,8 @@ struct usbip_host_driver {
 	/* list of exported device */
 	struct list_head edev_list;
 	const char *udev_subsystem;
+	const char *bus_type;
+	const char *drv_name;
 	struct usbip_host_driver_ops ops;
 };
 
diff --git a/tools/usb/usbip/libsrc/usbip_host_driver.c b/tools/usb/usbip/libsrc/usbip_host_driver.c
index 573e73ec36bd..e8f9d2ee2497 100644
--- a/tools/usb/usbip/libsrc/usbip_host_driver.c
+++ b/tools/usb/usbip/libsrc/usbip_host_driver.c
@@ -41,6 +41,8 @@ static int usbip_host_driver_open(struct usbip_host_driver *hdriver)
 struct usbip_host_driver host_driver = {
 	.edev_list = LIST_HEAD_INIT(host_driver.edev_list),
 	.udev_subsystem = "usb",
+	.bus_type = "usb",
+	.drv_name = USBIP_HOST_DRV_NAME,
 	.ops = {
 		.open = usbip_host_driver_open,
 		.close = usbip_generic_driver_close,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-03-30  3:11 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-03  8:17 [PATCH] usbip: tools: Add usbip host driver availability check Zongmin Zhou
2026-03-10 22:28 ` Shuah Khan
2026-03-12  2:17   ` Zongmin Zhou
2026-03-23 19:17     ` Shuah Khan
2026-03-25  2:26       ` [PATCH v2] " Zongmin Zhou
2026-03-25  8:58         ` Greg KH
2026-03-26  3:10           ` Zongmin Zhou
2026-03-26  8:43             ` Greg KH
2026-03-26 18:43               ` Shuah Khan
2026-03-27  8:39                 ` Zongmin Zhou
2026-03-27 17:51                   ` Shuah Khan
2026-03-27 18:29                     ` Shuah Khan
2026-03-30  3:10                       ` Zongmin Zhou
2026-03-11 12:13 ` [PATCH] " Greg KH
2026-03-12  2:17   ` Zongmin Zhou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox