power: supply: Propagate of_node to child device
authorVincent Whitchurch <vincent.whitchurch@axis.com>
Fri, 15 Sep 2023 07:02:14 +0000 (09:02 +0200)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Fri, 15 Sep 2023 19:41:57 +0000 (21:41 +0200)
Ensure that the dynamically created power supply device sets its
->of_node if the driver supplies one.  This brings it in line with
several other subsystems (see git grep 'of_node =.*parent.*of_node') and
allows easier identification of the device from udev rules and similar.

Before this patch:

 /sys/class/power_supply# ls -l bq256xx-battery/of_node
 ls: cannot access 'bq256xx-battery/of_node': No such file or directory
 # ls -l bq256xx-battery/hwmon1/of_node
 ls: cannot access 'bq256xx-battery/hwmon1/of_node': No such file or directory

After:

 /sys/class/power_supply# ls -l bq256xx-battery/of_node
 lrwxrwxrwx 1 root root 0 May 17 09:14 bq256xx-battery/of_node ->
 ../../../../../../../../firmware/devicetree/base/virtio@1/i2c/bq25619@09
 # ls -l bq256xx-battery/hwmon1/of_node
 lrwxrwxrwx 1 root root 0 May 17 09:14 bq256xx-battery/hwmon1/of_node ->
 ../../../../../../../../../firmware/devicetree/base/virtio@1/i2c/bq25619@09

Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
Link: https://lore.kernel.org/r/20230915-power-of-v2-1-ca54c441867e@axis.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/power_supply_core.c

index 416409e2fd6da274be964c6230ec0f3bcb1543fd..6e30674be366d45fc7f552d3abbed1b7f731a964 100644 (file)
@@ -1380,6 +1380,7 @@ __power_supply_register(struct device *parent,
                psy->drv_data = cfg->drv_data;
                psy->of_node =
                        cfg->fwnode ? to_of_node(cfg->fwnode) : cfg->of_node;
+               dev->of_node = psy->of_node;
                psy->supplied_to = cfg->supplied_to;
                psy->num_supplicants = cfg->num_supplicants;
        }