diff mbox series

[4/7] pistachio: Fix Null pointer access in pwm-img.c

Message ID 20200815180656.25299-4-hauke@hauke-m.de
State Accepted
Delegated to: Hauke Mehrtens
Headers show
Series [1/7] kernel: Add GigaDevice GD5F4GQ4xC SPI NAND flash | expand

Commit Message

Hauke Mehrtens Aug. 15, 2020, 6:06 p.m. UTC
This fixes a crash when booting the board.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
---
 ...img-Fix-null-pointer-access-in-probe.patch | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 target/linux/pistachio/patches-5.4/150-pwm-img-Fix-null-pointer-access-in-probe.patch
diff mbox series

Patch

diff --git a/target/linux/pistachio/patches-5.4/150-pwm-img-Fix-null-pointer-access-in-probe.patch b/target/linux/pistachio/patches-5.4/150-pwm-img-Fix-null-pointer-access-in-probe.patch
new file mode 100644
index 000000000000..3c7ccafb87eb
--- /dev/null
+++ b/target/linux/pistachio/patches-5.4/150-pwm-img-Fix-null-pointer-access-in-probe.patch
@@ -0,0 +1,46 @@ 
+From ae1d7ceaa99bd010d18537683993b23b0d9fc345 Mon Sep 17 00:00:00 2001
+From: Hauke Mehrtens <hauke@hauke-m.de>
+Date: Sat, 15 Aug 2020 16:37:43 +0200
+Subject: [PATCH] pwm: img: Fix null pointer access in probe
+
+dev_get_drvdata() is called in img_pwm_runtime_resume() before the
+driver data is set.
+When pm_runtime_enabled() returns false in img_pwm_probe() it calls
+img_pwm_runtime_resume() which results in a null pointer access.
+
+This patch fixes the problem by setting the driver data earlier in the
+img_pwm_probe() function.
+
+Fixes: e690ae526216 ("pwm: img: Add runtime PM")
+Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
+---
+ drivers/pwm/pwm-img.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+--- a/drivers/pwm/pwm-img.c
++++ b/drivers/pwm/pwm-img.c
+@@ -277,6 +277,8 @@ static int img_pwm_probe(struct platform
+ 		return PTR_ERR(pwm->pwm_clk);
+ 	}
+ 
++	platform_set_drvdata(pdev, pwm);
++
+ 	pm_runtime_set_autosuspend_delay(&pdev->dev, IMG_PWM_PM_TIMEOUT);
+ 	pm_runtime_use_autosuspend(&pdev->dev);
+ 	pm_runtime_enable(&pdev->dev);
+@@ -313,7 +315,6 @@ static int img_pwm_probe(struct platform
+ 		goto err_suspend;
+ 	}
+ 
+-	platform_set_drvdata(pdev, pwm);
+ 	return 0;
+ 
+ err_suspend:
+@@ -322,6 +323,7 @@ err_suspend:
+ err_pm_disable:
+ 	pm_runtime_disable(&pdev->dev);
+ 	pm_runtime_dont_use_autosuspend(&pdev->dev);
++	platform_set_drvdata(pdev, NULL);
+ 	return ret;
+ }
+