[PATCH 1/2] pwm: atmel-tcb: Fix race condition and convert to guards
Uwe Kleine-König
u.kleine-koenig at baylibre.com
Wed Jul 10 08:31:28 PDT 2024
Hello Nicolas,
On Wed, Jul 10, 2024 at 04:17:09PM +0200, Nicolas Ferre wrote:
> On 09/07/2024 at 12:18, Uwe Kleine-König wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> >
> > 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 at baylibre.com>
>
> Acked-by: Nicolas Ferre <nicolas.ferre at microchip.com>
>
> And I like the conversion to the "guard" lock helper.
I hesitated a bit to add it because it will make backporting to stable
harder. But I guess we will just not backport it, the problem doesn't
seem to matter in practise given that it was found by looking at code
and not hit in real life more more than 11 years after its introduction.
Best regards and thanks for your Acks,
Uwe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20240710/1c721cd6/attachment.sig>
More information about the linux-arm-kernel
mailing list