9c7527
From patchwork Wed Feb 24 17:34:43 2016
9c7527
Content-Type: text/plain; charset="utf-8"
9c7527
MIME-Version: 1.0
9c7527
Content-Transfer-Encoding: 7bit
9c7527
Subject: drm/nouveau: platform: Fix deferred probe
9c7527
From: Thierry Reding <thierry.reding@gmail.com>
9c7527
X-Patchwork-Id: 587554
9c7527
Message-Id: <1456335283-22097-1-git-send-email-thierry.reding@gmail.com>
9c7527
To: Ben Skeggs <bskeggs@redhat.com>
9c7527
Cc: Alexandre Courbot <gnurou@gmail.com>, Nicolas Chauvet <kwizart@gmail.com>,
9c7527
 dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org
9c7527
Date: Wed, 24 Feb 2016 18:34:43 +0100
9c7527
9c7527
From: Thierry Reding <treding@nvidia.com>
9c7527
9c7527
The error cleanup paths aren't quite correct and will crash upon
9c7527
deferred probe.
9c7527
9c7527
Cc: stable@vger.kernel.org # v4.3+
9c7527
Signed-off-by: Thierry Reding <treding@nvidia.com>
9c7527
Reviewed-by: Ben Skeggs <bskeggs@redhat.com>
9c7527
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
9c7527
---
9c7527
 drivers/gpu/drm/nouveau/nouveau_platform.c         |  2 +-
9c7527
 drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c | 40 ++++++++++++++++------
9c7527
 2 files changed, 30 insertions(+), 12 deletions(-)
9c7527
9c7527
diff --git a/drivers/gpu/drm/nouveau/nouveau_platform.c b/drivers/gpu/drm/nouveau/nouveau_platform.c
9c7527
index 8a70cec59bcd..2dfe58af12e4 100644
9c7527
--- a/drivers/gpu/drm/nouveau/nouveau_platform.c
9c7527
+++ b/drivers/gpu/drm/nouveau/nouveau_platform.c
9c7527
@@ -24,7 +24,7 @@
9c7527
 static int nouveau_platform_probe(struct platform_device *pdev)
9c7527
 {
9c7527
 	const struct nvkm_device_tegra_func *func;
9c7527
-	struct nvkm_device *device;
9c7527
+	struct nvkm_device *device = NULL;
9c7527
 	struct drm_device *drm;
9c7527
 	int ret;
9c7527
 
9c7527
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c
9c7527
index 7f8a42721eb2..e7e581d6a8ff 100644
9c7527
--- a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c
9c7527
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c
9c7527
@@ -252,32 +252,40 @@ nvkm_device_tegra_new(const struct nvkm_device_tegra_func *func,
9c7527
 
9c7527
 	if (!(tdev = kzalloc(sizeof(*tdev), GFP_KERNEL)))
9c7527
 		return -ENOMEM;
9c7527
-	*pdevice = &tdev->device;
9c7527
+
9c7527
 	tdev->func = func;
9c7527
 	tdev->pdev = pdev;
9c7527
 	tdev->irq = -1;
9c7527
 
9c7527
 	tdev->vdd = devm_regulator_get(&pdev->dev, "vdd");
9c7527
-	if (IS_ERR(tdev->vdd))
9c7527
-		return PTR_ERR(tdev->vdd);
9c7527
+	if (IS_ERR(tdev->vdd)) {
9c7527
+		ret = PTR_ERR(tdev->vdd);
9c7527
+		goto free;
9c7527
+	}
9c7527
 
9c7527
 	tdev->rst = devm_reset_control_get(&pdev->dev, "gpu");
9c7527
-	if (IS_ERR(tdev->rst))
9c7527
-		return PTR_ERR(tdev->rst);
9c7527
+	if (IS_ERR(tdev->rst)) {
9c7527
+		ret = PTR_ERR(tdev->rst);
9c7527
+		goto free;
9c7527
+	}
9c7527
 
9c7527
 	tdev->clk = devm_clk_get(&pdev->dev, "gpu");
9c7527
-	if (IS_ERR(tdev->clk))
9c7527
-		return PTR_ERR(tdev->clk);
9c7527
+	if (IS_ERR(tdev->clk)) {
9c7527
+		ret = PTR_ERR(tdev->clk);
9c7527
+		goto free;
9c7527
+	}
9c7527
 
9c7527
 	tdev->clk_pwr = devm_clk_get(&pdev->dev, "pwr");
9c7527
-	if (IS_ERR(tdev->clk_pwr))
9c7527
-		return PTR_ERR(tdev->clk_pwr);
9c7527
+	if (IS_ERR(tdev->clk_pwr)) {
9c7527
+		ret = PTR_ERR(tdev->clk_pwr);
9c7527
+		goto free;
9c7527
+	}
9c7527
 
9c7527
 	nvkm_device_tegra_probe_iommu(tdev);
9c7527
 
9c7527
 	ret = nvkm_device_tegra_power_up(tdev);
9c7527
 	if (ret)
9c7527
-		return ret;
9c7527
+		goto remove;
9c7527
 
9c7527
 	tdev->gpu_speedo = tegra_sku_info.gpu_speedo_value;
9c7527
 	ret = nvkm_device_ctor(&nvkm_device_tegra_func, NULL, &pdev->dev,
9c7527
@@ -285,9 +293,19 @@ nvkm_device_tegra_new(const struct nvkm_device_tegra_func *func,
9c7527
 			       cfg, dbg, detect, mmio, subdev_mask,
9c7527
 			       &tdev->device);
9c7527
 	if (ret)
9c7527
-		return ret;
9c7527
+		goto powerdown;
9c7527
+
9c7527
+	*pdevice = &tdev->device;
9c7527
 
9c7527
 	return 0;
9c7527
+
9c7527
+powerdown:
9c7527
+	nvkm_device_tegra_power_down(tdev);
9c7527
+remove:
9c7527
+	nvkm_device_tegra_remove_iommu(tdev);
9c7527
+free:
9c7527
+	kfree(tdev);
9c7527
+	return ret;
9c7527
 }
9c7527
 #else
9c7527
 int