All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pwm: img: Fix null pointer access in probe
@ 2020-08-15 16:31 Hauke Mehrtens
  2020-08-19 10:39 ` Lee Jones
  2020-08-20 13:02 ` Uwe Kleine-König
  0 siblings, 2 replies; 4+ messages in thread
From: Hauke Mehrtens @ 2020-08-15 16:31 UTC (permalink / raw)
  To: thierry.reding, u.kleine-koenig, lee.jones
  Cc: ed.blake, linux-pwm, wigyori, Hauke Mehrtens

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(-)

diff --git a/drivers/pwm/pwm-img.c b/drivers/pwm/pwm-img.c
index 599a0f66a384..11831e885e1b 100644
--- a/drivers/pwm/pwm-img.c
+++ b/drivers/pwm/pwm-img.c
@@ -277,6 +277,8 @@ static int img_pwm_probe(struct platform_device *pdev)
 		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_device *pdev)
 		goto err_suspend;
 	}
 
-	platform_set_drvdata(pdev, pwm);
 	return 0;
 
 err_suspend:
@@ -322,6 +323,7 @@ static int img_pwm_probe(struct platform_device *pdev)
 err_pm_disable:
 	pm_runtime_disable(&pdev->dev);
 	pm_runtime_dont_use_autosuspend(&pdev->dev);
+	platform_set_drvdata(pdev, NULL);
 	return ret;
 }
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-08-20 16:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-15 16:31 [PATCH] pwm: img: Fix null pointer access in probe Hauke Mehrtens
2020-08-19 10:39 ` Lee Jones
2020-08-20 13:02 ` Uwe Kleine-König
2020-08-20 16:16   ` Hauke Mehrtens

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.