X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=namedev.c;h=c1c22a6cfbdda12b3b522386cfe50adc898d10ba;hp=146dad604b2f639096d98abb14d9e6a787f5f8b7;hb=8f2f6e426fc4cc1fa39b864a1792428a4269b751;hpb=5ef42682053f57fc031d420f0a2ae3e204421b8d diff --git a/namedev.c b/namedev.c index 146dad604..c1c22a6cf 100644 --- a/namedev.c +++ b/namedev.c @@ -299,6 +299,8 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize, } break; case 'P': + if (!class_dev) + break; class_dev_parent = sysfs_get_classdev_parent(class_dev); if (class_dev_parent != NULL) { struct udevice udev_parent; @@ -306,8 +308,7 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize, dbg("found parent '%s', get the node name", class_dev_parent->path); memset(&udev_parent, 0x00, sizeof(struct udevice)); /* lookup the name in the udev_db with the DEVPATH of the parent */ - strfieldcpy(udev_parent.devpath, &class_dev_parent->path[strlen(sysfs_path)]); - if (udev_db_get_device(&udev_parent) == 0) { + if (udev_db_get_device_by_devpath(&udev_parent, &class_dev_parent->path[strlen(sysfs_path)]) == 0) { strfieldcatmax(string, udev_parent.name, maxsize); dbg("substitute parent node name'%s'", udev_parent.name); } else @@ -553,32 +554,27 @@ static int match_id(struct config_device *dev, struct sysfs_class_device *class_ static int match_place(struct config_device *dev, struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device) { char path[SYSFS_PATH_MAX]; - int found; - char *temp = NULL; + char *temp; /* we have to have a sysfs device for PLACE to work */ if (!sysfs_device) return -ENODEV; - found = 0; strfieldcpy(path, sysfs_device->path); temp = strrchr(path, '/'); dbg("search '%s' in '%s', path='%s'", dev->place, temp, path); - if (strstr(temp, dev->place) != NULL) { - found = 1; - } else { - *temp = 0x00; - temp = strrchr(path, '/'); - dbg("search '%s' in '%s', path='%s'", dev->place, temp, path); - if (strstr(temp, dev->place) != NULL) - found = 1; - } - if (!found) { - dbg("place doesn't match"); - return -ENODEV; - } + if (strstr(temp, dev->place) != NULL) + return 0; - return 0; + /* try the parent */ + temp[0] = '\0'; + temp = strrchr(path, '/'); + dbg("search '%s' in '%s', path='%s'", dev->place, temp, path); + if (strstr(temp, dev->place) == NULL) + return 0; + + dbg("place doesn't match"); + return -ENODEV; } static int match_rule(struct udevice *udev, struct config_device *dev,