diff mbox series

power: supply: Propagate of_node to child device

Message ID 20230704-power-of-v1-1-cc82d2eda65b@axis.com
State New
Headers show
Series power: supply: Propagate of_node to child device | expand

Commit Message

Vincent Whitchurch July 4, 2023, 7:43 a.m. UTC
Ensure that the dynamically created power supply device sets its
->of_node if the parent device has 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>
---
 drivers/power/supply/power_supply_core.c | 1 +
 1 file changed, 1 insertion(+)


---
base-commit: 6995e2de6891c724bfeb2db33d7b87775f913ad1
change-id: 20230704-power-of-4e2ab0bbe48d

Best regards,

Comments

Sebastian Reichel Sept. 14, 2023, 3:22 p.m. UTC | #1
Hi,

On Tue, Jul 04, 2023 at 09:43:29AM +0200, Vincent Whitchurch wrote:
> Ensure that the dynamically created power supply device sets its
> ->of_node if the parent device has 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>
> ---

This should use the same value as psy->of_node (so cfg->of_node),
which can be different from the parent of_node in some corner cases.

(also psy->of_node can be dropped in favour of always using
psy->dev->of_node, but that's a separate patch)

P.S.: Sorry for slow review

-- Sebastian

>  drivers/power/supply/power_supply_core.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index 3791aec69ddc6..8769d82dd9c3d 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -1368,6 +1368,7 @@ __power_supply_register(struct device *parent,
>  	dev->class = power_supply_class;
>  	dev->type = &power_supply_dev_type;
>  	dev->parent = parent;
> +	dev->of_node = parent->of_node;
>  	dev->release = power_supply_dev_release;
>  	dev_set_drvdata(dev, psy);
>  	psy->desc = desc;
> 
> ---
> base-commit: 6995e2de6891c724bfeb2db33d7b87775f913ad1
> change-id: 20230704-power-of-4e2ab0bbe48d
> 
> Best regards,
> -- 
> Vincent Whitchurch <vincent.whitchurch@axis.com>
>
diff mbox series

Patch

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 3791aec69ddc6..8769d82dd9c3d 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -1368,6 +1368,7 @@  __power_supply_register(struct device *parent,
 	dev->class = power_supply_class;
 	dev->type = &power_supply_dev_type;
 	dev->parent = parent;
+	dev->of_node = parent->of_node;
 	dev->release = power_supply_dev_release;
 	dev_set_drvdata(dev, psy);
 	psy->desc = desc;