Skip to contentSkip to conversation

slimbus: core: fix device, OF node and rpm leaks

PATCH New Johan Hovold 1 participant 7 messages Nov 26, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover slimbus: core: fix device, OF node and rpm leaks

This series fixes device, OF node and runtime PM reference leaks in the slimbus implementation.

Included are also two related kernel doc updates and cleanup of one of the involved helpers.

Johan

Johan Hovold (6):
slimbus: core: fix OF node leak on registration failure
slimbus: core: fix runtime PM imbalance on report present
slimbus: core: fix device reference leak on report present
slimbus: core: amend slim_get_device() kernel doc
slimbus: core: fix of_slim_get_device() kernel doc
slimbus: core: clean up of_slim_get_device()

 drivers/slimbus/core.c | 54 +++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 25 deletions(-)
Signature · 1 line
2.51.2
#1 lore raw

PATCH 1/6 slimbus: core: fix OF node leak on registration failure

Make sure to drop the OF node reference taken when initialising and registering the slimbus device also on registration failure by releasing it in the destructor as expected.

Fixes 7588a511bdb4 ("slimbus: core: add support to device tree helper")
Fixes 01360857486c ("slimbus: core: Fix mismatch in of_node_get/put")
Cc Saravana Kannan <[email protected]>
---
 drivers/slimbus/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/slimbus/core.c +1 -1
index 005fa2ef100f..c808233692ee 100644
@@ -146,6 +146,7 @@ static void slim_dev_release(struct device *dev)
 {
 	struct slim_device *sbdev = to_slim_device(dev);
 
+	of_node_put(sbdev->dev.of_node);
 	kfree(sbdev);
 }
 
@@ -280,7 +281,6 @@ EXPORT_SYMBOL_GPL(slim_register_controller);
 /* slim_remove_device: Remove the effect of slim_add_device() */
 static void slim_remove_device(struct slim_device *sbdev)
 {
-	of_node_put(sbdev->dev.of_node);
 	device_unregister(&sbdev->dev);
 }
 
Signature · 1 line
2.51.2
#2 lore raw

PATCH 2/6 slimbus: core: fix runtime PM imbalance on report present

In reply to Johan Hovold

Make sure to balance the runtime PM usage count in case slimbus device or address allocation fails on report present, which would otherwise prevent the controller from suspending.

Fixes 4b14e62ad3c9 ("slimbus: Add support for 'clock-pause' feature")
---
 drivers/slimbus/core.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/slimbus/core.c +9 -7
