Skip to contentSkip to conversation

soc: amlogic: canvas: fix device leak on lookup

PATCH Applied Johan Hovold 4 participants 8 messages Sep 26, 2025 – Oct 21, 2025

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

cover soc: amlogic: canvas: fix device leak on lookup

This series fixes a device leak in the canvas lookup helper and simplifies the lookup error handling somewhat.

Johan

Johan Hovold (2):
soc: amlogic: canvas: fix device leak on lookup
soc: amlogic: canvas: simplify lookup error handling

 drivers/soc/amlogic/meson-canvas.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
Signature · 1 line
2.49.1
#1 lore raw

PATCH 1/2 soc: amlogic: canvas: fix device leak on lookup

Make sure to drop the reference taken to the canvas platform device when looking up its driver data.

Note that holding a reference to a device does not prevent its driver data from going away so there is no point in keeping the reference.

Also note that commit 28f851e6afa8 ("soc: amlogic: canvas: add missing put_device() call in meson_canvas_get()") fixed the leak in a lookup error path, but the reference is still leaking on success.

Fixes d4983983d987 ("soc: amlogic: add meson-canvas driver")
Cc [email protected] # 4.20: 28f851e6afa8
Cc Yu Kuai <[email protected]>
---
 drivers/soc/amlogic/meson-canvas.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/soc/amlogic/meson-canvas.c +2 -3
index b6e06c4d2117..0711088da5dc 100644
@@ -73,10 +73,9 @@ struct meson_canvas *meson_canvas_get(struct device *dev)
 	 * current state, this driver probe cannot return -EPROBE_DEFER
 	 */
 	canvas = dev_get_drvdata(&canvas_pdev->dev);
-	if (!canvas) {
-		put_device(&canvas_pdev->dev);
+	put_device(&canvas_pdev->dev);
+	if (!canvas)
 		return ERR_PTR(-EINVAL);
-	}
 
 	return canvas;
 }
Signature · 1 line
2.49.1
reviewer Reviewed-by on v1 1/2
#3 lore raw
In reply to Johan Hovold
Quoted 7 lines · Johan Hovold

Make sure to drop the reference taken to the canvas platform device when looking up its driver data.

Note that holding a reference to a device does not prevent its driver data from going away so there is no point in keeping the reference.

Quoted 8 lines

Also note that commit 28f851e6afa8 ("soc: amlogic: canvas: add missing put_device() call in meson_canvas_get()") fixed the leak in a lookup error path, but the reference is still leaking on success.

Fixes d4983983d987 ("soc: amlogic: add meson-canvas driver")
Cc [email protected] # 4.20: 28f851e6afa8
Cc Yu Kuai <[email protected]>

I haven't used the scope-based resource management myself as pointed out by Markus.
That said, as far as I understand it's a feature in newer kernels and this patch may be backported until 5.4 (oldest -stable kernel still supported).
So let's go with this simple approach from Johan - we can still improve this (without having to worry about backports).

Best regards,
Martin

#4 lore raw

PATCH 2/2 soc: amlogic: canvas: simplify lookup error handling

In reply to Johan Hovold

Simplify the canvas lookup error handling by dropping the OF node reference sooner.

---
 drivers/soc/amlogic/meson-canvas.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/soc/amlogic/meson-canvas.c +2 -5
index 0711088da5dc..79681afea8c6 100644
@@ -60,12 +60,9 @@ struct meson_canvas *meson_canvas_get(struct device *dev)
 		return ERR_PTR(-ENODEV);
 
 	canvas_pdev = of_find_device_by_node(canvas_node);
-	if (!canvas_pdev) {
-		of_node_put(canvas_node);
-		return ERR_PTR(-EPROBE_DEFER);
-	}
-
 	of_node_put(canvas_node);
+	if (!canvas_pdev)
+		return ERR_PTR(-EPROBE_DEFER);
 
 	/*
 	 * If priv is NULL, it's probably because the canvas hasn't
Signature · 1 line
2.49.1
maintainer Applied
#7 lore raw
In reply to Johan Hovold

Hi,

Quoted 11 lines · Johan Hovold

This series fixes a device leak in the canvas lookup helper and simplifies the lookup error handling somewhat.

Johan

Johan Hovold (2):
soc: amlogic: canvas: fix device leak on lookup
soc: amlogic: canvas: simplify lookup error handling

[...]

Thanks, Applied to https://git.kernel.org/pub/scm/linux/kernel/git/amlogic/linux.git (v6.19/drivers)

[1/2] soc: amlogic: canvas: fix device leak on lookup

      https://git.kernel.org/amlogic/c/32200f4828de9d7e6db379909898e718747f4e18
[2/2] soc: amlogic: canvas: simplify lookup error handling
      https://git.kernel.org/amlogic/c/075daf22641870e435a16ec2129bfd3b3134c487

These changes has been applied on the intermediate git tree [1].

The v6.19/drivers branch will then be sent via a formal Pull Request to the Linux SoC maintainers for inclusion in their intermediate git branches in order to be sent to Linus during the next merge window, or sooner if it's a set of fixes.

In the cases of fixes, those will be merged in the current release candidate kernel and as soon they appear on the Linux master branch they will be backported to the previous Stable and Long-Stable kernels [2].

The intermediate git branches are merged daily in the linux-next tree [3], people are encouraged testing these pre-release kernels and report issues on the relevant mailing-lists.

If problems are discovered on those changes, please submit a signed-off-by revert patch followed by a corrective changeset.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/amlogic/linux.git
[2] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
[3] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git

Signature · 1 line
Neil