-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, subsys, devtype);
-}
-
-
-static int builtin_db(struct udev_device *dev, bool test,
- const char *database,
- const char *vendor_attr, const char *product_attr,
- const char *subsys, const char *devtype)
-{
- struct udev_device *parent;
- uint16_t vid = 0, pid = 0;
- char *vendor = NULL, *product = NULL;
-
- parent = find_device(dev, subsys, devtype);
- if (!parent) {
- fprintf(stderr, "Failed to find device.\n");
- goto finish;
- }
-
- if (get_vid_pid(parent, vendor_attr, product_attr, &vid, &pid) < 0)
- goto finish;
-
- if (lookup_vid_pid(database, vid, pid, &vendor, &product) < 0)
- goto finish;
-
- if (vendor)
- udev_builtin_add_property(dev, test, "ID_VENDOR_FROM_DATABASE", vendor);
- if (product)
- udev_builtin_add_property(dev, test, "ID_MODEL_FROM_DATABASE", product);
-
-finish:
- free(vendor);
- free(product);