soc: amlogic: canvas: fix device leak on lookup
Subsystems (2)
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
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.
--- drivers/soc/amlogic/meson-canvas.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/soc/amlogic/meson-canvas.c +2 -3
@@ -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
Quoted 2 lines
Make sure to drop the reference taken to the canvas platform device when looking up its driver data.
…
How do you think about to increase the application of scope-based resource management?
https://elixir.bootlin.com/linux/v6.17-rc7/source/include/linux/device.h#L1180
Regards,
Markus
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 missingput_device()call inmeson_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: 28f851e6afa8Cc Yu Kuai <[email protected]>Signed-off-by Johan Hovold <[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
PATCH 2/2 soc: amlogic: canvas: simplify lookup error handling
In reply to Johan HovoldSimplify 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
@@ -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
Re: [PATCH 2/2] soc: amlogic: canvas: simplify lookup error handling
Quoted 2 lines
Simplify the canvas lookup error handling by dropping the OF node reference sooner.
How do you think about to increase the application of scope-based resource management?
https://elixir.bootlin.com/linux/v6.17-rc7/source/include/linux/of.h#L138
Regards,
Markus
Re: [PATCH 2/2] soc: amlogic: canvas: simplify lookup error handling
In reply to Johan HovoldQuoted 5 lines · Johan Hovold
Simplify the canvas lookup error handling by dropping the OF node reference sooner.
Signed-off-by Johan Hovold <[email protected]>
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