* [PATCH 1/2] leds: flash: qcom-flash: fix the v4l2 flash release loops
@ 2026-11-24 9:54 Cong Nguyen
2026-11-24 9:54 ` [PATCH 2/2] leds: flash: qcom-flash: release v4l2 flash devices on torch clamp failure Cong Nguyen
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Cong Nguyen @ 2026-11-24 9:54 UTC (permalink / raw)
To: Lee Jones, Pavel Machek
Cc: Fenglin Wu, Konrad Dybcio, linux-leds, linux-kernel
qcom_flash_v4l2_init() stores each LED's v4l2_flash in
v4l2_flash[leds_count], and probe increments leds_count after each LED.
So the valid entries are 0..leds_count - 1.
The release loops in the probe error path and in remove() start one past
the last stored entry and never reach index 0:
while (v4l2_flash[leds_count] && leds_count)
v4l2_flash_release(v4l2_flash[leds_count--]);
After a successful probe of N LEDs, remove() reads index N of an array
with N entries. When probe fails, that entry is NULL, so nothing is
released.
Release the entries from leds_count - 1 down to 0 instead.
v4l2_flash_release() ignores NULL.
This issue was found by auditing the driver with an LLM coding assistant.
Fixes: 96a2e242a5dc ("leds: flash: Add driver to support flash LED module in QCOM PMICs")
Signed-off-by: Cong Nguyen <congnt264@gmail.com>
---
drivers/leds/flash/leds-qcom-flash.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/leds/flash/leds-qcom-flash.c b/drivers/leds/flash/leds-qcom-flash.c
index 4e62a210cf98..1003ba060b42 100644
--- a/drivers/leds/flash/leds-qcom-flash.c
+++ b/drivers/leds/flash/leds-qcom-flash.c
@@ -953,8 +953,8 @@ static int qcom_flash_led_probe(struct platform_device *pdev)
return regmap_field_write(flash_data->r_fields[REG_TORCH_CLAMP], flash_data->torch_clamp);
release:
- while (flash_data->v4l2_flash[flash_data->leds_count] && flash_data->leds_count)
- v4l2_flash_release(flash_data->v4l2_flash[flash_data->leds_count--]);
+ while (flash_data->leds_count)
+ v4l2_flash_release(flash_data->v4l2_flash[--flash_data->leds_count]);
return rc;
}
@@ -962,8 +962,8 @@ static void qcom_flash_led_remove(struct platform_device *pdev)
{
struct qcom_flash_data *flash_data = platform_get_drvdata(pdev);
- while (flash_data->v4l2_flash[flash_data->leds_count] && flash_data->leds_count)
- v4l2_flash_release(flash_data->v4l2_flash[flash_data->leds_count--]);
+ while (flash_data->leds_count)
+ v4l2_flash_release(flash_data->v4l2_flash[--flash_data->leds_count]);
mutex_destroy(&flash_data->lock);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] leds: flash: qcom-flash: release v4l2 flash devices on torch clamp failure
2026-11-24 9:54 [PATCH 1/2] leds: flash: qcom-flash: fix the v4l2 flash release loops Cong Nguyen
@ 2026-11-24 9:54 ` Cong Nguyen
2026-11-24 10:05 ` [PATCH 1/2] leds: flash: qcom-flash: fix the v4l2 flash release loops sashiko-bot
2026-11-24 10:05 ` sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: Cong Nguyen @ 2026-11-24 9:54 UTC (permalink / raw)
To: Lee Jones, Pavel Machek
Cc: Fenglin Wu, Konrad Dybcio, linux-leds, linux-kernel
qcom_flash_led_probe() registers the LEDs and their v4l2 flash
sub-devices in a loop, and then returns the result of the final
regmap_field_write() of the torch clamp field. Every other failure after
the first v4l2_flash_init() jumps to the release label, which calls
v4l2_flash_release().
If this last write fails, probe fails without releasing the v4l2 flash
sub-devices. They are not device managed, so they stay registered after the
LED class devices that they use are freed.
Jump to the release label on failure of that write as well.
This issue was found by auditing the driver with an LLM coding assistant.
Fixes: 5974e8f6c3e4 ("leds: flash: leds-qcom-flash: Update torch current clamp setting")
Signed-off-by: Cong Nguyen <congnt264@gmail.com>
---
drivers/leds/flash/leds-qcom-flash.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/leds/flash/leds-qcom-flash.c b/drivers/leds/flash/leds-qcom-flash.c
index 1003ba060b42..b335784fe68c 100644
--- a/drivers/leds/flash/leds-qcom-flash.c
+++ b/drivers/leds/flash/leds-qcom-flash.c
@@ -951,7 +951,11 @@ static int qcom_flash_led_probe(struct platform_device *pdev)
flash_data->leds_count++;
}
- return regmap_field_write(flash_data->r_fields[REG_TORCH_CLAMP], flash_data->torch_clamp);
+ rc = regmap_field_write(flash_data->r_fields[REG_TORCH_CLAMP], flash_data->torch_clamp);
+ if (rc < 0)
+ goto release;
+
+ return 0;
release:
while (flash_data->leds_count)
v4l2_flash_release(flash_data->v4l2_flash[--flash_data->leds_count]);
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 1/2] leds: flash: qcom-flash: fix the v4l2 flash release loops
2026-11-24 9:54 [PATCH 1/2] leds: flash: qcom-flash: fix the v4l2 flash release loops Cong Nguyen
2026-11-24 9:54 ` [PATCH 2/2] leds: flash: qcom-flash: release v4l2 flash devices on torch clamp failure Cong Nguyen
@ 2026-11-24 10:05 ` sashiko-bot
2026-11-24 10:05 ` sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-24 10:05 UTC (permalink / raw)
To: Cong Nguyen; +Cc: linux-leds, lee
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] leds: qcom-flash: use-after-free in qcom_flash_led_probe()
[1]
--
commit 01b91774110dfcae9bec7d39022e0b10aec8e56b
Author: Cong Nguyen <congnt264@gmail.com>
leds: flash: qcom-flash: fix the v4l2 flash release loops
This commit fixes the v4l2_flash_release() loops in the probe error path
and remove callback to release indices from leds_count - 1 down to 0.
> diff --git a/drivers/leds/flash/leds-qcom-flash.c b/drivers/leds/flash/leds-qcom-flash.c
> index 4e62a210cf98d..1003ba060b423 100644
> --- a/drivers/leds/flash/leds-qcom-flash.c
> +++ b/drivers/leds/flash/leds-qcom-flash.c
> @@ -953,8 +953,8 @@ static int qcom_flash_led_probe(struct platform_device *pdev)
>
> return regmap_field_write(flash_data->r_fields[REG_TORCH_CLAMP], flash_data->torch_clamp);
> release:
> - while (flash_data->v4l2_flash[flash_data->leds_count] && flash_data->leds_count)
> - v4l2_flash_release(flash_data->v4l2_flash[flash_data->leds_count--]);
> + while (flash_data->leds_count)
> + v4l2_flash_release(flash_data->v4l2_flash[--flash_data->leds_count]);
> return rc;
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but does returning directly
when regmap_field_write() fails skip the release label and leave
flash_data->v4l2_flash[] subdevices registered [1]? When probe
returns an error, devres frees the backing device-managed memory while V4L2
still holds pointers to the subdevices, leading to a use-after-free.
[1] https://sashiko.dev/#/bug/linux-e48f7fbe-dd94-4b3f-aff8-e1dc279dec37
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124095408.3842986-1-congnt264@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] leds: flash: qcom-flash: fix the v4l2 flash release loops
2026-11-24 9:54 [PATCH 1/2] leds: flash: qcom-flash: fix the v4l2 flash release loops Cong Nguyen
2026-11-24 9:54 ` [PATCH 2/2] leds: flash: qcom-flash: release v4l2 flash devices on torch clamp failure Cong Nguyen
2026-11-24 10:05 ` [PATCH 1/2] leds: flash: qcom-flash: fix the v4l2 flash release loops sashiko-bot
@ 2026-11-24 10:05 ` sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-24 10:05 UTC (permalink / raw)
To: Cong Nguyen; +Cc: linux-leds, lee
Sashiko has finished reviewing this 2-patch series:
- Patch 2: no issues found.
- Patch 1 ("leds: flash: qcom-flash: fix the v4l2 flash release..."): 1
related pre-existing bug noted
A detailed review has been sent as a separate reply to patch 1.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124095408.3842986-1-congnt264@gmail.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-24 10:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 9:54 [PATCH 1/2] leds: flash: qcom-flash: fix the v4l2 flash release loops Cong Nguyen
2026-11-24 9:54 ` [PATCH 2/2] leds: flash: qcom-flash: release v4l2 flash devices on torch clamp failure Cong Nguyen
2026-11-24 10:05 ` [PATCH 1/2] leds: flash: qcom-flash: fix the v4l2 flash release loops sashiko-bot
2026-11-24 10:05 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).