[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250706142720.8596-1-daniele.barcella@pm.me>
Date: Sun, 06 Jul 2025 14:27:26 +0000
From: Daniele Barcella <daniele.barcella@...me>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Daniele Barcella <daniele.barcella@...me>, linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] usb: modalias: Added a manufacturer string to usb modalias sysfs output
The patch improves the usb modalias sysfs output by including the manufacturer string ath the end in the format 'mnf%s' after filtering the string, like how it is done for the dmi id device.
For example usb:v0483p5740d0100dcEFdsc02dp01ic02isc02ip00in00mnfFlipperDevicesInc.
This change allows hwdb rules to target devices with the same vid+pid but different manufacturer.
For example, the STMicroelectronics Virtual COM Port (0483:5740) is widely used in both prototyping and production devices that don't have a unique vendor ID.
For further context, refer to the related discussion on systemd's GitHub: https://github.com/systemd/systemd/pull/24869.
Signed-off-by: Daniele Barcella <daniele.barcella@...me>
---
drivers/usb/core/sysfs.c | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 23f3cb1989f4..dc191fa94372 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -1154,20 +1154,39 @@ static ssize_t interface_show(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_RO(interface);
+static void ascii_filter(char *d, const char *s)
+{
+ /* Filter out characters we don't want to see in the modalias string */
+ for (; *s; s++)
+ if (*s > ' ' && *s < 127 && *s != ':')
+ *(d++) = *s;
+
+ *d = 0;
+}
+
static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct usb_interface *intf;
struct usb_device *udev;
struct usb_host_interface *alt;
+ char *manufacturer;
+ int emit;
intf = to_usb_interface(dev);
udev = interface_to_usbdev(intf);
alt = READ_ONCE(intf->cur_altsetting);
- return sysfs_emit(buf,
+ if (udev->manufacturer) {
+ manufacturer = kmalloc(strlen(udev->manufacturer) + 1, GFP_KERNEL);
+ ascii_filter(manufacturer, udev->manufacturer);
+ } else {
+ manufacturer = kstrdup("", GFP_KERNEL);
+ }
+
+ emit = sysfs_emit(buf,
"usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02X"
- "ic%02Xisc%02Xip%02Xin%02X\n",
+ "ic%02Xisc%02Xip%02Xin%02Xmnf%s\n",
le16_to_cpu(udev->descriptor.idVendor),
le16_to_cpu(udev->descriptor.idProduct),
le16_to_cpu(udev->descriptor.bcdDevice),
@@ -1177,7 +1196,11 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
alt->desc.bInterfaceClass,
alt->desc.bInterfaceSubClass,
alt->desc.bInterfaceProtocol,
- alt->desc.bInterfaceNumber);
+ alt->desc.bInterfaceNumber,
+ manufacturer
+ );
+ kfree(manufacturer);
+ return emit;
}
static DEVICE_ATTR_RO(modalias);
--
2.47.2
Powered by blists - more mailing lists