[PATCH 2/2] config: construct the USB ID from ID_MODEL_ID and ID_VENDOR_ID_ID

Peter Hutterer peter.hutterer at who-t.net
Wed Jul 27 17:17:13 PDT 2011


The scanf relies on the kernel never changing the format. Use the actual
variables instead (if they exist).

Reported-by: Lennart Poettering <lennart at poettering.net>
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 config/udev.c |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/config/udev.c b/config/udev.c
index 22e3567..cc69e02 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -67,6 +67,7 @@ device_added(struct udev_device *udev_device)
     struct udev_device *parent;
     int rc;
     const char *dev_seat;
+    const char *vendor, *model;
 
     path = udev_device_get_devnode(udev_device);
 
@@ -105,12 +106,19 @@ device_added(struct udev_device *udev_device)
     name = udev_device_get_property_value(udev_device, "ID_MODEL");
     LOG_SYSATTR(path, "ID_MODEL", name);
 
+    vendor = udev_device_get_property_value(udev_device, "ID_VENDOR_ID");
+    LOG_PROPERTY(path, "ID_VENDOR_ID", vendor);
+    model = udev_device_get_property_value(udev_device, "ID_MODEL_ID");
+    LOG_PROPERTY(path, "ID_MODEL_ID", model);
+    if (vendor && model) {
+        if (asprintf(&attrs.usb_id, "%s:%s", vendor, model) == -1)
+            attrs.usb_id = NULL;
+    }
+
     parent = udev_device_get_parent(udev_device);
     if (parent) {
         const char *ppath = udev_device_get_devnode(parent);
-        const char *product = udev_device_get_property_value(parent, "PRODUCT");
         const char *pnp_id = udev_device_get_sysattr_value(parent, "id");
-        unsigned int usb_vendor, usb_model;
 
         if (!name) {
             name = udev_device_get_sysattr_value(parent, "name");
@@ -126,12 +134,16 @@ device_added(struct udev_device *udev_device)
         LOG_SYSATTR(ppath, "id", pnp_id);
 
         /* construct USB ID in lowercase hex - "0000:ffff" */
-        if (product && sscanf(product, "%*x/%4x/%4x/%*x", &usb_vendor, &usb_model) == 2) {
-            if (asprintf(&attrs.usb_id, "%04x:%04x", usb_vendor, usb_model)
-                == -1)
-                attrs.usb_id = NULL;
-            else
-                LOG_PROPERTY(ppath, "PRODUCT", product);
+        if (!attrs.usb_id) {
+            unsigned int usb_vendor, usb_model;
+            const char *product = udev_device_get_property_value(parent, "PRODUCT");
+            if (product && sscanf(product, "%*x/%4x/%4x/%*x", &usb_vendor, &usb_model) == 2) {
+                if (asprintf(&attrs.usb_id, "%04x:%04x", usb_vendor, usb_model)
+                        == -1)
+                    attrs.usb_id = NULL;
+                else
+                    LOG_PROPERTY(ppath, "PRODUCT", product);
+            }
         }
     }
     if (!name)
-- 
1.7.6



More information about the xorg-devel mailing list