From e751c69241e08795615cdca67da1a5beff817a82 Mon Sep 17 00:00:00 2001 From: illiliti Date: Fri, 31 Jul 2020 01:13:41 +0300 Subject: [PATCH] do not try to search parent device very deeply --- udev_device.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/udev_device.c b/udev_device.c index 92188e9..aa6db22 100644 --- a/udev_device.c +++ b/udev_device.c @@ -117,31 +117,35 @@ struct udev *udev_device_get_udev(struct udev_device *udev_device) struct udev_device *udev_device_get_parent(struct udev_device *udev_device) { - char *tmp, *path; + char *path, *syspath; if (!udev_device) { return NULL; } - path = strdup(udev_device_get_syspath(udev_device)); + syspath = path = strdup(udev_device_get_syspath(udev_device)); if (!path) { return NULL; } + if (strncmp(path, "/sys/devices/", 13) == 0) { + path += 13; + } + do { - if ((tmp = strrchr(path, '/'))) { - *tmp = '\0'; + if ((path = strrchr(path, '/'))) { + *path = '\0'; } else { break; } - udev_device->parent = udev_device_new_from_syspath(udev_device->udev, path); + udev_device->parent = udev_device_new_from_syspath(udev_device->udev, syspath); } while (!udev_device->parent); - free(path); + free(syspath); return udev_device->parent; }