From c789d0fb8a193aadefb6d9eb471ae00311080ebe Mon Sep 17 00:00:00 2001 From: Abhijit Kulkarni Date: Thu, 7 May 2020 19:21:19 -0700 Subject: [PATCH] disp: msm: check if kms is instantiated This defensive check is now required since the allocation of driver private data has moved from bind to probe phase. There is a chance that device shutdown can be called before bind phase and this can cause invalid memory access. Change-Id: I2d471a4aff93ae03291e19f6f902f1e5c28dc50f Signed-off-by: Abhijit Kulkarni --- msm/msm_drv.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/msm/msm_drv.c b/msm/msm_drv.c index a59fbdcb75ab..5e725f481f05 100644 --- a/msm/msm_drv.c +++ b/msm/msm_drv.c @@ -970,7 +970,10 @@ static void msm_postclose(struct drm_device *dev, struct drm_file *file) struct msm_file_private *ctx = file->driver_priv; struct msm_kms *kms = priv->kms; - if (kms && kms->funcs && kms->funcs->postclose) + if (!kms) + return; + + if (kms->funcs && kms->funcs->postclose) kms->funcs->postclose(kms, file); mutex_lock(&dev->struct_mutex); @@ -994,11 +997,14 @@ static void msm_lastclose(struct drm_device *dev) struct msm_kms *kms = priv->kms; int i, rc; + if (!kms) + return; + /* check for splash status before triggering cleanup * if we end up here with splash status ON i.e before first * commit then ignore the last close call */ - if (kms && kms->funcs && kms->funcs->check_for_splash + if (kms->funcs && kms->funcs->check_for_splash && kms->funcs->check_for_splash(kms)) return; @@ -1026,7 +1032,7 @@ static void msm_lastclose(struct drm_device *dev) DRM_ERROR("client modeset commit failed: %d\n", rc); } - if (kms && kms->funcs && kms->funcs->lastclose) + if (kms->funcs && kms->funcs->lastclose) kms->funcs->lastclose(kms); }