Patch "pwm: sifive: Always let the first pwm_apply_state succeed" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    pwm: sifive: Always let the first pwm_apply_state succeed

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     pwm-sifive-always-let-the-first-pwm_apply_state-succ.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit fd45fc7a589d54b3163f84f59ba5d3c07da4d9c9
Author: Emil Renner Berthing <emil.renner.berthing@xxxxxxxxxxxxx>
Date:   Wed Nov 9 12:37:24 2022 +0100

    pwm: sifive: Always let the first pwm_apply_state succeed
    
    [ Upstream commit 334c7b13d38321e47d1a51dba0bef9f4c403ec75 ]
    
    Commit 2cfe9bbec56ea579135cdd92409fff371841904f added support for the
    RGB and green PWM controlled LEDs on the HiFive Unmatched board
    managed by the leds-pwm-multicolor and leds-pwm drivers respectively.
    All three colours of the RGB LED and the green LED run from different
    lines of the same PWM, but with the same period so this works fine when
    the LED drivers are loaded one after the other.
    
    Unfortunately it does expose a race in the PWM driver when both LED
    drivers are loaded at roughly the same time. Here is an example:
    
      |          Thread A           |          Thread B           |
      |  led_pwm_mc_probe           |  led_pwm_probe              |
      |    devm_fwnode_pwm_get      |                             |
      |      pwm_sifive_request     |                             |
      |        ddata->user_count++  |                             |
      |                             |    devm_fwnode_pwm_get      |
      |                             |      pwm_sifive_request     |
      |                             |        ddata->user_count++  |
      |         ...                 |          ...                |
      |    pwm_state_apply          |    pwm_state_apply          |
      |      pwm_sifive_apply       |      pwm_sifive_apply       |
    
    Now both calls to pwm_sifive_apply will see that ddata->approx_period,
    initially 0, is different from the requested period and the clock needs
    to be updated. But since ddata->user_count >= 2 both calls will fail
    with -EBUSY, which will then cause both LED drivers to fail to probe.
    
    Fix it by letting the first call to pwm_sifive_apply update the clock
    even when ddata->user_count != 1.
    
    Fixes: 9e37a53eb051 ("pwm: sifive: Add a driver for SiFive SoC PWM")
    Signed-off-by: Emil Renner Berthing <emil.renner.berthing@xxxxxxxxxxxxx>
    Signed-off-by: Thierry Reding <thierry.reding@xxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c
index 85760c90278c0..41a6fc47cc163 100644
--- a/drivers/pwm/pwm-sifive.c
+++ b/drivers/pwm/pwm-sifive.c
@@ -184,7 +184,13 @@ static int pwm_sifive_apply(struct pwm_chip *chip, struct pwm_device *pwm,
 
 	mutex_lock(&ddata->lock);
 	if (state->period != ddata->approx_period) {
-		if (ddata->user_count != 1) {
+		/*
+		 * Don't let a 2nd user change the period underneath the 1st user.
+		 * However if ddate->approx_period == 0 this is the first time we set
+		 * any period, so let whoever gets here first set the period so other
+		 * users who agree on the period won't fail.
+		 */
+		if (ddata->user_count != 1 && ddata->approx_period) {
 			mutex_unlock(&ddata->lock);
 			ret = -EBUSY;
 			goto exit;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux