]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: fix sysname check in sd_device_new_from_subsystem_sysname()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 22 Apr 2025 15:13:51 +0000 (00:13 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 14 May 2025 20:33:39 +0000 (21:33 +0100)
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).

(cherry picked from commit 1393c5a2a42d6ff16afcdc3ac39f007921b9cb57)

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

index 9e2815977967eb898678cedb8d5d37492a5f6729..2373f1a4f2cea6abf63987b650c143c3923b8afe 100644 (file)
@@ -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;
                 }