]> www.infradead.org Git - users/jedix/linux-maple.git/commit
pwm: atmel-tcb: Fix race condition and convert to guards
authorUwe Kleine-König <u.kleine-koenig@baylibre.com>
Tue, 9 Jul 2024 10:18:05 +0000 (12:18 +0200)
committerUwe Kleine-König <ukleinek@kernel.org>
Wed, 10 Jul 2024 15:51:04 +0000 (17:51 +0200)
commit37f7707077f5ea2515bf4b1dc7fad43f8e12993e
tree90f97bd93a52b38895a567a991fe65a0df575117
parent32207e9ddf7400a5676cb27559560cadee062577
pwm: atmel-tcb: Fix race condition and convert to guards

The hardware only supports a single period length for both PWM outputs. So
atmel_tcb_pwm_config() checks the configuration of the other output if it's
compatible with the currently requested setting. The register values are
then actually updated in atmel_tcb_pwm_enable(). To make this race free
the lock must be held during the whole process, so grab the lock in
.apply() instead of individually in atmel_tcb_pwm_disable() and
atmel_tcb_pwm_enable() which then also covers atmel_tcb_pwm_config().

To simplify handling, use the guard helper to let the compiler care for
unlocking. Otherwise unlocking would be more difficult as there is more
than one exit path in atmel_tcb_pwm_apply().

Fixes: 9421bade0765 ("pwm: atmel: add Timer Counter Block PWM driver")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Link: https://lore.kernel.org/r/20240709101806.52394-3-u.kleine-koenig@baylibre.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
drivers/pwm/pwm-atmel-tcb.c