media: mediatek: fix VPU device leaks on probe
Subsystems (5)
v2 cover media: mediatek: fix VPU device leaks on probe
This series fixes VPU device leaks during probe of the mdp driver.
Included is also a minor documentation update to make it clear that the VPU lookup helper returns the device with an incremented refcount.
Johan
Changes in v2
- drop incorrect vcodec patch since that reference leak has already been fixed by commit bf1d556ad4e0 ("media: mtk-vcodec: abstract firmware interface") which added the codec release callback
Johan Hovold (2):
media: mediatek: mdp: fix device leak on probe
media: mediatek: amend vpu_get_plat_device() documentation
drivers/media/platform/mediatek/mdp/mtk_mdp_core.c | 7 +++++-- drivers/media/platform/mediatek/vpu/mtk_vpu.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-)
Signature · 1 line
2.51.0
PATCH v2 1/2 media: mediatek: mdp: fix device leak on probe
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.
--- drivers/media/platform/mediatek/mdp/mtk_mdp_core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/media/platform/mediatek/mdp/mtk_mdp_core.c +5 -2
@@ -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);
Signature · 1 line
2.51.0
PATCH v2 2/2 media: mediatek: amend vpu_get_plat_device() documentation
In reply to Johan HovoldAdd 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).
--- drivers/media/platform/mediatek/vpu/mtk_vpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/mediatek/vpu/mtk_vpu.h +1 -1
@@ -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);
Signature · 1 line
2.51.0
Quoted 14 lines · Johan Hovold
This series fixes VPU device leaks during probe of the mdp driver.
Included is also a minor documentation update to make it clear that the VPU lookup helper returns the device with an incremented refcount.
Johan
Changes in v2
- drop incorrect vcodec patch since that reference leak has already been fixed by commitbf1d556ad4e0("media: mtk-vcodec: abstract firmware interface") which added the codec release callback
Quoted 3 lines
Johan Hovold (2):
media: mediatek: mdp: fix device leak on probe
media: mediatek: amendvpu_get_plat_device()documentation
Looks like I forgot to add Chen-Yu's reviewed-by when respinning:
Il 28/10/25 11:04, Johan Hovold ha scritto:
Quoted 14 lines
This series fixes VPU device leaks during probe of the mdp driver.
Included is also a minor documentation update to make it clear that the VPU lookup helper returns the device with an incremented refcount.
Johan
Changes in v2
- drop incorrect vcodec patch since that reference leak has already been fixed by commitbf1d556ad4e0("media: mtk-vcodec: abstract firmware interface") which added the codec release callback
Quoted 8 lines
Johan Hovold (2):
media: mediatek: mdp: fix device leak on probe
media: mediatek: amendvpu_get_plat_device()documentationdrivers/media/platform/mediatek/mdp/mtk_mdp_core.c | 7 +++++-- drivers/media/platform/mediatek/vpu/mtk_vpu.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-)
While series is
Quoted 11 lines · Johan Hovold
This series fixes VPU device leaks during probe of the mdp driver.
Included is also a minor documentation update to make it clear that the VPU lookup helper returns the device with an incremented refcount.
Changes in v2
- drop incorrect vcodec patch since that reference leak has already been fixed by commitbf1d556ad4e0("media: mtk-vcodec: abstract firmware interface") which added the codec release callback
Quoted 3 lines
Johan Hovold (2):
media: mediatek: mdp: fix device leak on probe
media: mediatek: amendvpu_get_plat_device()documentation
Can these be picked up for 6.19?
Johan
Re: [PATCH v2 2/2] media: mediatek: amend vpu_get_plat_device() documentation
In reply to Johan HovoldHi,
Le mardi 28 octobre 2025 à 11:04 +0100, Johan Hovold a écrit :
Quoted 14 lines
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 <[email protected]>---
drivers/media/platform/mediatek/vpu/mtk_vpu.h | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/platform/mediatek/vpu/mtk_vpu.h +0
-0
drivers/media/platform/mediatek/vpu/mtk_vpu.h int vpu_ipi_send(struct platform_device *pdev, · line 123
Quoted 5 lines
drivers/media/platform/mediatek/vpu/mtk_vpu.h +1
-1@@ -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
I picked this patch but rewrote with what felt like better and dense.
- * Return: Return NULL if it is failed.
- * otherwise it is VPU's platform device
+ * Return: a reference to the VPU's platform device, or NULL on failure.
hope its ok with you,
cheers,
Nicolas
Quoted 3 lines
drivers/media/platform/mediatek/vpu/mtk_vpu.h +0
-0**/ struct platform_device *vpu_get_plat_device(struct platform_device *pdev);
Re: [PATCH v2 2/2] media: mediatek: amend vpu_get_plat_device() documentation
Quoted 25 lines · Nicolas Dufresne
Hi,
Le mardi 28 octobre 2025 à 11:04 +0100, Johan Hovold a écrit :
Quoted 14 lines
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 <[email protected]>---
drivers/media/platform/mediatek/vpu/mtk_vpu.h | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/platform/mediatek/vpu/mtk_vpu.h +0
-0drivers/media/platform/mediatek/vpu/mtk_vpu.h int vpu_ipi_send(struct platform_device *pdev, · line 123
Quoted 5 lines
drivers/media/platform/mediatek/vpu/mtk_vpu.h +1
-1@@ -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 countI picked this patch but rewrote with what felt like better and dense.
Quoted 5 lines
- * Return: Return NULL if it is failed.
- * otherwise it is VPU's platform device
+ * Return: a reference to the VPU's platform device, or NULL on failure.hope its ok with you,
Sure, my only concern is that just saying "reference" is too subtle, that's why I explicitly mentioned the refcount.
Btw, why is patch 2/2 marked obsolete? That leak is still there both on probe errors (which I saw someone else posted a fix for) and on driver unbind.
Johan
Re: [PATCH v2 2/2] media: mediatek: amend vpu_get_plat_device() documentation
Le mercredi 10 décembre 2025 à 12:21 +0900, Johan Hovold a écrit :
Quoted 27 lines · Nicolas Dufresne
Quoted 26 lines
Hi,
Le mardi 28 octobre 2025 à 11:04 +0100, Johan Hovold a écrit :
Quoted 15 lines
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 <[email protected]>---
drivers/media/platform/mediatek/vpu/mtk_vpu.h | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/platform/mediatek/vpu/mtk_vpu.h +0
-0drivers/media/platform/mediatek/vpu/mtk_vpu.h int vpu_ipi_send(struct platform_device *pdev, · line 123
Quoted 5 lines
drivers/media/platform/mediatek/vpu/mtk_vpu.h +1
-1@@ -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 countI picked this patch but rewrote with what felt like better and dense.
Quoted 8 lines
Quoted 5 lines
- * Return: Return NULL if it is failed.
- * otherwise it is VPU's platform device
+ * Return: a reference to the VPU's platform device, or NULL on failure.hope its ok with you,
Sure, my only concern is that just saying "reference" is too subtle, that's why I explicitly mentioned the refcount.
For me everyone should read "a reference" as a kref based reference counted structure. A quick grep across out documentation, this is the vast majority of the wording. Though, I spent limited time looking.
Quoted 4 lines
Btw, why is patch 2/2 marked obsolete? That leak is still there both on probe errors (which I saw someone else posted a fix for) and on driver unbind.
I had two patches fixing the same thing, it just happen that I ended up picking the other one first, and liked you documentation fix, except it was replicating obvious weird english such as "if it is failed", and documenting the error before the expected outcome (opposite of my preference, not sure there is any rules or guidelines).
https://lore.kernel.org/all/[email protected]/
cheers,
Nicolas
Quoted 2 lines
Johan
Re: [PATCH v2 2/2] media: mediatek: amend vpu_get_plat_device() documentation
Quoted 21 lines · Nicolas Dufresne
Le mercredi 10 décembre 2025 à 12:21 +0900, Johan Hovold a écrit :
Quoted 20 lines · Nicolas Dufresne
Quoted 19 lines
Le mardi 28 octobre 2025 à 11:04 +0100, Johan Hovold a écrit :
drivers/media/platform/mediatek/vpu/mtk_vpu.h int vpu_ipi_send(struct platform_device *pdev, · line 123
Quoted 10 lines
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).drivers/media/platform/mediatek/vpu/mtk_vpu.h +1
-1@@ -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 countI picked this patch but rewrote with what felt like better and dense.
- * Return: Return NULL if it is failed.
- * otherwise it is VPU's platform device
+ * Return: a reference to the VPU's platform device, or NULL on failure.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
hope its ok with you,
Sure, my only concern is that just saying "reference" is too subtle, that's why I explicitly mentioned the refcount.
For me everyone should read "a reference" as a kref based reference counted structure. A quick grep across out documentation, this is the vast majority of the wording. Though, I spent limited time looking.
It should be sufficient but given how many people miss this it may still be worth being more explicit.
Quoted 6 lines
Quoted 3 lines
Btw, why is patch 2/2 marked obsolete? That leak is still there both on probe errors (which I saw someone else posted a fix for) and on driver unbind.
I had two patches fixing the same thing, it just happen that I ended up picking the other one first
Ah, I had missed that and the fix is not in linux-next yet either so without a reply it wasn't obvious.
Quoted 4 lines
and liked you documentation fix, except it was replicating obvious weird english such as "if it is failed", and documenting the error before the expected outcome (opposite of my preference, not sure there is any rules or guidelines).
Yeah, I considered rewriting the whole comment too but given that the surrounding comments used similar language I just amended what was there.
But I'm totally fine with the update you did.
Quoted 1 line
Johan