Linux USB
 help / color / mirror / Atom feed
From: "Łukasz Bartosik" <ukaszb@chromium.org>
To: Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, "Łukasz Bartosik" <ukaszb@chromium.org>
Subject: [PATCH v1 2/4] xhci: dbc: allow to set serial number through sysfs
Date: Mon, 29 Sep 2025 09:02:04 +0000	[thread overview]
Message-ID: <20250929090206.423937-3-ukaszb@google.com> (raw)
In-Reply-To: <20250929090206.423937-1-ukaszb@google.com>

From: Łukasz Bartosik <ukaszb@chromium.org>

Add code which allows to set serial number of a DbC
device through sysfs.

Signed-off-by: Łukasz Bartosik <ukaszb@chromium.org>
---
 drivers/usb/host/xhci-dbgcap.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index c2fecaffd6f3..5cc201afe8f4 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -1200,6 +1200,36 @@ static ssize_t dbc_bcdDevice_store(struct device *dev,
 	return size;
 }
 
+static ssize_t dbc_iSerial_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.serial);
+}
+
+static ssize_t dbc_iSerial_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;
+
+	if (dbc->state != DS_DISABLED)
+		return -EBUSY;
+
+	if (size > USB_MAX_STRING_LEN/2+1)
+		return -E2BIG;
+
+	memcpy(dbc->str.serial, buf, size);
+	/* remove newline and terminate the string */
+	dbc->str.serial[size-1] = '\0';
+
+	return size;
+}
+
 static ssize_t dbc_bInterfaceProtocol_show(struct device *dev,
 				 struct device_attribute *attr,
 				 char *buf)
@@ -1287,6 +1317,7 @@ static DEVICE_ATTR_RW(dbc);
 static DEVICE_ATTR_RW(dbc_idVendor);
 static DEVICE_ATTR_RW(dbc_idProduct);
 static DEVICE_ATTR_RW(dbc_bcdDevice);
+static DEVICE_ATTR_RW(dbc_iSerial);
 static DEVICE_ATTR_RW(dbc_bInterfaceProtocol);
 static DEVICE_ATTR_RW(dbc_poll_interval_ms);
 
@@ -1295,6 +1326,7 @@ static struct attribute *dbc_dev_attrs[] = {
 	&dev_attr_dbc_idVendor.attr,
 	&dev_attr_dbc_idProduct.attr,
 	&dev_attr_dbc_bcdDevice.attr,
+	&dev_attr_dbc_iSerial.attr,
 	&dev_attr_dbc_bInterfaceProtocol.attr,
 	&dev_attr_dbc_poll_interval_ms.attr,
 	NULL
-- 
2.51.0.536.g15c5d4f767-goog


  parent reply	other threads:[~2025-09-29  9:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-29  9:02 [PATCH v1 0/4] Enable to set DbC strings through sysfs Łukasz Bartosik
2025-09-29  9:02 ` [PATCH v1 1/4] xhci: dbc: prepare to expose " Łukasz Bartosik
2025-09-29  9:02 ` Łukasz Bartosik [this message]
2025-09-29 12:59   ` [PATCH v1 2/4] xhci: dbc: allow to set serial number " Greg Kroah-Hartman
2025-09-29 13:00   ` Greg Kroah-Hartman
2025-10-01  8:28     ` Łukasz Bartosik
2025-09-29  9:02 ` [PATCH v1 3/4] xhci: dbc: allow to set product name " Łukasz Bartosik
2025-09-29  9:02 ` [PATCH v1 4/4] xhci: dbc: allow to set manufacturer " Łukasz Bartosik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250929090206.423937-3-ukaszb@google.com \
    --to=ukaszb@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox