X Tutup
Skip to content

Commit 1365952

Browse files
committed
sd-device: use path_find_last_component() to set driver subsystem
1 parent 3066293 commit 1365952

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/libsystemd/sd-device/sd-device.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -810,32 +810,26 @@ int device_set_subsystem(sd_device *device, const char *subsystem) {
810810

811811
int device_set_drivers_subsystem(sd_device *device) {
812812
_cleanup_free_ char *subsystem = NULL;
813-
const char *syspath, *drivers, *p;
813+
const char *devpath, *drivers, *p;
814814
int r;
815815

816816
assert(device);
817817

818-
r = sd_device_get_syspath(device, &syspath);
818+
r = sd_device_get_devpath(device, &devpath);
819819
if (r < 0)
820820
return r;
821821

822-
drivers = strstr(syspath, "/drivers/");
822+
drivers = strstr(devpath, "/drivers/");
823823
if (!drivers)
824824
return -EINVAL;
825825

826-
for (p = drivers - 1; p >= syspath; p--)
827-
if (*p == '/')
828-
break;
829-
830-
if (p <= syspath)
831-
/* syspath does not start with /sys/ ?? */
832-
return -EINVAL;
833-
p++;
834-
if (p >= drivers)
835-
/* refuse duplicated slashes */
826+
r = path_find_last_component(devpath, false, &drivers, &p);
827+
if (r < 0)
828+
return r;
829+
if (r == 0)
836830
return -EINVAL;
837831

838-
subsystem = strndup(p, drivers - p);
832+
subsystem = strndup(p, r);
839833
if (!subsystem)
840834
return -ENOMEM;
841835

0 commit comments

Comments
 (0)
X Tutup