d5c573c75ca5e51bd5cbab4e29a31f1f442edcc8
[openwrt/openwrt.git] / target / linux / pistachio / patches-5.4 / 150-pwm-img-Fix-null-pointer-access-in-probe.patch
1 From 502396fe598126ffd91f962d53a507aa6c7276fc Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 15 Aug 2020 16:37:43 +0200
4 Subject: [PATCH v2] pwm: img: Fix null pointer access in probe
5
6 dev_get_drvdata() is called in img_pwm_runtime_resume() before the
7 driver data is set.
8 When pm_runtime_enabled() returns false in img_pwm_probe() it calls
9 img_pwm_runtime_resume() which results in a null pointer access.
10
11 This patch fixes the problem by setting the driver data earlier in the
12 img_pwm_probe() function.
13
14 This crash was seen when booting the Imagination Technologies Creator
15 Ci40 (Marduk) with kernel 5.4 in OpenWrt.
16
17 Fixes: e690ae526216 ("pwm: img: Add runtime PM")
18 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
19 Acked-by: Lee Jones <lee.jones@linaro.org>
20 ---
21 drivers/pwm/pwm-img.c | 3 ++-
22 1 file changed, 2 insertions(+), 1 deletion(-)
23
24 --- a/drivers/pwm/pwm-img.c
25 +++ b/drivers/pwm/pwm-img.c
26 @@ -277,6 +277,8 @@ static int img_pwm_probe(struct platform
27 return PTR_ERR(pwm->pwm_clk);
28 }
29
30 + platform_set_drvdata(pdev, pwm);
31 +
32 pm_runtime_set_autosuspend_delay(&pdev->dev, IMG_PWM_PM_TIMEOUT);
33 pm_runtime_use_autosuspend(&pdev->dev);
34 pm_runtime_enable(&pdev->dev);
35 @@ -313,7 +315,6 @@ static int img_pwm_probe(struct platform
36 goto err_suspend;
37 }
38
39 - platform_set_drvdata(pdev, pwm);
40 return 0;
41
42 err_suspend: