Skip to content

Commit 926d002

Browse files
jhovoldChun-Kuang Hu
authored andcommitted
drm/mediatek: Fix device use-after-free on unbind
A recent change fixed device reference leaks when looking up drm platform device driver data during bind() but failed to remove a partial fix which had been added by commit 80805b6 ("drm/mediatek: Fix kobject put for component sub-drivers"). This results in a reference imbalance on component bind() failures and on unbind() which could lead to a user-after-free. Make sure to only drop the references after retrieving the driver data by effectively reverting the previous partial fix. Note that holding a reference to a device does not prevent its driver data from going away so there is no point in keeping the reference. Fixes: 1f40369 ("drm/mediatek: Fix device/node reference count leaks in mtk_drm_get_all_drm_priv") Reported-by: Sjoerd Simons <[email protected]> Closes: https://lore.kernel.org/r/[email protected] Cc: [email protected] Cc: Ma Ke <[email protected]> Cc: AngeloGioacchino Del Regno <[email protected]> Signed-off-by: Johan Hovold <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: Sjoerd Simons <[email protected]> Tested-by: Sjoerd Simons <[email protected]> Tested-by: Ritesh Raj Sarraf <[email protected]> Reviewed-by: CK Hu <[email protected]> Link: https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/ Signed-off-by: Chun-Kuang Hu <[email protected]>
1 parent 3a86608 commit 926d002

File tree

1 file changed

+0
-10
lines changed

1 file changed

+0
-10
lines changed

drivers/gpu/drm/mediatek/mtk_drm_drv.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -686,29 +686,19 @@ static int mtk_drm_bind(struct device *dev)
686686
for (i = 0; i < private->data->mmsys_dev_num; i++)
687687
private->all_drm_private[i]->drm = NULL;
688688
err_put_dev:
689-
for (i = 0; i < private->data->mmsys_dev_num; i++) {
690-
/* For device_find_child in mtk_drm_get_all_priv() */
691-
put_device(private->all_drm_private[i]->dev);
692-
}
693689
put_device(private->mutex_dev);
694690
return ret;
695691
}
696692

697693
static void mtk_drm_unbind(struct device *dev)
698694
{
699695
struct mtk_drm_private *private = dev_get_drvdata(dev);
700-
int i;
701696

702697
/* for multi mmsys dev, unregister drm dev in mmsys master */
703698
if (private->drm_master) {
704699
drm_dev_unregister(private->drm);
705700
mtk_drm_kms_deinit(private->drm);
706701
drm_dev_put(private->drm);
707-
708-
for (i = 0; i < private->data->mmsys_dev_num; i++) {
709-
/* For device_find_child in mtk_drm_get_all_priv() */
710-
put_device(private->all_drm_private[i]->dev);
711-
}
712702
put_device(private->mutex_dev);
713703
}
714704
private->mtk_drm_bound = false;

0 commit comments

Comments
 (0)