* [PATCH 1/2] soc: amlogic: canvas: fix device leak on lookup [not found] <20250926142454.5929-1-johan@kernel.org> @ 2025-09-26 14:24 ` Johan Hovold 2025-09-26 19:15 ` Markus Elfring 2025-10-04 19:52 ` Martin Blumenstingl 0 siblings, 2 replies; 3+ messages in thread From: Johan Hovold @ 2025-09-26 14:24 UTC (permalink / raw) To: Neil Armstrong, Kevin Hilman Cc: Jerome Brunet, Martin Blumenstingl, linux-amlogic, linux-kernel, Johan Hovold, stable, Yu Kuai 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: stable@vger.kernel.org # 4.20: 28f851e6afa8 Cc: Yu Kuai <yukuai3@huawei.com> Signed-off-by: Johan Hovold <johan@kernel.org> --- drivers/soc/amlogic/meson-canvas.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/soc/amlogic/meson-canvas.c b/drivers/soc/amlogic/meson-canvas.c index b6e06c4d2117..0711088da5dc 100644 --- a/drivers/soc/amlogic/meson-canvas.c +++ b/drivers/soc/amlogic/meson-canvas.c @@ -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; } -- 2.49.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] soc: amlogic: canvas: fix device leak on lookup 2025-09-26 14:24 ` [PATCH 1/2] soc: amlogic: canvas: fix device leak on lookup Johan Hovold @ 2025-09-26 19:15 ` Markus Elfring 2025-10-04 19:52 ` Martin Blumenstingl 1 sibling, 0 replies; 3+ messages in thread From: Markus Elfring @ 2025-09-26 19:15 UTC (permalink / raw) To: Johan Hovold, linux-amlogic, Kevin Hilman, Neil Armstrong Cc: stable, LKML, Jerome Brunet, Martin Blumenstingl, Yu Kuai > 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] soc: amlogic: canvas: fix device leak on lookup 2025-09-26 14:24 ` [PATCH 1/2] soc: amlogic: canvas: fix device leak on lookup Johan Hovold 2025-09-26 19:15 ` Markus Elfring @ 2025-10-04 19:52 ` Martin Blumenstingl 1 sibling, 0 replies; 3+ messages in thread From: Martin Blumenstingl @ 2025-10-04 19:52 UTC (permalink / raw) To: Johan Hovold Cc: Neil Armstrong, Kevin Hilman, Jerome Brunet, linux-amlogic, linux-kernel, stable, Yu Kuai, Markus.Elfring On Fri, Sep 26, 2025 at 4:25 PM Johan Hovold <johan@kernel.org> wrote: > > 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: stable@vger.kernel.org # 4.20: 28f851e6afa8 > Cc: Yu Kuai <yukuai3@huawei.com> > Signed-off-by: Johan Hovold <johan@kernel.org> Reviewed-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com> 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-04 19:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20250926142454.5929-1-johan@kernel.org>
2025-09-26 14:24 ` [PATCH 1/2] soc: amlogic: canvas: fix device leak on lookup Johan Hovold
2025-09-26 19:15 ` Markus Elfring
2025-10-04 19:52 ` Martin Blumenstingl
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox