Message ID | 20221018061656.1428111-1-u.kleine-koenig@pengutronix.de |
---|---|
State | Accepted |
Headers | show |
Series | pwm: sifive: Call pwm_sifive_update_clock() while mutex is held | expand |
> As was documented in commit 0f02f491b786 ("pwm: sifive: Reduce time the > controller lock is held") a caller of pwm_sifive_update_clock() must > hold the mutex. So fix pwm_sifive_clock_notifier() to grab the lock. > > While this necessity was only documented later, the race exists since > the driver was introduced. > > Fixes: 9e37a53eb051 ("pwm: sifive: Add a driver for SiFive SoC PWM") > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Thanks, as discussed on IRC: Reported-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> ..and you can also add my Reviewed-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> /Emil > --- > drivers/pwm/pwm-sifive.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c > index 2d4fa5e5fdd4..bb7239313401 100644 > --- a/drivers/pwm/pwm-sifive.c > +++ b/drivers/pwm/pwm-sifive.c > @@ -204,8 +204,11 @@ static int pwm_sifive_clock_notifier(struct notifier_block *nb, > struct pwm_sifive_ddata *ddata = > container_of(nb, struct pwm_sifive_ddata, notifier); > > - if (event == POST_RATE_CHANGE) > + if (event == POST_RATE_CHANGE) { > + mutex_lock(&ddata->lock); > pwm_sifive_update_clock(ddata, ndata->new_rate); > + mutex_unlock(&ddata->lock); > + } > > return NOTIFY_OK; > } > > base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780 > > -- > 2.37.2
diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c index 2d4fa5e5fdd4..bb7239313401 100644 --- a/drivers/pwm/pwm-sifive.c +++ b/drivers/pwm/pwm-sifive.c @@ -204,8 +204,11 @@ static int pwm_sifive_clock_notifier(struct notifier_block *nb, struct pwm_sifive_ddata *ddata = container_of(nb, struct pwm_sifive_ddata, notifier); - if (event == POST_RATE_CHANGE) + if (event == POST_RATE_CHANGE) { + mutex_lock(&ddata->lock); pwm_sifive_update_clock(ddata, ndata->new_rate); + mutex_unlock(&ddata->lock); + } return NOTIFY_OK; }
As was documented in commit 0f02f491b786 ("pwm: sifive: Reduce time the controller lock is held") a caller of pwm_sifive_update_clock() must hold the mutex. So fix pwm_sifive_clock_notifier() to grab the lock. While this necessity was only documented later, the race exists since the driver was introduced. Fixes: 9e37a53eb051 ("pwm: sifive: Add a driver for SiFive SoC PWM") Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> --- drivers/pwm/pwm-sifive.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780