index c808233692ee..9f85c4280171 100644
@@ -489,21 +489,23 @@ int slim_device_report_present(struct slim_controller *ctrl,
 	if (ctrl->sched.clk_state != SLIM_CLK_ACTIVE) {
 		dev_err(ctrl->dev, "slim ctrl not active,state:%d, ret:%d\n",
 				    ctrl->sched.clk_state, ret);
-		goto slimbus_not_active;
+		goto out_put_rpm;
 	}
 
 	sbdev = slim_get_device(ctrl, e_addr);
-	if (IS_ERR(sbdev))
-		return -ENODEV;
+	if (IS_ERR(sbdev)) {
+		ret = -ENODEV;
+		goto out_put_rpm;
+	}
 
 	if (sbdev->is_laddr_valid) {
 		*laddr = sbdev->laddr;
-		return 0;
+		ret = 0;
+	} else {
+		ret = slim_device_alloc_laddr(sbdev, true);
 	}
 
-	ret = slim_device_alloc_laddr(sbdev, true);
-
-slimbus_not_active:
+out_put_rpm:
 	pm_runtime_mark_last_busy(ctrl->dev);
 	pm_runtime_put_autosuspend(ctrl->dev);
 	return ret;
Signature · 1 line
2.51.2
#3 lore raw

PATCH 3/6 slimbus: core: fix device reference leak on report present

In reply to Johan Hovold

Slimbus devices can be allocated dynamically upon reception of report-present messages.

Make sure to drop the reference taken when looking up already registered devices.

Note that this requires taking an extra reference in case the device has not yet been registered and has to be allocated.

Fixes 46a2bb5a7f7e ("slimbus: core: Add slim controllers support")
---
 drivers/slimbus/core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/slimbus/core.c +3 -0
index 9f85c4280171..b4ab9a5d44b3 100644
@@ -379,6 +379,8 @@ struct slim_device *slim_get_device(struct slim_controller *ctrl,
 		sbdev = slim_alloc_device(ctrl, e_addr, NULL);
 		if (!sbdev)
 			return ERR_PTR(-ENOMEM);
+
+		get_device(&sbdev->dev);
 	}
 
 	return sbdev;
@@ -505,6 +507,7 @@ int slim_device_report_present(struct slim_controller *ctrl,
 		ret = slim_device_alloc_laddr(sbdev, true);
 	}
 
+	put_device(&sbdev->dev);
 out_put_rpm:
 	pm_runtime_mark_last_busy(ctrl->dev);
 	pm_runtime_put_autosuspend(ctrl->dev);
Signature · 1 line
2.51.2
#4 lore raw

PATCH 4/6 slimbus: core: amend slim_get_device() kernel doc

In reply to Johan Hovold

Add a comment to clarify that slim_get_device() takes a reference to the embedded struct device of the returned slimbus device.

---
 drivers/slimbus/core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/slimbus/core.c +3 -0
index b4ab9a5d44b3..9402950e7ebd 100644
@@ -366,6 +366,9 @@ static struct slim_device *find_slim_device(struct slim_controller *ctrl,
  * @ctrl: Controller on which this device will be added/queried
  * @e_addr: Enumeration address of the device to be queried
  *
+ * Takes a reference to the embedded struct device which needs to be dropped
+ * after use.
+ *
  * Return: pointer to a device if it has already reported. Creates a new
  * device and returns pointer to it if the device has not yet enumerated.
  */
Signature · 1 line
2.51.2
#5 lore raw

PATCH 5/6 slimbus: core: fix of_slim_get_device() kernel doc

In reply to Johan Hovold

Unlike slim_get_device() the of_slim_get_device() helper does not allocate and register any slimbus devices in case lookup fails.

Update the of_slim_get_device() kernel doc to reflect this and add a comment about the helper taking a reference to the returned device.

Fixes e0772de8a48b ("slimbus: core: add of_slim_device_get() helper")
---
 drivers/slimbus/core.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/slimbus/core.c +5 -3
index 9402950e7ebd..a2c243e3ad52 100644
@@ -408,11 +408,13 @@ static struct slim_device *of_find_slim_device(struct slim_controller *ctrl,
 /**
  * of_slim_get_device() - get handle to a device using dt node.
  *
- * @ctrl: Controller on which this device will be added/queried
+ * @ctrl: Controller on which this device will be queried
  * @np: node pointer to device
  *
- * Return: pointer to a device if it has already reported. Creates a new
- * device and returns pointer to it if the device has not yet enumerated.
+ * Takes a reference to the embedded struct device which needs to be dropped
+ * after use.
+ *
+ * Return: pointer to a device if it has been registered, otherwise NULL.
  */
 struct slim_device *of_slim_get_device(struct slim_controller *ctrl,
 				       struct device_node *np)
Signature · 1 line
2.51.2
#6 lore raw

PATCH 6/6 slimbus: core: clean up of_slim_get_device()

In reply to Johan Hovold

Clean up of_find_slim_device() by folding in the of_find_slim_device() helper.

---
 drivers/slimbus/core.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)
drivers/slimbus/core.c +10 -16
index a2c243e3ad52..5079d3271ee8 100644
@@ -390,21 +390,6 @@ struct slim_device *slim_get_device(struct slim_controller *ctrl,
 }
 EXPORT_SYMBOL_GPL(slim_get_device);
 
-static struct slim_device *of_find_slim_device(struct slim_controller *ctrl,
-					       struct device_node *np)
-{
-	struct slim_device *sbdev;
-	struct device *dev;
-
-	dev = device_find_child(ctrl->dev, np, device_match_of_node);
-	if (dev) {
-		sbdev = to_slim_device(dev);
-		return sbdev;
-	}
-
-	return NULL;
-}
-
 /**
  * of_slim_get_device() - get handle to a device using dt node.
  *
@@ -419,7 +404,16 @@ static struct slim_device *of_find_slim_device(struct slim_controller *ctrl,
 struct slim_device *of_slim_get_device(struct slim_controller *ctrl,
 				       struct device_node *np)
 {
-	return of_find_slim_device(ctrl, np);
+	struct slim_device *sbdev;
+	struct device *dev;
+
+	dev = device_find_child(ctrl->dev, np, device_match_of_node);
+	if (dev) {
+		sbdev = to_slim_device(dev);
+		return sbdev;
+	}
+
+	return NULL;
 }
 EXPORT_SYMBOL_GPL(of_slim_get_device);
 
Signature · 1 line
2.51.2