* [PATCH 1/3] media: mediatek: vcodec: fix device leak on codec init
2025-09-24 13:35 [PATCH 0/3] media: mediatek: fix VPU device leaks on probe Johan Hovold
@ 2025-09-24 13:35 ` Johan Hovold
2025-09-24 13:35 ` [PATCH 2/3] media: mediatek: mdp: fix device leak on probe Johan Hovold
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2025-09-24 13:35 UTC (permalink / raw)
To: Minghsiu Tsai, Houlong Wei, Andrew-CT Chen, Tiffany Lin,
Yunfei Dong
Cc: Mauro Carvalho Chehab, Matthias Brugger,
AngeloGioacchino Del Regno, Hans Verkuil, linux-media,
linux-mediatek, linux-kernel, Johan Hovold, stable
Make sure to drop the reference taken when looking up the VPU firmware
device during codec init on probe failure (e.g. probe deferral) and on
driver unbind.
Fixes: 590577a4e525 ("[media] vcodec: mediatek: Add Mediatek V4L2 Video Decoder Driver")
Fixes: 4e855a6efa54 ("[media] vcodec: mediatek: Add Mediatek V4L2 Video Encoder Driver")
Cc: stable@vger.kernel.org # 4.8
Cc: Tiffany Lin <tiffany.lin@mediatek.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
.../mediatek/vcodec/common/mtk_vcodec_fw_vpu.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c
index d7027d600208..9237738d7632 100644
--- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c
+++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vpu.c
@@ -83,12 +83,20 @@ static const struct mtk_vcodec_fw_ops mtk_vcodec_vpu_msg = {
.release = mtk_vcodec_vpu_release,
};
+static void mtk_vcodec_vpu_put_device(void *_dev)
+{
+ struct device *dev = _dev;
+
+ put_device(dev);
+}
+
struct mtk_vcodec_fw *mtk_vcodec_fw_vpu_init(void *priv, enum mtk_vcodec_fw_use fw_use)
{
struct platform_device *fw_pdev;
struct platform_device *plat_dev;
struct mtk_vcodec_fw *fw;
enum rst_id rst_id;
+ int ret;
if (fw_use == ENCODER) {
struct mtk_vcodec_enc_dev *enc_dev = priv;
@@ -111,6 +119,11 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_vpu_init(void *priv, enum mtk_vcodec_fw_use
return ERR_PTR(-EINVAL);
}
+ ret = devm_add_action_or_reset(&plat_dev->dev, mtk_vcodec_vpu_put_device,
+ &fw_pdev->dev);
+ if (ret)
+ return ERR_PTR(ret);
+
if (fw_use == DECODER)
vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_vpu_reset_dec_handler, priv, rst_id);
else
--
2.49.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 2/3] media: mediatek: mdp: fix device leak on probe
2025-09-24 13:35 [PATCH 0/3] media: mediatek: fix VPU device leaks on probe Johan Hovold
2025-09-24 13:35 ` [PATCH 1/3] media: mediatek: vcodec: fix device leak on codec init Johan Hovold
@ 2025-09-24 13:35 ` Johan Hovold
2025-09-24 13:35 ` [PATCH 3/3] media: mediatek: amend vpu_get_plat_device() documentation Johan Hovold
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2025-09-24 13:35 UTC (permalink / raw)
To: Minghsiu Tsai, Houlong Wei, Andrew-CT Chen, Tiffany Lin,
Yunfei Dong
Cc: Mauro Carvalho Chehab, Matthias Brugger,
AngeloGioacchino Del Regno, Hans Verkuil, linux-media,
linux-mediatek, linux-kernel, Johan Hovold, stable
Make sure to drop the reference taken when looking up the VPU firmware
device during probe on probe failure (e.g. probe deferral) and on driver
unbind.
Fixes: c8eb2d7e8202 ("[media] media: Add Mediatek MDP Driver")
Cc: stable@vger.kernel.org # 4.10
Cc: Minghsiu Tsai <minghsiu.tsai@mediatek.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/media/platform/mediatek/mdp/mtk_mdp_core.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/media/platform/mediatek/mdp/mtk_mdp_core.c b/drivers/media/platform/mediatek/mdp/mtk_mdp_core.c
index 80fdc6ff57e0..5c7dcf4090f4 100644
--- a/drivers/media/platform/mediatek/mdp/mtk_mdp_core.c
+++ b/drivers/media/platform/mediatek/mdp/mtk_mdp_core.c
@@ -198,7 +198,7 @@ static int mtk_mdp_probe(struct platform_device *pdev)
VPU_RST_MDP);
if (ret) {
dev_err(&pdev->dev, "Failed to register reset handler\n");
- goto err_m2m_register;
+ goto err_put_vpu;
}
platform_set_drvdata(pdev, mdp);
@@ -206,7 +206,7 @@ static int mtk_mdp_probe(struct platform_device *pdev)
ret = vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32));
if (ret) {
dev_err(&pdev->dev, "Failed to set vb2 dma mag seg size\n");
- goto err_m2m_register;
+ goto err_put_vpu;
}
pm_runtime_enable(dev);
@@ -214,6 +214,8 @@ static int mtk_mdp_probe(struct platform_device *pdev)
return 0;
+err_put_vpu:
+ put_device(&mdp->vpu_dev->dev);
err_m2m_register:
v4l2_device_unregister(&mdp->v4l2_dev);
@@ -241,6 +243,7 @@ static void mtk_mdp_remove(struct platform_device *pdev)
struct mtk_mdp_comp *comp, *comp_temp;
pm_runtime_disable(&pdev->dev);
+ put_device(&mdp->vpu_dev->dev);
vb2_dma_contig_clear_max_seg_size(&pdev->dev);
mtk_mdp_unregister_m2m_device(mdp);
v4l2_device_unregister(&mdp->v4l2_dev);
--
2.49.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 3/3] media: mediatek: amend vpu_get_plat_device() documentation
2025-09-24 13:35 [PATCH 0/3] media: mediatek: fix VPU device leaks on probe Johan Hovold
2025-09-24 13:35 ` [PATCH 1/3] media: mediatek: vcodec: fix device leak on codec init Johan Hovold
2025-09-24 13:35 ` [PATCH 2/3] media: mediatek: mdp: fix device leak on probe Johan Hovold
@ 2025-09-24 13:35 ` Johan Hovold
2025-09-25 4:54 ` [PATCH 0/3] media: mediatek: fix VPU device leaks on probe Chen-Yu Tsai
2025-10-27 13:37 ` Johan Hovold
4 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2025-09-24 13:35 UTC (permalink / raw)
To: Minghsiu Tsai, Houlong Wei, Andrew-CT Chen, Tiffany Lin,
Yunfei Dong
Cc: Mauro Carvalho Chehab, Matthias Brugger,
AngeloGioacchino Del Regno, Hans Verkuil, linux-media,
linux-mediatek, linux-kernel, Johan Hovold
Add a comment to the vpu_get_plat_device() documentation to make it
clear that the VPU platform device is returned with an incremented
reference count (which needs to be dropped after use).
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/media/platform/mediatek/vpu/mtk_vpu.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/media/platform/mediatek/vpu/mtk_vpu.h b/drivers/media/platform/mediatek/vpu/mtk_vpu.h
index da05f3e74081..5808311d2b15 100644
--- a/drivers/media/platform/mediatek/vpu/mtk_vpu.h
+++ b/drivers/media/platform/mediatek/vpu/mtk_vpu.h
@@ -120,7 +120,7 @@ int vpu_ipi_send(struct platform_device *pdev,
* device for using VPU API.
*
* Return: Return NULL if it is failed.
- * otherwise it is VPU's platform device
+ * otherwise it is VPU's platform device with incremented reference count
**/
struct platform_device *vpu_get_plat_device(struct platform_device *pdev);
--
2.49.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 0/3] media: mediatek: fix VPU device leaks on probe
2025-09-24 13:35 [PATCH 0/3] media: mediatek: fix VPU device leaks on probe Johan Hovold
` (2 preceding siblings ...)
2025-09-24 13:35 ` [PATCH 3/3] media: mediatek: amend vpu_get_plat_device() documentation Johan Hovold
@ 2025-09-25 4:54 ` Chen-Yu Tsai
2025-10-27 13:37 ` Johan Hovold
4 siblings, 0 replies; 9+ messages in thread
From: Chen-Yu Tsai @ 2025-09-25 4:54 UTC (permalink / raw)
To: Johan Hovold
Cc: Minghsiu Tsai, Houlong Wei, Andrew-CT Chen, Tiffany Lin,
Yunfei Dong, Mauro Carvalho Chehab, Matthias Brugger,
AngeloGioacchino Del Regno, Hans Verkuil, linux-media,
linux-mediatek, linux-kernel
On Wed, Sep 24, 2025 at 9:36 PM Johan Hovold <johan@kernel.org> wrote:
>
> This series fixes VPU device leaks during probe of the mdp and two codec
> drivers.
>
> Included is also a minor documentation update to make it clear that the
> VPU lookup helper returns the device with an incremented refcount.
>
> Johan
>
>
> Johan Hovold (3):
> media: mediatek: vcodec: fix device leak on codec init
> media: mediatek: mdp: fix device leak on probe
> media: mediatek: amend vpu_get_plat_device() documentation
Whole series is
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
>
> drivers/media/platform/mediatek/mdp/mtk_mdp_core.c | 7 +++++--
> .../mediatek/vcodec/common/mtk_vcodec_fw_vpu.c | 13 +++++++++++++
> drivers/media/platform/mediatek/vpu/mtk_vpu.h | 2 +-
> 3 files changed, 19 insertions(+), 3 deletions(-)
>
> --
> 2.49.1
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 0/3] media: mediatek: fix VPU device leaks on probe
2025-09-24 13:35 [PATCH 0/3] media: mediatek: fix VPU device leaks on probe Johan Hovold
` (3 preceding siblings ...)
2025-09-25 4:54 ` [PATCH 0/3] media: mediatek: fix VPU device leaks on probe Chen-Yu Tsai
@ 2025-10-27 13:37 ` Johan Hovold
2025-10-27 19:29 ` Nicolas Dufresne
4 siblings, 1 reply; 9+ messages in thread
From: Johan Hovold @ 2025-10-27 13:37 UTC (permalink / raw)
To: Minghsiu Tsai, Houlong Wei, Andrew-CT Chen, Tiffany Lin,
Yunfei Dong
Cc: Mauro Carvalho Chehab, Matthias Brugger,
AngeloGioacchino Del Regno, Hans Verkuil, linux-media,
linux-mediatek, linux-kernel
On Wed, Sep 24, 2025 at 03:35:49PM +0200, Johan Hovold wrote:
> This series fixes VPU device leaks during probe of the mdp and two codec
> drivers.
>
> Included is also a minor documentation update to make it clear that the
> VPU lookup helper returns the device with an incremented refcount.
Can these be picked up for 6.19?
Johan
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 0/3] media: mediatek: fix VPU device leaks on probe
2025-10-27 13:37 ` Johan Hovold
@ 2025-10-27 19:29 ` Nicolas Dufresne
2025-10-28 8:21 ` Johan Hovold
0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Dufresne @ 2025-10-27 19:29 UTC (permalink / raw)
To: Johan Hovold, Minghsiu Tsai, Houlong Wei, Andrew-CT Chen,
Tiffany Lin, Yunfei Dong
Cc: Mauro Carvalho Chehab, Matthias Brugger,
AngeloGioacchino Del Regno, Hans Verkuil, linux-media,
linux-mediatek, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 569 bytes --]
Hi,
Le lundi 27 octobre 2025 à 14:37 +0100, Johan Hovold a écrit :
> On Wed, Sep 24, 2025 at 03:35:49PM +0200, Johan Hovold wrote:
> > This series fixes VPU device leaks during probe of the mdp and two codec
> > drivers.
> >
> > Included is also a minor documentation update to make it clear that the
> > VPU lookup helper returns the device with an incremented refcount.
>
> Can these be picked up for 6.19?
They are picked already, please check in the tree,
https://gitlab.freedesktop.org/linux-media/media-committers/-/commits/next
Nicolas
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/3] media: mediatek: fix VPU device leaks on probe
2025-10-27 19:29 ` Nicolas Dufresne
@ 2025-10-28 8:21 ` Johan Hovold
2025-10-28 9:32 ` Johan Hovold
0 siblings, 1 reply; 9+ messages in thread
From: Johan Hovold @ 2025-10-28 8:21 UTC (permalink / raw)
To: Nicolas Dufresne
Cc: Minghsiu Tsai, Houlong Wei, Andrew-CT Chen, Tiffany Lin,
Yunfei Dong, Mauro Carvalho Chehab, Matthias Brugger,
AngeloGioacchino Del Regno, Hans Verkuil, linux-media,
linux-mediatek, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1205 bytes --]
On Mon, Oct 27, 2025 at 07:29:39PM +0000, Nicolas Dufresne wrote:
> Le lundi 27 octobre 2025 à 14:37 +0100, Johan Hovold a écrit :
> > On Wed, Sep 24, 2025 at 03:35:49PM +0200, Johan Hovold wrote:
> > > This series fixes VPU device leaks during probe of the mdp and two codec
> > > drivers.
> > >
> > > Included is also a minor documentation update to make it clear that the
> > > VPU lookup helper returns the device with an incremented refcount.
> >
> > Can these be picked up for 6.19?
>
> They are picked already, please check in the tree,
>
> https://gitlab.freedesktop.org/linux-media/media-committers/-/commits/next
I can't seem to find them in that branch either, and they are not in
linux-next.
(I seem to have trimmed my original message too much so that the patch
summaries were not included in my reminder. Perhaps you are thinking of
the related mtk-mdp3 fix?)
But I do see an incomplete attempt at a fix of the reference leak in
that branch by someone else in commit cdd0f118ef87 ("media: mediatek:
vcodec: Fix a reference leak in mtk_vcodec_fw_vpu_init()")
Can that commit be dropped in favour of this series or shall I rebase on
top of it?
Johan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH 0/3] media: mediatek: fix VPU device leaks on probe
2025-10-28 8:21 ` Johan Hovold
@ 2025-10-28 9:32 ` Johan Hovold
0 siblings, 0 replies; 9+ messages in thread
From: Johan Hovold @ 2025-10-28 9:32 UTC (permalink / raw)
To: Nicolas Dufresne
Cc: Minghsiu Tsai, Houlong Wei, Andrew-CT Chen, Tiffany Lin,
Yunfei Dong, Mauro Carvalho Chehab, Matthias Brugger,
AngeloGioacchino Del Regno, Hans Verkuil, linux-media,
linux-mediatek, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1404 bytes --]
On Tue, Oct 28, 2025 at 09:21:24AM +0100, Johan Hovold wrote:
> On Mon, Oct 27, 2025 at 07:29:39PM +0000, Nicolas Dufresne wrote:
> > Le lundi 27 octobre 2025 à 14:37 +0100, Johan Hovold a écrit :
> > > On Wed, Sep 24, 2025 at 03:35:49PM +0200, Johan Hovold wrote:
> > > > This series fixes VPU device leaks during probe of the mdp and two codec
> > > > drivers.
> > > >
> > > > Included is also a minor documentation update to make it clear that the
> > > > VPU lookup helper returns the device with an incremented refcount.
> > >
> > > Can these be picked up for 6.19?
> >
> > They are picked already, please check in the tree,
> >
> > https://gitlab.freedesktop.org/linux-media/media-committers/-/commits/next
>
> I can't seem to find them in that branch either, and they are not in
> linux-next.
>
> (I seem to have trimmed my original message too much so that the patch
> summaries were not included in my reminder. Perhaps you are thinking of
> the related mtk-mdp3 fix?)
>
> But I do see an incomplete attempt at a fix of the reference leak in
> that branch by someone else in commit cdd0f118ef87 ("media: mediatek:
> vcodec: Fix a reference leak in mtk_vcodec_fw_vpu_init()")
>
> Can that commit be dropped in favour of this series or shall I rebase on
> top of it?
Scratch that. The merged commit is correct. I'll respin this series on
top.
Johan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread