sd-device: fix validation for devices under /sys/firmware/ in sd_device_new_from_subsystem_sysname() (#35863)

Devices under /sys/firmware/ do not have subsystems. Hence, the
validation in sd_device_new_from_subsystem_sysname() ->
device_new_from_path_join() always failed.

Fixes a bug introduced by cd7c71154c
(v257).
Fixes #35861.
This commit is contained in:
Luca Boccassi
2025-01-06 11:06:23 +00:00
committed by GitHub

View File

@@ -234,7 +234,7 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
r = path_simplify_alloc(_syspath, &syspath);
if (r < 0)
return r;
return log_oom_debug();
}
assert_se(devpath = startswith(syspath, "/sys"));
@@ -401,7 +401,6 @@ static int device_new_from_path_join(
int r;
assert(device);
assert(subsystem);
assert(sysname);
p = path_join(a, b, c, d);
@@ -486,13 +485,13 @@ _public_ int sd_device_new_from_subsystem_sysname(
if (streq(subsystem, "subsystem")) {
FOREACH_STRING(s, "/sys/bus/", "/sys/class/") {
r = device_new_from_path_join(&device, subsystem, NULL, sysname, s, name, NULL, NULL);
r = device_new_from_path_join(&device, subsystem, /* driver_subsystem = */ NULL, sysname, s, name, NULL, NULL);
if (r < 0)
return r;
}
} else if (streq(subsystem, "module")) {
r = device_new_from_path_join(&device, subsystem, NULL, sysname, "/sys/module/", name, NULL, NULL);
r = device_new_from_path_join(&device, subsystem, /* driver_subsystem = */ NULL, sysname, "/sys/module/", name, NULL, NULL);
if (r < 0)
return r;
@@ -514,15 +513,17 @@ _public_ int sd_device_new_from_subsystem_sysname(
}
}
r = device_new_from_path_join(&device, subsystem, NULL, sysname, "/sys/bus/", subsystem, "/devices/", name);
r = device_new_from_path_join(&device, subsystem, /* driver_subsystem = */ NULL, sysname, "/sys/bus/", subsystem, "/devices/", name);
if (r < 0)
return r;
r = device_new_from_path_join(&device, subsystem, NULL, sysname, "/sys/class/", subsystem, name, NULL);
r = device_new_from_path_join(&device, subsystem, /* driver_subsystem = */ NULL, sysname, "/sys/class/", subsystem, name, NULL);
if (r < 0)
return r;
r = device_new_from_path_join(&device, subsystem, NULL, sysname, "/sys/firmware/", subsystem, name, NULL);
/* Note that devices under /sys/firmware/ (e.g. /sys/firmware/devicetree/base/) do not have
* subsystem. Hence, pass NULL for subsystem. See issue #35861. */
r = device_new_from_path_join(&device, /* subsystem = */ NULL, /* driver_subsystem = */ NULL, sysname, "/sys/firmware/", subsystem, name, NULL);
if (r < 0)
return r;