drm/mediatek: Fix kobject put for component sub-drivers

[ Upstream commit 80805b62ea5b95eda54c225b989f929ca0691ab0 ]

In function mtk_drm_get_all_drm_priv(), this driver is incrementing
the refcount for the sub-drivers of mediatek-drm with a call to
device_find_child() when taking a reference to all of those child
devices.

When the component bind fails multiple times this results in a
refcount_t overflow, as the reference count is never decremented:
fix that by adding a call to put_device() for all of the mmsys
devices in a loop, in error cases of mtk_drm_bind() and in the
mtk_drm_unbind() callback.

Fixes: 1ef7ed4835 ("drm/mediatek: Modify mediatek-drm for mt8195 multi mmsys support")
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://patchwork.kernel.org/project/dri-devel/patch/20250403104741.71045-3-angelogioacchino.delregno@collabora.com/
Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
AngeloGioacchino Del Regno
2025-04-03 12:47:38 +02:00
committed by Greg Kroah-Hartman
parent 8126855798
commit a2502fd0fa

View File

@@ -635,6 +635,10 @@ err_free:
for (i = 0; i < private->data->mmsys_dev_num; i++) for (i = 0; i < private->data->mmsys_dev_num; i++)
private->all_drm_private[i]->drm = NULL; private->all_drm_private[i]->drm = NULL;
err_put_dev: err_put_dev:
for (i = 0; i < private->data->mmsys_dev_num; i++) {
/* For device_find_child in mtk_drm_get_all_priv() */
put_device(private->all_drm_private[i]->dev);
}
put_device(private->mutex_dev); put_device(private->mutex_dev);
return ret; return ret;
} }
@@ -642,6 +646,7 @@ err_put_dev:
static void mtk_drm_unbind(struct device *dev) static void mtk_drm_unbind(struct device *dev)
{ {
struct mtk_drm_private *private = dev_get_drvdata(dev); struct mtk_drm_private *private = dev_get_drvdata(dev);
int i;
/* for multi mmsys dev, unregister drm dev in mmsys master */ /* for multi mmsys dev, unregister drm dev in mmsys master */
if (private->drm_master) { if (private->drm_master) {
@@ -649,6 +654,10 @@ static void mtk_drm_unbind(struct device *dev)
mtk_drm_kms_deinit(private->drm); mtk_drm_kms_deinit(private->drm);
drm_dev_put(private->drm); drm_dev_put(private->drm);
for (i = 0; i < private->data->mmsys_dev_num; i++) {
/* For device_find_child in mtk_drm_get_all_priv() */
put_device(private->all_drm_private[i]->dev);
}
put_device(private->mutex_dev); put_device(private->mutex_dev);
} }
private->mtk_drm_bound = false; private->mtk_drm_bound = false;