Re: [PATCH v2 REBASED] pwm: pca9685: fix pwm/gpio inter-operation
From: Thierry Reding
Date: Fri Apr 03 2020 - 15:44:30 EST
On Wed, Apr 01, 2020 at 07:01:06PM +0200, Clemens Gruber wrote:
> From: Sven Van Asbroeck <TheSven73@xxxxxxxxx>
>
> This driver allows pwms to be requested as gpios via gpiolib.
> Obviously, it should not be allowed to request a gpio when its
> corresponding pwm is already requested (and vice versa).
> So it requires some exclusion code.
>
> Given that the pwm and gpio cores are not synchronized with
> respect to each other, this exclusion code will also require
> proper synchronization.
>
> Such a mechanism was in place, but was inadvertently removed
> by Uwe's clean-up patch.
>
> Upon revisiting the synchronization mechanism, we found that
> theoretically, it could allow two threads to successfully
> request conflicting pwms / gpios.
>
> Replace with a bitmap which tracks pwm in-use, plus a mutex.
> As long as pwm and gpio's respective request/free functions
> modify the in-use bitmap while holding the mutex, proper
> synchronization will be guaranteed.
>
> Reported-by: YueHaibing <yuehaibing@xxxxxxxxxx>
> Fixes: e926b12c611c ("pwm: Clear chip_data in pwm_put()")
> Cc: Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx>
> Cc: Uwe Kleine-KÃnig <u.kleine-koenig@xxxxxxxxxxxxxx>
> Cc: YueHaibing <yuehaibing@xxxxxxxxxx>
> Link: https://lkml.org/lkml/2019/5/31/963
> Signed-off-by: Sven Van Asbroeck <TheSven73@xxxxxxxxx>
> Reviewed-by: Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx>
> Tested-by: Clemens Gruber <clemens.gruber@xxxxxxxxxxxx>
> [cg: Tested on an i.MX6Q board with two NXP PCA9685 chips]
>
> ---
> drivers/pwm/pwm-pca9685.c | 85 ++++++++++++++++++++++-----------------
> 1 file changed, 48 insertions(+), 37 deletions(-)
Applied, thanks.
Thierry
Attachment:
signature.asc
Description: PGP signature