[PATCH v4] media: v4l2-flash: Enter LED off state after file handle closed
From: cy_huang
Date: Tue Feb 24 2026 - 03:12:10 EST
From: ChiYuan Huang <cy_huang@xxxxxxxxxxx>
To make sure LED enter off state after file handle is closed, initiatively
configure LED_MODE to NONE. This can guarantee whatever the previous state
is torch or strobe mode, the final state will be off.
Cc: stable@xxxxxxxxxxxxxxx
Fixes: 42bd6f59ae90 ("media: Add registration helpers for V4L2 flash sub-devices")
Signed-off-by: ChiYuan Huang <cy_huang@xxxxxxxxxxx>
---
v4:
- Refine the led close into lock guarantee.
v3
- Remove 'Reported-by' tag
- Fix identation check for patch integration
v2
- Fix commit message redudant space cause patch robot parsing error
Hi,
Since the original 'direcly return' is bad, the below lines cannot be
called like as restroing led/iled to sysfs control. Therefore I refine
the code writing. 'goto' may be a bad coding. But to minimize changes,
this could be tradeoff.
Open discussion if there's the better solution.
[Preface]
We encounter an issue. When the upper layer camera process is crashed,
if the new process did not reinit the LED, it will keeps the previous
state whatever it's in torch or strobe mode
OS will handle the resource management. So when the process is crashed
or terminated, the 'close' API will be called to release resources.
That's why we add the initiative action to trigger LED off in file
handle close is called.
---
drivers/media/v4l2-core/v4l2-flash-led-class.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-flash-led-class.c b/drivers/media/v4l2-core/v4l2-flash-led-class.c
index 163badeef76f..259fe014db26 100644
--- a/drivers/media/v4l2-core/v4l2-flash-led-class.c
+++ b/drivers/media/v4l2-core/v4l2-flash-led-class.c
@@ -624,10 +624,17 @@ static int v4l2_flash_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
if (led_cdev) {
mutex_lock(&led_cdev->led_access);
+ /* If file handle is released, make sure LED enter off state */
+ ret = v4l2_ctrl_s_ctrl(v4l2_flash->ctrls[LED_MODE],
+ V4L2_FLASH_LED_MODE_NONE);
+ if (ret)
+ goto out_led_close;
+
if (v4l2_flash->ctrls[STROBE_SOURCE])
ret = v4l2_ctrl_s_ctrl(
v4l2_flash->ctrls[STROBE_SOURCE],
V4L2_FLASH_STROBE_SOURCE_SOFTWARE);
+out_led_close:
led_sysfs_enable(led_cdev);
mutex_unlock(&led_cdev->led_access);
--
2.34.1