From: Yu Watanabe Date: Tue, 22 Apr 2025 15:13:51 +0000 (+0900) Subject: sd-device: fix sysname check in sd_device_new_from_subsystem_sysname() X-Git-Tag: v258-rc1~760 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1393c5a2a42d6ff16afcdc3ac39f007921b9cb57;p=thirdparty%2Fsystemd.git sd-device: fix sysname check in sd_device_new_from_subsystem_sysname() For example, consider the following device: - syspath: /sys/bus/mdio_bus/drivers/Qualcomm Atheros AR8031!AR8033 - subsystem: "drivers" - driver subsystem: "mdio_bus" - sysname: "Qualcomm Atheros AR8031/AR8033" <-- '!' is replaced with '/' When sd_device_new_from_subsystem_sysname() is called to get the device, the arguments to sd_device_new_from_subsystem_sysname() should be - subsystem: "drivers" - sysname (concatenated with driver subsystem): "mdio_bus:Qualcomm Atheros AR8031/AR8033" In that case, we need to pass to device_new_from_path_join() the following: - subsystem: "drivers" - driver subsystem: "mdio_bus" - sysname: "Qualcomm Atheros AR8031/AR8033" - a: "/sys/bus" - b: "drivers" - c: "mdio_bus" - d: "Qualcomm Atheros AR8031!AR8033" Here, the important point is that the `sysname` argument and the last argument `d` are differnt: the `sysname` argument needs to match the sysname obtained by `sd_device_get_sysname()`, but `d` must be the last path component of the syspath. Previously, we passed a wrong sysname to device_new_from_path_join(). This fixes the issue. Fixes a bug in cd7c71154cd62d3f50c07ce387edd9c20aebd7bc (v257). --- diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 75bf545aff2..98a10d5b1f9 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -507,7 +507,7 @@ _public_ int sd_device_new_from_subsystem_sysname( if (streq(sep, "drivers")) /* If the sysname is "drivers", then it's the drivers directory itself that is meant. */ r = device_new_from_path_join(&device, subsystem, subsys, "drivers", "/sys/bus/", subsys, "/drivers", NULL); else - r = device_new_from_path_join(&device, subsystem, subsys, sep, "/sys/bus/", subsys, "/drivers/", sep); + r = device_new_from_path_join(&device, subsystem, subsys, sysname + (sep - name), "/sys/bus/", subsys, "/drivers/", sep); if (r < 0) return r; }