Skip to contentSkip to conversation

driver core: auxiliary bus: fix OF node leak

PATCH In review Johan Hovold 4 participants 5 messages Jul 8, 2025

Subsystems (2)
lore
Share & tools
lore

Johan Hovold

author maintainer
#0 lore raw

PATCH 1/1 driver core: auxiliary bus: fix OF node leak

Make sure to drop the OF node reference taken when creating an auxiliary device using auxiliary_device_create() when the device is later released.

Fixes eaa0d30216c1 ("driver core: auxiliary bus: add device creation helpers")
Cc Jerome Brunet <[email protected]>
---
 drivers/base/auxiliary.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/base/auxiliary.c +2 -0
index dba7c8e13a53..6bdefebf3609 100644
@@ -399,6 +399,7 @@ static void auxiliary_device_release(struct device *dev)
 {
 	struct auxiliary_device *auxdev = to_auxiliary_dev(dev);
 
+	of_node_put(dev->of_node);
 	kfree(auxdev);
 }
 
@@ -435,6 +436,7 @@ struct auxiliary_device *auxiliary_device_create(struct device *dev,
 
 	ret = auxiliary_device_init(auxdev);
 	if (ret) {
+		of_node_put(auxdev->dev.of_node);
 		kfree(auxdev);
 		return NULL;
 	}
Signature · 1 line
2.49.0
#1 lore raw
Quoted 3 lines · Johan Hovold

Make sure to drop the OF node reference taken when creating an auxiliary device using auxiliary_device_create() when the device is later released.

I'm probably missing something, but random grep for the device_set_of_node_from_dev() callers shows that none of them are calling to of_node_put() explicitly.

Thanks

Quoted 31 lines
Fixes eaa0d30216c1 ("driver core: auxiliary bus: add device creation helpers")
Cc Jerome Brunet <[email protected]>
---
 drivers/base/auxiliary.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/base/auxiliary.c +2 -0
index dba7c8e13a53..6bdefebf3609 100644
@@ -399,6 +399,7 @@ static void auxiliary_device_release(struct device *dev)
 {
 	struct auxiliary_device *auxdev = to_auxiliary_dev(dev);
 
+	of_node_put(dev->of_node);
 	kfree(auxdev);
 }
 
@@ -435,6 +436,7 @@ struct auxiliary_device *auxiliary_device_create(struct device *dev,
 
 	ret = auxiliary_device_init(auxdev);
 	if (ret) {
+		of_node_put(auxdev->dev.of_node);
 		kfree(auxdev);
 		return NULL;
 	}
Signature · 1 line
2.49.0
author maintainer
#2 lore raw
Quoted 8 lines · Leon Romanovsky
Quoted 3 lines · Johan Hovold

Make sure to drop the OF node reference taken when creating an auxiliary device using auxiliary_device_create() when the device is later released.

I'm probably missing something, but random grep for the device_set_of_node_from_dev() callers shows that none of them are calling to of_node_put() explicitly.

Yeah, the platform bus code takes care of dropping the reference for platform devices.

Johan

Reviewed-by
#3 lore raw
Quoted 6 lines · Johan Hovold
Quoted 5 lines · Leon Romanovsky
Quoted 3 lines · Johan Hovold

Make sure to drop the OF node reference taken when creating an auxiliary device using auxiliary_device_create() when the device is later released.

Quoted 6 lines
Quoted 3 lines

I'm probably missing something, but random grep for the device_set_of_node_from_dev() callers shows that none of them are calling to of_node_put() explicitly.

Yeah, the platform bus code takes care of dropping the reference for platform devices.

There is an of_node_get() that needs balancing indeed, Thanks

Quoted 2 lines

Johan

Signature · 1 line
Jerome