Skip to contentSkip to conversation

drm/msm/a5xx: Fix dereference of pointer pdev before null check on pdev

PATCH Superseded Colin Ian King 2 participants 2 messages Nov 12, 2024

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/msm/a5xx: Fix dereference of pointer pdev before null check on pdev

The pointer config is dereferencing pointer pdev before pdev is null checked, this could lead to a potential null pointer dereference on pdev. Fix this by only assinging config after pdev has been null checked.

Fixes 736a93273656 ("drm/msm/a5xx: really check for A510 in a5xx_gpu_init")
---
 drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +2 -1
index ee89db72e36e..e83081346059 100644
@@ -1753,7 +1753,7 @@ struct msm_gpu *a5xx_gpu_init(struct drm_device *dev)
 {
 	struct msm_drm_private *priv = dev->dev_private;
 	struct platform_device *pdev = priv->gpu_pdev;
-	struct adreno_platform_config *config = pdev->dev.platform_data;
+	struct adreno_platform_config *config;
 	struct a5xx_gpu *a5xx_gpu = NULL;
 	struct adreno_gpu *adreno_gpu;
 	struct msm_gpu *gpu;
@@ -1764,6 +1764,7 @@ struct msm_gpu *a5xx_gpu_init(struct drm_device *dev)
 		DRM_DEV_ERROR(dev->dev, "No A5XX device is defined\n");
 		return ERR_PTR(-ENXIO);
 	}
+	config = pdev->dev.platform_data;
 
 	a5xx_gpu = kzalloc(sizeof(*a5xx_gpu), GFP_KERNEL);
 	if (!a5xx_gpu)
Signature · 1 line
2.39.5
#1 lore raw
Quoted 7 lines · Colin Ian King

The pointer config is dereferencing pointer pdev before pdev is null checked, this could lead to a potential null pointer dereference on pdev. Fix this by only assinging config after pdev has been null checked.

Fixes 736a93273656 ("drm/msm/a5xx: really check for A510 in a5xx_gpu_init")

---

I'd rather drop this check, the only call chain is rather safe here

Konrad