From: Yu Watanabe Date: Wed, 23 Mar 2022 05:45:49 +0000 (+0900) Subject: sd-device: use path_find_last_component() to set driver subsystem X-Git-Tag: v251-rc1~54^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=13659527efd4cf00677ccacba5994bb77dc866b0;p=thirdparty%2Fsystemd.git sd-device: use path_find_last_component() to set driver subsystem --- diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index a58877e11ee..f22088db57d 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -810,32 +810,26 @@ int device_set_subsystem(sd_device *device, const char *subsystem) { int device_set_drivers_subsystem(sd_device *device) { _cleanup_free_ char *subsystem = NULL; - const char *syspath, *drivers, *p; + const char *devpath, *drivers, *p; int r; assert(device); - r = sd_device_get_syspath(device, &syspath); + r = sd_device_get_devpath(device, &devpath); if (r < 0) return r; - drivers = strstr(syspath, "/drivers/"); + drivers = strstr(devpath, "/drivers/"); if (!drivers) return -EINVAL; - for (p = drivers - 1; p >= syspath; p--) - if (*p == '/') - break; - - if (p <= syspath) - /* syspath does not start with /sys/ ?? */ - return -EINVAL; - p++; - if (p >= drivers) - /* refuse duplicated slashes */ + r = path_find_last_component(devpath, false, &drivers, &p); + if (r < 0) + return r; + if (r == 0) return -EINVAL; - subsystem = strndup(p, drivers - p); + subsystem = strndup(p, r); if (!subsystem) return -ENOMEM;