Skip to content

Commit

Permalink
sd-device: fix validation for devices under /sys/firmware/ in sd_devi…
Browse files Browse the repository at this point in the history
…ce_new_from_subsystem_sysname()

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 cd7c711 (v257).
Fixes #35861.

(cherry picked from commit 3328d1e1816f408e6516c35991a89a8d21fd60b4)

Resolves: RHEL-72798
  • Loading branch information
yuwata authored and lnykryn committed Jan 6, 2025
1 parent 5d21d8f commit 1a9f20b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/libsystemd/sd-device/sd-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down

0 comments on commit 1a9f20b

Please sign in to comment.