chiark / gitweb /
libudev: device - remove udev_device_get_parent_with_subsystem
[elogind.git] / udev / lib / libudev-device.c
index 06227be328c0851a121c7b08463903aba18158d0..0cb59212815459924f7319187ff7e5b0d81e9f21 100644 (file)
@@ -541,33 +541,26 @@ struct udev_device *udev_device_get_parent(struct udev_device *udev_device)
        return udev_device->parent_device;
 }
 
-struct udev_device *udev_device_get_parent_with_subsystem(struct udev_device *udev_device, const char *subsystem)
+struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, const char *subsystem, const char *devtype)
 {
        struct udev_device *parent;
 
-       parent = udev_device_get_parent(udev_device);
-       while (parent != NULL) {
-               const char *parent_subsystem;
-
-               parent_subsystem = udev_device_get_subsystem(parent);
-               if (parent_subsystem != NULL && strcmp(parent_subsystem, subsystem) == 0)
-                       break;
-               parent = udev_device_get_parent(parent);
-       }
-       return parent;
-}
-
-struct udev_device *udev_device_get_parent_with_devtype(struct udev_device *udev_device, const char *devtype)
-{
-       struct udev_device *parent;
+       if (subsystem == NULL)
+               return NULL;
 
        parent = udev_device_get_parent(udev_device);
        while (parent != NULL) {
+               const char *parent_subsystem;
                const char *parent_devtype;
 
-               parent_devtype = udev_device_get_devtype(parent);
-               if (parent_devtype != NULL && strcmp(parent_devtype, devtype) == 0)
-                       break;
+               parent_subsystem = udev_device_get_subsystem(parent);
+               if (parent_subsystem != NULL && strcmp(parent_subsystem, subsystem) == 0) {
+                       if (devtype == NULL)
+                               break;
+                       parent_devtype = udev_device_get_devtype(parent);
+                       if (parent_devtype != NULL && strcmp(parent_devtype, devtype) == 0)
+                               break;
+               }
                parent = udev_device_get_parent(parent);
        }
        return parent;
@@ -758,7 +751,8 @@ const char *udev_device_get_devtype(struct udev_device *udev_device)
                return NULL;
        if (!udev_device->devtype_set) {
                udev_device->devtype_set = 1;
-               udev_device_read_uevent_file(udev_device);
+               if (!udev_device->info_loaded)
+                       udev_device_read_uevent_file(udev_device);
        }
        return udev_device->devtype;
 }