* [PATCH 0/6] slimbus: core: fix device, OF node and rpm leaks
@ 2025-11-26 14:53 Johan Hovold
2025-11-26 14:53 ` [PATCH 1/6] slimbus: core: fix OF node leak on registration failure Johan Hovold
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Johan Hovold @ 2025-11-26 14:53 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: Greg Kroah-Hartman, linux-sound, linux-kernel, Johan Hovold
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(-)
--
2.51.2
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/6] slimbus: core: fix OF node leak on registration failure
2025-11-26 14:53 [PATCH 0/6] slimbus: core: fix device, OF node and rpm leaks Johan Hovold
@ 2025-11-26 14:53 ` Johan Hovold
2025-11-26 14:53 ` [PATCH 2/6] slimbus: core: fix runtime PM imbalance on report present Johan Hovold
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2025-11-26 14:53 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: Greg Kroah-Hartman, linux-sound, linux-kernel, Johan Hovold,
Saravana Kannan
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 <saravanak@google.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/slimbus/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c
index 005fa2ef100f..c808233692ee 100644
--- a/drivers/slimbus/core.c
+++ b/drivers/slimbus/core.c
@@ -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);
}
--
2.51.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/6] slimbus: core: fix runtime PM imbalance on report present
2025-11-26 14:53 [PATCH 0/6] slimbus: core: fix device, OF node and rpm leaks Johan Hovold
2025-11-26 14:53 ` [PATCH 1/6] slimbus: core: fix OF node leak on registration failure Johan Hovold
@ 2025-11-26 14:53 ` Johan Hovold
2025-11-26 14:53 ` [PATCH 3/6] slimbus: core: fix device reference leak " Johan Hovold
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2025-11-26 14:53 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: Greg Kroah-Hartman, linux-sound, linux-kernel, Johan Hovold,
stable
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")
Cc: stable@vger.kernel.org # 4.16
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/slimbus/core.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c
index c808233692ee..9f85c4280171 100644
--- a/drivers/slimbus/core.c
+++ b/drivers/slimbus/core.c
@@ -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;
--
2.51.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/6] slimbus: core: fix device reference leak on report present
2025-11-26 14:53 [PATCH 0/6] slimbus: core: fix device, OF node and rpm leaks Johan Hovold
2025-11-26 14:53 ` [PATCH 1/6] slimbus: core: fix OF node leak on registration failure Johan Hovold
2025-11-26 14:53 ` [PATCH 2/6] slimbus: core: fix runtime PM imbalance on report present Johan Hovold
@ 2025-11-26 14:53 ` Johan Hovold
2025-11-26 14:53 ` [PATCH 4/6] slimbus: core: amend slim_get_device() kernel doc Johan Hovold
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2025-11-26 14:53 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: Greg Kroah-Hartman, linux-sound, linux-kernel, Johan Hovold,
stable
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")
Cc: stable@vger.kernel.org # 4.16
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/slimbus/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c
index 9f85c4280171..b4ab9a5d44b3 100644
--- a/drivers/slimbus/core.c
+++ b/drivers/slimbus/core.c
@@ -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);
--
2.51.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/6] slimbus: core: amend slim_get_device() kernel doc
2025-11-26 14:53 [PATCH 0/6] slimbus: core: fix device, OF node and rpm leaks Johan Hovold
` (2 preceding siblings ...)
2025-11-26 14:53 ` [PATCH 3/6] slimbus: core: fix device reference leak " Johan Hovold
@ 2025-11-26 14:53 ` Johan Hovold
2025-11-26 14:53 ` [PATCH 5/6] slimbus: core: fix of_slim_get_device() " Johan Hovold
2025-11-26 14:53 ` [PATCH 6/6] slimbus: core: clean up of_slim_get_device() Johan Hovold
5 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2025-11-26 14:53 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: Greg Kroah-Hartman, linux-sound, linux-kernel, Johan Hovold
Add a comment to clarify that slim_get_device() takes a reference to
the embedded struct device of the returned slimbus device.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/slimbus/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c
index b4ab9a5d44b3..9402950e7ebd 100644
--- a/drivers/slimbus/core.c
+++ b/drivers/slimbus/core.c
@@ -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.
*/
--
2.51.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/6] slimbus: core: fix of_slim_get_device() kernel doc
2025-11-26 14:53 [PATCH 0/6] slimbus: core: fix device, OF node and rpm leaks Johan Hovold
` (3 preceding siblings ...)
2025-11-26 14:53 ` [PATCH 4/6] slimbus: core: amend slim_get_device() kernel doc Johan Hovold
@ 2025-11-26 14:53 ` Johan Hovold
2025-11-26 14:53 ` [PATCH 6/6] slimbus: core: clean up of_slim_get_device() Johan Hovold
5 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2025-11-26 14:53 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: Greg Kroah-Hartman, linux-sound, linux-kernel, 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")
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/slimbus/core.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c
index 9402950e7ebd..a2c243e3ad52 100644
--- a/drivers/slimbus/core.c
+++ b/drivers/slimbus/core.c
@@ -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)
--
2.51.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 6/6] slimbus: core: clean up of_slim_get_device()
2025-11-26 14:53 [PATCH 0/6] slimbus: core: fix device, OF node and rpm leaks Johan Hovold
` (4 preceding siblings ...)
2025-11-26 14:53 ` [PATCH 5/6] slimbus: core: fix of_slim_get_device() " Johan Hovold
@ 2025-11-26 14:53 ` Johan Hovold
5 siblings, 0 replies; 7+ messages in thread
From: Johan Hovold @ 2025-11-26 14:53 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: Greg Kroah-Hartman, linux-sound, linux-kernel, Johan Hovold
Clean up of_find_slim_device() by folding in the of_find_slim_device()
helper.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/slimbus/core.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c
index a2c243e3ad52..5079d3271ee8 100644
--- a/drivers/slimbus/core.c
+++ b/drivers/slimbus/core.c
@@ -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);
--
2.51.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-11-26 14:54 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-26 14:53 [PATCH 0/6] slimbus: core: fix device, OF node and rpm leaks Johan Hovold
2025-11-26 14:53 ` [PATCH 1/6] slimbus: core: fix OF node leak on registration failure Johan Hovold
2025-11-26 14:53 ` [PATCH 2/6] slimbus: core: fix runtime PM imbalance on report present Johan Hovold
2025-11-26 14:53 ` [PATCH 3/6] slimbus: core: fix device reference leak " Johan Hovold
2025-11-26 14:53 ` [PATCH 4/6] slimbus: core: amend slim_get_device() kernel doc Johan Hovold
2025-11-26 14:53 ` [PATCH 5/6] slimbus: core: fix of_slim_get_device() " Johan Hovold
2025-11-26 14:53 ` [PATCH 6/6] slimbus: core: clean up of_slim_get_device() Johan Hovold
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox