* [PATCH v4] media: v4l2-flash: Enter LED off state after file handle closed
@ 2026-02-24 8:06 cy_huang
0 siblings, 0 replies; only message in thread
From: cy_huang @ 2026-02-24 8:06 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Jacek Anaszewski
Cc: Bryan Wu, Jacek Anaszewski, Kyungmin Park, Sakari Ailus,
roger-hy.wang, ChiYuan Huang, linux-media, linux-kernel, stable
From: ChiYuan Huang <cy_huang@richtek.com>
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@vger.kernel.org
Fixes: 42bd6f59ae90 ("media: Add registration helpers for V4L2 flash sub-devices")
Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
---
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-02-24 8:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-24 8:06 [PATCH v4] media: v4l2-flash: Enter LED off state after file handle closed cy_huang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox