On Wed, Apr 01, 2020 at 07:01:06PM +0200, Clemens Gruber wrote: > From: Sven Van Asbroeck > > 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 > Fixes: e926b12c611c ("pwm: Clear chip_data in pwm_put()") > Cc: Mika Westerberg > Cc: Uwe Kleine-König > Cc: YueHaibing > Link: https://lkml.org/lkml/2019/5/31/963 > Signed-off-by: Sven Van Asbroeck > Reviewed-by: Mika Westerberg > Tested-by: Clemens Gruber > [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