Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH v2] Input: lm8323 - drain PWM work and finish with outputs disabled
@ 2026-11-15 11:48 Hongyan Xu
  2026-11-16  2:36 ` Dmitry Torokhov
  0 siblings, 1 reply; 2+ messages in thread
From: Hongyan Xu @ 2026-11-15 11:48 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, linux-kernel, stable

A PWM brightness callback can leave private work pending when the
managed LED and chip state are released. Merely cancelling that
work also discards the final LED_OFF requested by LED unregister.
Flushing alone is insufficient if an earlier fade is still
running: the worker waits for an IRQ to requeue it, and the
managed IRQ is released before the LEDs during teardown.

Install cleanup before registering each LED. Once LED unregister
and IRQ teardown have stopped the producers, cancel its work and
use the documented single-END shutdown sequence: put END with
RESET set in unused script slot 59, stop the channel and restart
at that slot. Do not overwrite a running brightness script. The
engine then disables its output autonomously without another IRQ
or a worker accessing freed driver data. A current long RAMP can
delay completion, as documented by the device specification.

Found by the author's in-house static analysis tool.

Fixes: a48b2d4a0091 ("Input: introduce lm8323 keypad driver")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20260728065518.489-1-getshell@seu.edu.cn/
Link: https://www.ti.com/lit/ds/symlink/lm8323.pdf
Signed-off-by: Hongyan Xu <getshell@seu.edu.cn>
Signed-off-by: Zehao Gao <gaozehao@iie.ac.cn>
---

Discovery: found by the author's in-house static analysis tool.

 drivers/input/keyboard/lm8323.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/input/keyboard/lm8323.c b/drivers/input/keyboard/lm8323.c
index 4b87d39..e13bcde 100644
--- a/drivers/input/keyboard/lm8323.c
+++ b/drivers/input/keyboard/lm8323.c
@@ -548,6 +548,21 @@ static struct attribute *lm8323_pwm_attrs[] = {
 };
 ATTRIBUTE_GROUPS(lm8323_pwm);
 
+#define LM8323_PWM_SHUTDOWN_ADDR	59
+
+static void lm8323_pwm_shutdown(void *data)
+{
+	struct lm8323_pwm *pwm = data;
+
+	cancel_work_sync(&pwm->work);
+
+	/* The normal brightness scripts use only slots 0 through 3. */
+	lm8323_write_pwm_one(pwm, LM8323_PWM_SHUTDOWN_ADDR, PWM_END(1));
+	lm8323_write(pwm->chip, 2, LM8323_CMD_STOP_PWM, pwm->id);
+	lm8323_write(pwm->chip, 2, LM8323_CMD_START_PWM,
+		     (LM8323_PWM_SHUTDOWN_ADDR << 2) | pwm->id);
+}
+
 static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev,
 		    const char *name)
 {
@@ -569,6 +584,10 @@ static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev,
 	pwm->chip = lm;
 
 	if (name) {
+		err = devm_add_action_or_reset(dev, lm8323_pwm_shutdown, pwm);
+		if (err)
+			return err;
+
 		pwm->cdev.name = name;
 		pwm->cdev.brightness_set = lm8323_pwm_set_brightness;
 		pwm->cdev.groups = lm8323_pwm_groups;
-- 
2.50.1.windows.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] Input: lm8323 - drain PWM work and finish with outputs disabled
  2026-11-15 11:48 [PATCH v2] Input: lm8323 - drain PWM work and finish with outputs disabled Hongyan Xu
@ 2026-11-16  2:36 ` Dmitry Torokhov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Torokhov @ 2026-11-16  2:36 UTC (permalink / raw)
  To: Hongyan Xu; +Cc: linux-input, linux-kernel, stable

Hi Hongyan,

On Sun, Nov 15, 2026 at 07:48:12PM +0800, Hongyan Xu wrote:
> A PWM brightness callback can leave private work pending when the
> managed LED and chip state are released. Merely cancelling that
> work also discards the final LED_OFF requested by LED unregister.
> Flushing alone is insufficient if an earlier fade is still
> running: the worker waits for an IRQ to requeue it, and the
> managed IRQ is released before the LEDs during teardown.
> 
> Install cleanup before registering each LED. Once LED unregister
> and IRQ teardown have stopped the producers, cancel its work and
> use the documented single-END shutdown sequence: put END with
> RESET set in unused script slot 59, stop the channel and restart
> at that slot. Do not overwrite a running brightness script. The
> engine then disables its output autonomously without another IRQ
> or a worker accessing freed driver data. A current long RAMP can
> delay completion, as documented by the device specification.
> 
> Found by the author's in-house static analysis tool.
> 
> Fixes: a48b2d4a0091 ("Input: introduce lm8323 keypad driver")

This driver is being removed, no need to patch it. 

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-16  2:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15 11:48 [PATCH v2] Input: lm8323 - drain PWM work and finish with outputs disabled Hongyan Xu
2026-11-16  2:36 ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox