Skip to content

Commit 0fe9a58

Browse files
AngeloGioacchino Del Regnogregkh
authored andcommitted
drm/mediatek: mtk_hdmi: Unregister audio platform device on failure
[ Upstream commit 0be123c ] The probe function of this driver may fail after registering the audio platform device: in that case, the state is not getting cleaned up, leaving this device registered. Adding up to the mix, should the probe function of this driver return a probe deferral for N times, we're registering up to N audio platform devices and, again, never freeing them up. To fix this, add a pointer to the audio platform device in the mtk_hdmi structure, and add a devm action to unregister it upon driver removal or probe failure. Fixes: 8f83f26 ("drm/mediatek: Add HDMI support") Reviewed-by: CK Hu <ck.hu@mediatek.com> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Link: https://patchwork.kernel.org/project/linux-mediatek/patch/20250217154836.108895-18-angelogioacchino.delregno@collabora.com/ Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 372e387 commit 0fe9a58

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

drivers/gpu/drm/mediatek/mtk_hdmi.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ struct mtk_hdmi {
173173
unsigned int sys_offset;
174174
void __iomem *regs;
175175
enum hdmi_colorspace csp;
176+
struct platform_device *audio_pdev;
176177
struct hdmi_audio_param aud_param;
177178
bool audio_enable;
178179
bool powered;
@@ -1663,6 +1664,11 @@ static const struct hdmi_codec_ops mtk_hdmi_audio_codec_ops = {
16631664
.no_capture_mute = 1,
16641665
};
16651666

1667+
static void mtk_hdmi_unregister_audio_driver(void *data)
1668+
{
1669+
platform_device_unregister(data);
1670+
}
1671+
16661672
static int mtk_hdmi_register_audio_driver(struct device *dev)
16671673
{
16681674
struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
@@ -1672,13 +1678,20 @@ static int mtk_hdmi_register_audio_driver(struct device *dev)
16721678
.i2s = 1,
16731679
.data = hdmi,
16741680
};
1675-
struct platform_device *pdev;
1681+
int ret;
16761682

1677-
pdev = platform_device_register_data(dev, HDMI_CODEC_DRV_NAME,
1678-
PLATFORM_DEVID_AUTO, &codec_data,
1679-
sizeof(codec_data));
1680-
if (IS_ERR(pdev))
1681-
return PTR_ERR(pdev);
1683+
hdmi->audio_pdev = platform_device_register_data(dev,
1684+
HDMI_CODEC_DRV_NAME,
1685+
PLATFORM_DEVID_AUTO,
1686+
&codec_data,
1687+
sizeof(codec_data));
1688+
if (IS_ERR(hdmi->audio_pdev))
1689+
return PTR_ERR(hdmi->audio_pdev);
1690+
1691+
ret = devm_add_action_or_reset(dev, mtk_hdmi_unregister_audio_driver,
1692+
hdmi->audio_pdev);
1693+
if (ret)
1694+
return ret;
16821695

16831696
DRM_INFO("%s driver bound to HDMI\n", HDMI_CODEC_DRV_NAME);
16841697
return 0;

0 commit comments

Comments
 (0)