pwm: lpc18xx-sct: Initialize driver data and hardware before pwmchip_add()
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 10 Nov 2021 08:49:48 +0000 (09:49 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 12:23:44 +0000 (14:23 +0200)
commit6f4f778f2747c23a14bda72df6bf5a445b68fee2
tree10d6d3176c26d0dea30d82a08599741eef363c93
parent28a886a308ed5221557bcc8d812e0cf0228501a8
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: 841e6f90bb78 ("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>
drivers/pwm/pwm-lpc18xx-sct.c