Patch "pwm: sysfs: Do not apply state to already disabled PWMs" has been added to the 5.4-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: sysfs: Do not apply state to already disabled PWMs

to the 5.4-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-sysfs-do-not-apply-state-to-already-disabled-pwm.patch
and it can be found in the queue-5.4 subdirectory.

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



commit fa6912a8dd82c69bf7e1b9dda0dc7ce9cc0170fe
Author: Marek Vasut <marex@xxxxxxx>
Date:   Fri May 12 18:47:36 2023 +0200

    pwm: sysfs: Do not apply state to already disabled PWMs
    
    [ Upstream commit 38ba83598633373f47951384cfc389181c8d1bed ]
    
    If the PWM is exported but not enabled, do not call pwm_class_apply_state().
    First of all, in this case, period may still be unconfigured and this would
    make pwm_class_apply_state() return -EINVAL, and then suspend would fail.
    Second, it makes little sense to apply state onto PWM that is not enabled
    before suspend.
    
    Failing case:
    "
    $ echo 1 > /sys/class/pwm/pwmchip4/export
    $ echo mem > /sys/power/state
    ...
    pwm pwmchip4: PM: dpm_run_callback(): pwm_class_suspend+0x1/0xa8 returns -22
    pwm pwmchip4: PM: failed to suspend: error -22
    PM: Some devices failed to suspend, or early wake event detected
    "
    
    Working case:
    "
    $ echo 1 > /sys/class/pwm/pwmchip4/export
    $ echo 100 > /sys/class/pwm/pwmchip4/pwm1/period
    $ echo 10 > /sys/class/pwm/pwmchip4/pwm1/duty_cycle
    $ echo mem > /sys/power/state
    ...
    "
    
    Do not call pwm_class_apply_state() in case the PWM is disabled
    to fix this issue.
    
    Fixes: 7fd4edc57bbae ("pwm: sysfs: Add suspend/resume support")
    Signed-off-by: Marek Vasut <marex@xxxxxxx>
    Fixes: ef2bf4997f7d ("pwm: Improve args checking in pwm_apply_state()")
    Reviewed-by: Brian Norris <briannorris@xxxxxxxxxxxx>
    Reviewed-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxxxx>
    Signed-off-by: Thierry Reding <thierry.reding@xxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/pwm/sysfs.c b/drivers/pwm/sysfs.c
index 2389b86698468..986f3a29a13d5 100644
--- a/drivers/pwm/sysfs.c
+++ b/drivers/pwm/sysfs.c
@@ -424,6 +424,13 @@ static int pwm_class_resume_npwm(struct device *parent, unsigned int npwm)
 		if (!export)
 			continue;
 
+		/* If pwmchip was not enabled before suspend, do nothing. */
+		if (!export->suspend.enabled) {
+			/* release lock taken in pwm_class_get_state */
+			mutex_unlock(&export->lock);
+			continue;
+		}
+
 		state.enabled = export->suspend.enabled;
 		ret = pwm_class_apply_state(export, pwm, &state);
 		if (ret < 0)
@@ -448,7 +455,17 @@ static int __maybe_unused pwm_class_suspend(struct device *parent)
 		if (!export)
 			continue;
 
+		/*
+		 * If pwmchip was not enabled before suspend, save
+		 * state for resume time and do nothing else.
+		 */
 		export->suspend = state;
+		if (!state.enabled) {
+			/* release lock taken in pwm_class_get_state */
+			mutex_unlock(&export->lock);
+			continue;
+		}
+
 		state.enabled = false;
 		ret = pwm_class_apply_state(export, pwm, &state);
 		if (ret < 0) {



[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