Skip to contentSkip to conversation

drm/amdgpu: avoid NULL deref in isp_genpd_remove_device

PATCH In review Bin Du 2 participants 2 messages Sep 7 – Sep 8

Subsystems (2)
lore
Share & tools
lore

Bin Du

author
#0 lore raw

PATCH 1/1 drm/amdgpu: avoid NULL deref in isp_genpd_remove_device

hw_fini passes NULL as device_for_each_child() data, but the callback derived adev from that pointer for logging and oopsed on unbind. Drop the unused genpd lookup, log against the child device, keep walking on remove failure, and only clear syscore after a successful detach.

Fixes fd1478607102 ("drm/amd/amdgpu: Add ISP Generic PM Domain (genpd) support")
---
 drivers/gpu/drm/amd/amdgpu/isp_v4_1_1.c | 28 ++++++-------------------
 1 file changed, 6 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/isp_v4_1_1.c +6 -22
index 485ecdec9618..26dbfe2d2739 100644
@@ -156,35 +156,19 @@ static int isp_genpd_add_device(struct device *dev, void *data)
 
 static int isp_genpd_remove_device(struct device *dev, void *data)
 {
-	struct generic_pm_domain *gpd = data;
-	struct platform_device *pdev = container_of(dev, struct platform_device, dev);
-	struct amdgpu_isp *isp = container_of(gpd, struct amdgpu_isp, ispgpd);
-	struct amdgpu_device *adev = isp->adev;
 	int ret;
 
-	if (!pdev)
-		return -EINVAL;
-
-	if (!dev->type || !dev->type->name) {
-		drm_dbg(&adev->ddev, "Invalid device type to remove\n");
-		goto exit;
-	}
-
-	if (strcmp(dev->type->name, "mfd_device")) {
-		drm_dbg(&adev->ddev, "Invalid isp mfd device %s to remove\n",
-			pdev->mfd_cell->name);
-		goto exit;
-	}
+	if (!dev->type || !dev->type->name ||
+	    strcmp(dev->type->name, "mfd_device"))
+		return 0;
 
 	ret = pm_genpd_remove_device(dev);
 	if (ret) {
-		drm_err(&adev->ddev, "Failed to remove dev from genpd %d\n", ret);
-		return -ENODEV;
+		dev_err(dev, "Failed to remove dev from genpd %d\n", ret);
+		return 0;
 	}
-	dev_pm_syscore_device(dev, false);
 
-exit:
-	/* Continue to remove */
+	dev_pm_syscore_device(dev, false);
 	return 0;
 }
 
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Bin Du

hw_fini passes NULL as device_for_each_child() data, but the callback derived adev from that pointer for logging and oopsed on unbind. Drop the unused genpd lookup, log against the child device, keep walking on remove failure, and only clear syscore after a successful detach.

Fixes fd1478607102 ("drm/amd/amdgpu: Add ISP Generic PM Domain (genpd) support")
Quoted 49 lines
  drivers/gpu/drm/amd/amdgpu/isp_v4_1_1.c | 28 ++++++-------------------
  1 file changed, 6 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/isp_v4_1_1.c +6 -22
index 485ecdec9618..26dbfe2d2739 100644
@@ -156,35 +156,19 @@ static int isp_genpd_add_device(struct device *dev, void *data)
 
  static int isp_genpd_remove_device(struct device *dev, void *data)
  {
-	struct generic_pm_domain *gpd = data;
-	struct platform_device *pdev = container_of(dev, struct platform_device, dev);
-	struct amdgpu_isp *isp = container_of(gpd, struct amdgpu_isp, ispgpd);
-	struct amdgpu_device *adev = isp->adev;
  	int ret;
 
-	if (!pdev)
-		return -EINVAL;
-
-	if (!dev->type || !dev->type->name) {
-		drm_dbg(&adev->ddev, "Invalid device type to remove\n");
-		goto exit;
-	}
-
-	if (strcmp(dev->type->name, "mfd_device")) {
-		drm_dbg(&adev->ddev, "Invalid isp mfd device %s to remove\n",
-			pdev->mfd_cell->name);
-		goto exit;
-	}
+	if (!dev->type || !dev->type->name ||
+	    strcmp(dev->type->name, "mfd_device"))
+		return 0;
 
  	ret = pm_genpd_remove_device(dev);
  	if (ret) {
-		drm_err(&adev->ddev, "Failed to remove dev from genpd %d\n", ret);
-		return -ENODEV;
+		dev_err(dev, "Failed to remove dev from genpd %d\n", ret);
+		return 0;
  	}
-	dev_pm_syscore_device(dev, false);
 
-exit:
-	/* Continue to remove */
+	dev_pm_syscore_device(dev, false);
  	return 0;
  }