udev: improve device discovery with udev for add/remove
authorJohannes Zellner <johannes.zellner@nokia.com>
Tue, 15 May 2012 19:43:08 +0000 (12:43 -0700)
committerQt by Nokia <qt-info@nokia.com>
Tue, 15 May 2012 21:03:23 +0000 (23:03 +0200)
As the udev device tree structure varies between distros and udev
versions, first probe the actual leaf node for device properties.
If leaf does not contain needed properties, walk up the tree to the
next node matching the queried submodule.

Change-Id: I09329d5a76a1a2a797513f4a787cb27fed5293c7
Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
src/platformsupport/udev/qudevicehelper.cpp

index 688cedd..0cf370b 100644 (file)
@@ -192,13 +192,18 @@ void QUDeviceHelper::handleUDevNotification()
         subsystem = "drm";
     else goto cleanup;
 
-    // does not increase the refcount
-    dev = udev_device_get_parent_with_subsystem_devtype(dev, subsystem, 0);
-    if (!dev)
-        goto cleanup;
-
     types = checkDeviceType(dev);
 
+    // if we cannot determine a type, walk up the device tree
+    if (types == UDev_Unknown) {
+        // does not increase the refcount
+        dev = udev_device_get_parent_with_subsystem_devtype(dev, subsystem, 0);
+        if (!dev)
+            goto cleanup;
+
+        types = checkDeviceType(dev);
+    }
+
     if (types && (qstrcmp(action, "add") == 0))
         emit deviceDetected(devNode, types);