leds: sgm3140: Add missing timer cleanup and flash gpio control

Message ID 20240217191133.1757553-1-megi@xff.cz
State New
Headers
Series leds: sgm3140: Add missing timer cleanup and flash gpio control |

Commit Message

Ondřej Jirman Feb. 17, 2024, 7:11 p.m. UTC
  From: Ondrej Jirman <megi@xff.cz>

Enabling strobe and then setting brightness to 0 causes the driver to enter
invalid state after strobe end timer fires. We should cancel strobe mode
resources when changing brightness (aka torch mode).

Fixes: cef8ec8cbd21 ("leds: add sgm3140 driver")
Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
I also have a sense the driver has other issues, like running regulator_disable
in atomic context, and lacking locking in general. But that's for another time.

I don't think this device is typically used from multiple threads/processes.
But writing strobe = 1 and then brightness = 0 affects real usecases.

 drivers/leds/flash/leds-sgm3140.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Lee Jones Feb. 23, 2024, 4:13 p.m. UTC | #1
On Sat, 17 Feb 2024 20:11:30 +0100, Ondřej Jirman wrote:
> Enabling strobe and then setting brightness to 0 causes the driver to enter
> invalid state after strobe end timer fires. We should cancel strobe mode
> resources when changing brightness (aka torch mode).
> 
> 

Applied, thanks!

[1/1] leds: sgm3140: Add missing timer cleanup and flash gpio control
      commit: 3e7b2b9309cd3eb1b82121b8a978d2dd19301924

--
Lee Jones [李琼斯]
  

Patch

diff --git a/drivers/leds/flash/leds-sgm3140.c b/drivers/leds/flash/leds-sgm3140.c
index eb648ff54b4e..db0ac6641954 100644
--- a/drivers/leds/flash/leds-sgm3140.c
+++ b/drivers/leds/flash/leds-sgm3140.c
@@ -114,8 +114,11 @@  static int sgm3140_brightness_set(struct led_classdev *led_cdev,
 				"failed to enable regulator: %d\n", ret);
 			return ret;
 		}
+		gpiod_set_value_cansleep(priv->flash_gpio, 0);
 		gpiod_set_value_cansleep(priv->enable_gpio, 1);
 	} else {
+		del_timer_sync(&priv->powerdown_timer);
+		gpiod_set_value_cansleep(priv->flash_gpio, 0);
 		gpiod_set_value_cansleep(priv->enable_gpio, 0);
 		ret = regulator_disable(priv->vin_regulator);
 		if (ret) {