Skip to content

Commit 2291859

Browse files
AngeloGioacchino Del RegnoChun-Kuang Hu
authored andcommitted
drm/mediatek: mtk_drm_drv: Fix kobject put for mtk_mutex device ptr
This driver is taking a kobject for mtk_mutex only once per mmsys device for each drm-mediatek driver instance, differently from the behavior with other components, but it is decrementing the kobj's refcount in a loop and once per mmsys: this is not right and will result in a refcount_t underflow warning when mediatek-drm returns multiple probe deferrals in one boot (or when manually bound and unbound). Besides that, the refcount for mutex_dev was not decremented for error cases in mtk_drm_bind(), causing another refcount_t warning but this time for overflow, when the failure happens not during driver bind but during component bind. In order to fix one of the reasons why this is happening, remove the put_device(xx->mutex_dev) loop from the mtk_drm_kms_init()'s put_mutex_dev label (and drop the label) and add a single call to correctly free the single incremented refcount of mutex_dev to the mtk_drm_unbind() function to fix the refcount_t underflow. Moreover, add the same call to the error cases in mtk_drm_bind() to fix the refcount_t overflow. Fixes: 1ef7ed4 ("drm/mediatek: Modify mediatek-drm for mt8195 multi mmsys support") Reviewed-by: Chen-Yu Tsai <[email protected]> Signed-off-by: AngeloGioacchino Del Regno <[email protected]> Link: https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/ Signed-off-by: Chun-Kuang Hu <[email protected]>
1 parent 587f6ac commit 2291859

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/gpu/drm/mediatek/mtk_drm_drv.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ static int mtk_drm_kms_init(struct drm_device *drm)
470470

471471
ret = drmm_mode_config_init(drm);
472472
if (ret)
473-
goto put_mutex_dev;
473+
return ret;
474474

475475
drm->mode_config.min_width = 64;
476476
drm->mode_config.min_height = 64;
@@ -489,7 +489,7 @@ static int mtk_drm_kms_init(struct drm_device *drm)
489489
drm->dev_private = private->all_drm_private[i];
490490
ret = component_bind_all(private->all_drm_private[i]->dev, drm);
491491
if (ret)
492-
goto put_mutex_dev;
492+
return ret;
493493
}
494494

495495
/*
@@ -582,9 +582,6 @@ static int mtk_drm_kms_init(struct drm_device *drm)
582582
err_component_unbind:
583583
for (i = 0; i < private->data->mmsys_dev_num; i++)
584584
component_unbind_all(private->all_drm_private[i]->dev, drm);
585-
put_mutex_dev:
586-
for (i = 0; i < private->data->mmsys_dev_num; i++)
587-
put_device(private->all_drm_private[i]->mutex_dev);
588585

589586
return ret;
590587
}
@@ -655,8 +652,10 @@ static int mtk_drm_bind(struct device *dev)
655652
return 0;
656653

657654
drm = drm_dev_alloc(&mtk_drm_driver, dev);
658-
if (IS_ERR(drm))
659-
return PTR_ERR(drm);
655+
if (IS_ERR(drm)) {
656+
ret = PTR_ERR(drm);
657+
goto err_put_dev;
658+
}
660659

661660
private->drm_master = true;
662661
drm->dev_private = private;
@@ -682,6 +681,8 @@ static int mtk_drm_bind(struct device *dev)
682681
drm_dev_put(drm);
683682
for (i = 0; i < private->data->mmsys_dev_num; i++)
684683
private->all_drm_private[i]->drm = NULL;
684+
err_put_dev:
685+
put_device(private->mutex_dev);
685686
return ret;
686687
}
687688

@@ -694,6 +695,8 @@ static void mtk_drm_unbind(struct device *dev)
694695
drm_dev_unregister(private->drm);
695696
mtk_drm_kms_deinit(private->drm);
696697
drm_dev_put(private->drm);
698+
699+
put_device(private->mutex_dev);
697700
}
698701
private->mtk_drm_bound = false;
699702
private->drm_master = false;

0 commit comments

Comments
 (0)