drm/msm: Fix dereference of pointer minor before null check
authorColin Ian King <colin.i.king@gmail.com>
Wed, 30 Jul 2025 14:29:05 +0000 (15:29 +0100)
committerRob Clark <robin.clark@oss.qualcomm.com>
Thu, 7 Aug 2025 16:22:27 +0000 (09:22 -0700)
Currently the pointer minor is being dereferenced before it is null
checked, leading to a potential null pointer dereference issue. Fix this
by dereferencing the pointer only after it has been null checked. Also
Replace minor->dev with dev.

Fixes: 4f89cf40d01e ("drm/msm: bail out late_init_minor() if it is not a GPU device")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Patchwork: https://patchwork.freedesktop.org/patch/666259/
Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com>
drivers/gpu/drm/msm/msm_debugfs.c

index bbda865addae2e0ef5bb175bec0ed219cd0d9988..97dc70876442f9aa932677edbed5d26f6095e7ee 100644 (file)
@@ -325,25 +325,28 @@ static struct drm_info_list msm_debugfs_list[] = {
 
 static int late_init_minor(struct drm_minor *minor)
 {
-       struct drm_device *dev = minor->dev;
-       struct msm_drm_private *priv = dev->dev_private;
+       struct drm_device *dev;
+       struct msm_drm_private *priv;
        int ret;
 
        if (!minor)
                return 0;
 
+       dev = minor->dev;
+       priv = dev->dev_private;
+
        if (!priv->gpu_pdev)
                return 0;
 
        ret = msm_rd_debugfs_init(minor);
        if (ret) {
-               DRM_DEV_ERROR(minor->dev->dev, "could not install rd debugfs\n");
+               DRM_DEV_ERROR(dev->dev, "could not install rd debugfs\n");
                return ret;
        }
 
        ret = msm_perf_debugfs_init(minor);
        if (ret) {
-               DRM_DEV_ERROR(minor->dev->dev, "could not install perf debugfs\n");
+               DRM_DEV_ERROR(dev->dev, "could not install perf debugfs\n");
                return ret;
        }