summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Bartosik <ukaszb@chromium.org>2026-01-20 21:11:47 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-01-23 19:16:24 +0300
commit33d15312e35d4cfd26b68ab4c1b0143cc43d8b16 (patch)
tree00b0c4fcd8288252b3f697a07c76b522dcce5fa7
parent412de639b55fcf1ab5ad50a6be84f5164104abe3 (diff)
downloadlinux-33d15312e35d4cfd26b68ab4c1b0143cc43d8b16.tar.xz
xhci: dbc: allow setting product string through sysfs
Add dbc_product sysfs attribute to allow changing the product description presented by the debug device when a host requests a string descriptor with iProduct 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 USB Debug Target". The field 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 <ukaszb@chromium.org> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Link: https://patch.msgid.link/20260120181148.128712-4-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd14
-rw-r--r--drivers/usb/host/xhci-dbgcap.c36
2 files changed, 50 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd b/Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd
index b0e8ded09c16..d153162d6045 100644
--- a/Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd
+++ b/Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd
@@ -100,3 +100,17 @@ Description:
connected to a USB host.
The default value is "0001".
The field length can be from 1 to 126 characters.
+
+What: /sys/bus/pci/drivers/xhci_hcd/.../dbc_product
+Date: January 2026
+Contact: Łukasz Bartosik <ukaszb@chromium.org>
+Description:
+ The dbc_product attribute allows to change the product string
+ descriptor presented by the debug device when a host requests
+ a string descriptor with iProduct index.
+ Index is found in the iProduct field in the device descriptor.
+ 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 USB Debug Target".
+ 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 a78d386ffdc3..cae98576545e 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_product_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.product);
+}
+
+static ssize_t dbc_product_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.product, buf, len);
+ dbc->str.product[len] = '\0';
+
+ return size;
+}
+
static ssize_t dbc_serial_show(struct device *dev,
struct device_attribute *attr,
char *buf)
@@ -1332,6 +1366,7 @@ static DEVICE_ATTR_RW(dbc_idVendor);
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_bInterfaceProtocol);
static DEVICE_ATTR_RW(dbc_poll_interval_ms);
@@ -1341,6 +1376,7 @@ static struct attribute *dbc_dev_attrs[] = {
&dev_attr_dbc_idProduct.attr,
&dev_attr_dbc_bcdDevice.attr,
&dev_attr_dbc_serial.attr,
+ &dev_attr_dbc_product.attr,
&dev_attr_dbc_bInterfaceProtocol.attr,
&dev_attr_dbc_poll_interval_ms.attr,
NULL