pwm: lpc18xx-sct: Initialize driver data and hardware before pwmchip_add()
[ Upstream commit 0401f24cd238ae200a23a13925f98de3d2c883b8 ]
When a driver calls pwmchip_add() it has to be prepared to immediately
get its callbacks called. So move allocation of driver data and hardware
initialization before the call to pwmchip_add().
This fixes a potential NULL pointer exception and a race condition on
register writes.
Fixes: 841e6f90bb
("pwm: NXP LPC18xx PWM/SCT driver")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
996291d068
commit
af1fdbbb7b
@ -400,12 +400,6 @@ static int lpc18xx_pwm_probe(struct platform_device *pdev)
|
|||||||
lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_LIMIT,
|
lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_LIMIT,
|
||||||
BIT(lpc18xx_pwm->period_event));
|
BIT(lpc18xx_pwm->period_event));
|
||||||
|
|
||||||
ret = pwmchip_add(&lpc18xx_pwm->chip);
|
|
||||||
if (ret < 0) {
|
|
||||||
dev_err(&pdev->dev, "pwmchip_add failed: %d\n", ret);
|
|
||||||
goto disable_pwmclk;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < lpc18xx_pwm->chip.npwm; i++) {
|
for (i = 0; i < lpc18xx_pwm->chip.npwm; i++) {
|
||||||
struct lpc18xx_pwm_data *data;
|
struct lpc18xx_pwm_data *data;
|
||||||
|
|
||||||
@ -415,14 +409,12 @@ static int lpc18xx_pwm_probe(struct platform_device *pdev)
|
|||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto remove_pwmchip;
|
goto disable_pwmclk;
|
||||||
}
|
}
|
||||||
|
|
||||||
pwm_set_chip_data(pwm, data);
|
pwm_set_chip_data(pwm, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
platform_set_drvdata(pdev, lpc18xx_pwm);
|
|
||||||
|
|
||||||
val = lpc18xx_pwm_readl(lpc18xx_pwm, LPC18XX_PWM_CTRL);
|
val = lpc18xx_pwm_readl(lpc18xx_pwm, LPC18XX_PWM_CTRL);
|
||||||
val &= ~LPC18XX_PWM_BIDIR;
|
val &= ~LPC18XX_PWM_BIDIR;
|
||||||
val &= ~LPC18XX_PWM_CTRL_HALT;
|
val &= ~LPC18XX_PWM_CTRL_HALT;
|
||||||
@ -430,10 +422,16 @@ static int lpc18xx_pwm_probe(struct platform_device *pdev)
|
|||||||
val |= LPC18XX_PWM_PRE(0);
|
val |= LPC18XX_PWM_PRE(0);
|
||||||
lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CTRL, val);
|
lpc18xx_pwm_writel(lpc18xx_pwm, LPC18XX_PWM_CTRL, val);
|
||||||
|
|
||||||
|
ret = pwmchip_add(&lpc18xx_pwm->chip);
|
||||||
|
if (ret < 0) {
|
||||||
|
dev_err(&pdev->dev, "pwmchip_add failed: %d\n", ret);
|
||||||
|
goto disable_pwmclk;
|
||||||
|
}
|
||||||
|
|
||||||
|
platform_set_drvdata(pdev, lpc18xx_pwm);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
remove_pwmchip:
|
|
||||||
pwmchip_remove(&lpc18xx_pwm->chip);
|
|
||||||
disable_pwmclk:
|
disable_pwmclk:
|
||||||
clk_disable_unprepare(lpc18xx_pwm->pwm_clk);
|
clk_disable_unprepare(lpc18xx_pwm->pwm_clk);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user