[PATCH 1/2] usbip: Convert usbip_debug to driver attribute.

From: Jakub Lecki

Date: Thu Jun 11 2026 - 18:13:01 EST


Changing configuration of the debug flag affects all of devices debug
prints. Move the attribute to a driver level to prevent duplication.

The attribute for given drivers is located under:
* /sys/bus/platform/drivers/vhci_hcd/usbip_debug
* /sys/bus/usb/drivers/usbip-host/usbip_debug

Signed-off-by: Jakub Lecki <lec.jakub@xxxxxxxxx>
---
drivers/usb/usbip/stub_dev.c | 10 +++++++++-
drivers/usb/usbip/usbip_common.c | 14 ++++++--------
drivers/usb/usbip/usbip_common.h | 2 +-
drivers/usb/usbip/vhci_hcd.c | 7 +++++++
drivers/usb/usbip/vhci_sysfs.c | 3 +--
5 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
index abfa11d6bde7..653d582de181 100644
--- a/drivers/usb/usbip/stub_dev.c
+++ b/drivers/usb/usbip/stub_dev.c
@@ -145,11 +145,16 @@ static DEVICE_ATTR_WO(usbip_sockfd);
static struct attribute *usbip_attrs[] = {
&dev_attr_usbip_status.attr,
&dev_attr_usbip_sockfd.attr,
- &dev_attr_usbip_debug.attr,
NULL,
};
ATTRIBUTE_GROUPS(usbip);

+static struct attribute *usbip_drv_attrs[] = {
+ &driver_attr_usbip_debug.attr,
+ NULL,
+};
+ATTRIBUTE_GROUPS(usbip_drv);
+
static void stub_shutdown_connection(struct usbip_device *ud)
{
struct stub_device *sdev = container_of(ud, struct stub_device, ud);
@@ -531,4 +536,7 @@ struct usb_device_driver stub_driver = {
#endif
.supports_autosuspend = 0,
.dev_groups = usbip_groups,
+ .driver = {
+ .groups = usbip_drv_groups,
+ }
};
diff --git a/drivers/usb/usbip/usbip_common.c b/drivers/usb/usbip/usbip_common.c
index a5837c0feb05..6920c12f2863 100644
--- a/drivers/usb/usbip/usbip_common.c
+++ b/drivers/usb/usbip/usbip_common.c
@@ -30,24 +30,22 @@ module_param(usbip_debug_flag, ulong, S_IRUGO|S_IWUSR);
MODULE_PARM_DESC(usbip_debug_flag, "debug flags (defined in usbip_common.h)");

/* FIXME */
-struct device_attribute dev_attr_usbip_debug;
-EXPORT_SYMBOL_GPL(dev_attr_usbip_debug);
+struct driver_attribute driver_attr_usbip_debug;
+EXPORT_SYMBOL_GPL(driver_attr_usbip_debug);

-static ssize_t usbip_debug_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+static ssize_t usbip_debug_show(struct device_driver *driver, char *buf)
{
return sprintf(buf, "%lx\n", usbip_debug_flag);
}

-static ssize_t usbip_debug_store(struct device *dev,
- struct device_attribute *attr, const char *buf,
- size_t count)
+static ssize_t usbip_debug_store(struct device_driver *driver,
+ const char *buf, size_t count)
{
if (sscanf(buf, "%lx", &usbip_debug_flag) != 1)
return -EINVAL;
return count;
}
-DEVICE_ATTR_RW(usbip_debug);
+DRIVER_ATTR_RW(usbip_debug);

static void usbip_dump_buffer(char *buff, int bufflen)
{
diff --git a/drivers/usb/usbip/usbip_common.h b/drivers/usb/usbip/usbip_common.h
index 282efca64a01..ee4114e44935 100644
--- a/drivers/usb/usbip/usbip_common.h
+++ b/drivers/usb/usbip/usbip_common.h
@@ -57,7 +57,7 @@ enum {
#define usbip_dbg_flag_vhci_sysfs (usbip_debug_flag & usbip_debug_vhci_sysfs)

extern unsigned long usbip_debug_flag;
-extern struct device_attribute dev_attr_usbip_debug;
+extern struct driver_attribute driver_attr_usbip_debug;

#define usbip_dbg_with_flag(flag, fmt, args...) \
do { \
diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
index 39e8faf4c18c..bff752ac3183 100644
--- a/drivers/usb/usbip/vhci_hcd.c
+++ b/drivers/usb/usbip/vhci_hcd.c
@@ -1506,6 +1506,12 @@ static int vhci_hcd_resume(struct platform_device *pdev)

#endif

+static struct attribute *vhci_attrs[] = {
+ &driver_attr_usbip_debug.attr,
+ NULL
+};
+ATTRIBUTE_GROUPS(vhci);
+
static struct platform_driver vhci_driver = {
.probe = vhci_hcd_probe,
.remove = vhci_hcd_remove,
@@ -1513,6 +1519,7 @@ static struct platform_driver vhci_driver = {
.resume = vhci_hcd_resume,
.driver = {
.name = driver_name,
+ .groups = vhci_groups,
},
};

diff --git a/drivers/usb/usbip/vhci_sysfs.c b/drivers/usb/usbip/vhci_sysfs.c
index 5bc8c47788d4..2742ab12f309 100644
--- a/drivers/usb/usbip/vhci_sysfs.c
+++ b/drivers/usb/usbip/vhci_sysfs.c
@@ -512,9 +512,8 @@ int vhci_init_attr_group(void)
*attrs = &dev_attr_nports.attr;
*(attrs + 1) = &dev_attr_detach.attr;
*(attrs + 2) = &dev_attr_attach.attr;
- *(attrs + 3) = &dev_attr_usbip_debug.attr;
for (i = 0; i < vhci_num_controllers; i++)
- *(attrs + i + 4) = &((status_attrs + i)->attr.attr);
+ *(attrs + i + 3) = &((status_attrs + i)->attr.attr);
vhci_attr_group.attrs = attrs;
return 0;
}

--
2.53.0