From: Łukasz Bartosik Date: Tue, 20 Jan 2026 18:11:48 +0000 (+0200) Subject: xhci: dbc: allow setting manufacturer string through sysfs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db7fd1955e6825756d0241343add1d172098bb18;p=thirdparty%2Flinux.git xhci: dbc: allow setting manufacturer string through sysfs Add dbc_manufacturer sysfs attribute to allow changing the manufacturer description presented by the debug device when a host requests a string descriptor with iManufacturer index. Value can only be changed while debug capability (DbC) is in disabled state to prevent USB device descriptor change while connected to a USB host. The default value is "Linux Foundation". The string length can be from 1 to 126 characters. String is terminated at null or newline, driver does not support empty string. [ mn: Improve commit message and sysfs entry documentation ] Signed-off-by: Łukasz Bartosik Signed-off-by: Mathias Nyman Link: https://patch.msgid.link/20260120181148.128712-5-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- diff --git a/Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd b/Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd index d153162d6045..d10e6de3adb2 100644 --- a/Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd +++ b/Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd @@ -114,3 +114,16 @@ Description: connected to a USB host. The default value is "Linux USB Debug Target". The field length can be from 1 to 126 characters. + +What: /sys/bus/pci/drivers/xhci_hcd/.../dbc_manufacturer +Date: January 2026 +Contact: Łukasz Bartosik +Description: + The dbc_manufacturer attribute allows to change the manufacturer + string descriptor presented by the debug device when a host + requests a string descriptor with iManufacturer index. + Value can only be changed while debug capability (DbC) is in + disabled state to prevent USB device descriptor change while + connected to a USB host. + The default value is "Linux Foundation". + The field length can be from 1 to 126 characters. diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c index cae98576545e..9fd497e0dc7f 100644 --- a/drivers/usb/host/xhci-dbgcap.c +++ b/drivers/usb/host/xhci-dbgcap.c @@ -1210,6 +1210,40 @@ static ssize_t dbc_bcdDevice_store(struct device *dev, return size; } +static ssize_t dbc_manufacturer_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct xhci_hcd *xhci = hcd_to_xhci(dev_get_drvdata(dev)); + struct xhci_dbc *dbc = xhci->dbc; + + return sysfs_emit(buf, "%s\n", dbc->str.manufacturer); +} + +static ssize_t dbc_manufacturer_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + struct xhci_hcd *xhci = hcd_to_xhci(dev_get_drvdata(dev)); + struct xhci_dbc *dbc = xhci->dbc; + size_t len; + + if (dbc->state != DS_DISABLED) + return -EBUSY; + + len = strcspn(buf, "\n"); + if (!len) + return -EINVAL; + + if (len > USB_MAX_STRING_LEN) + return -E2BIG; + + memcpy(dbc->str.manufacturer, buf, len); + dbc->str.manufacturer[len] = '\0'; + + return size; +} + static ssize_t dbc_product_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -1367,6 +1401,7 @@ static DEVICE_ATTR_RW(dbc_idProduct); static DEVICE_ATTR_RW(dbc_bcdDevice); static DEVICE_ATTR_RW(dbc_serial); static DEVICE_ATTR_RW(dbc_product); +static DEVICE_ATTR_RW(dbc_manufacturer); static DEVICE_ATTR_RW(dbc_bInterfaceProtocol); static DEVICE_ATTR_RW(dbc_poll_interval_ms); @@ -1377,6 +1412,7 @@ static struct attribute *dbc_dev_attrs[] = { &dev_attr_dbc_bcdDevice.attr, &dev_attr_dbc_serial.attr, &dev_attr_dbc_product.attr, + &dev_attr_dbc_manufacturer.attr, &dev_attr_dbc_bInterfaceProtocol.attr, &dev_attr_dbc_poll_interval_ms.attr, NULL