summaryrefslogtreecommitdiffstats
path: root/usb-db
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2009-02-26 21:56:37 +0100
committerKay Sievers <kay.sievers@vrfy.org>2009-02-26 21:56:37 +0100
commit62cacab6b2e7097786064157b99981811810d432 (patch)
treed0f7bd9dfe5cfa9699f619b5c07332abbeebae05 /usb-db
parent91a4a541106431634b27231493fa1763f517212d (diff)
usb-db: also handle the passed device, not only the parents
Diffstat (limited to 'usb-db')
-rw-r--r--usb-db/usb-db.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/usb-db/usb-db.c b/usb-db/usb-db.c
index b53e4e5..db1f843 100644
--- a/usb-db/usb-db.c
+++ b/usb-db/usb-db.c
@@ -172,7 +172,6 @@ static int lookup_vid_pid(
finish:
free(line);
-
fclose(f);
if (ret < 0) {
@@ -185,6 +184,28 @@ finish:
return ret;
}
+static struct udev_device *find_device(struct udev_device *dev, const char *subsys, const char *devtype)
+{
+ const char *str;
+
+ str = udev_device_get_subsystem(dev);
+ if (str == NULL)
+ goto try_parent;
+ if (strcmp(str, subsys) != 0)
+ goto try_parent;
+
+ if (devtype != NULL) {
+ str = udev_device_get_devtype(dev);
+ if (str == NULL)
+ goto try_parent;
+ if (strcmp(str, devtype) != 0)
+ goto try_parent;
+ }
+ return dev;
+try_parent:
+ return udev_device_get_parent_with_subsystem_devtype(dev, SUBSYSTEM, DEVTYPE);
+}
+
int main(int argc, char*argv[]) {
struct udev *udev = NULL;
@@ -215,8 +236,9 @@ int main(int argc, char*argv[]) {
goto finish;
}
- if (!(parent = udev_device_get_parent_with_subsystem_devtype(dev, SUBSYSTEM, DEVTYPE))) {
- fprintf(stderr, "Failed to find parent device.\n");
+ parent = find_device(dev, SUBSYSTEM, DEVTYPE);
+ if (!parent) {
+ fprintf(stderr, "Failed to find device.\n");
goto finish;
}
@@ -235,15 +257,10 @@ int main(int argc, char*argv[]) {
ret = 0;
finish:
- if (dev)
- udev_device_unref(dev);
-
- if (udev)
- udev_unref(udev);
-
+ udev_device_unref(dev);
+ udev_unref(udev);
free(vendor);
free(product);
return ret;
-
}