[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
Tue Jul 19 23:19:13 PDT 2011


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

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 5cc071c..e21dc47 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -65,6 +65,7 @@ device_added(struct udev_device *udev_device)
     struct udev_list_entry *set, *entry;
     struct udev_device *parent;
     int rc;
+    const char *vendor, *model;
 
     path = udev_device_get_devnode(udev_device);
 
@@ -93,12 +94,19 @@ device_added(struct udev_device *udev_device)
     name = udev_device_get_property_value(parent, "ID_MODEL");
     LOG_SYSATTR(path, "ID_MODEL", name);
 
+    vendor = udev_device_get_property_value(parent, "ID_VENDOR_ID");
+    LOG_PROPERTY(path, "ID_VENDOR_ID", vendor);
+    model = udev_device_get_property_value(parent, "ID_MODEL_ID");
+    LOG_PROPERTY(path, "ID_MODEL_ID", model);
+    if (vendor && model) {
+        if (asprintf("%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");
@@ -114,12 +122,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(path, "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(path, "PRODUCT", product);
+            }
         }
     }
     if (!name)
-- 
1.7.6


--mYCpIKhGyMATD0i+--


More information about the xorg-devel mailing list