From 1393c5a2a42d6ff16afcdc3ac39f007921b9cb57 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 23 Apr 2025 00:13:51 +0900 Subject: [PATCH] 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). --- src/libsystemd/sd-device/sd-device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 75bf545aff..98a10d5b1f 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; }