From: Johan Hovold <johan@kernel.org>
To: Minghsiu Tsai <minghsiu.tsai@mediatek.com>,
Houlong Wei <houlong.wei@mediatek.com>,
Andrew-CT Chen <andrew-ct.chen@mediatek.com>,
Tiffany Lin <tiffany.lin@mediatek.com>,
Yunfei Dong <yunfei.dong@mediatek.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Hans Verkuil <hans.verkuil@cisco.com>,
linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org,
linux-kernel@vger.kernel.org, Johan Hovold <johan@kernel.org>,
stable@vger.kernel.org
Subject: [PATCH 1/3] media: mediatek: vcodec: fix device leak on codec init
Date: Wed, 24 Sep 2025 15:35:50 +0200 [thread overview]
Message-ID: <20250924133552.28841-2-johan@kernel.org> (raw)
In-Reply-To: <20250924133552.28841-1-johan@kernel.org>
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
next prev parent reply other threads:[~2025-09-24 13:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2025-09-24 13:35 ` [PATCH 2/3] media: mediatek: mdp: fix device leak " Johan Hovold
2025-09-24 13:35 ` [PATCH 3/3] media: mediatek: amend vpu_get_plat_device() documentation 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
2025-10-27 19:29 ` Nicolas Dufresne
2025-10-28 8:21 ` Johan Hovold
2025-10-28 9:32 ` Johan Hovold
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250924133552.28841-2-johan@kernel.org \
--to=johan@kernel.org \
--cc=andrew-ct.chen@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=hans.verkuil@cisco.com \
--cc=houlong.wei@mediatek.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=mchehab@kernel.org \
--cc=minghsiu.tsai@mediatek.com \
--cc=stable@vger.kernel.org \
--cc=tiffany.lin@mediatek.com \
--cc=yunfei.dong@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.