The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Cong Nguyen <congnt264@gmail.com>
To: Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>
Cc: Fenglin Wu <quic_fenglinw@quicinc.com>,
	Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>,
	linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] leds: flash: qcom-flash: release v4l2 flash devices on torch clamp failure
Date: Tue, 24 Nov 2026 16:54:08 +0700	[thread overview]
Message-ID: <20261124095408.3842986-2-congnt264@gmail.com> (raw)
In-Reply-To: <20261124095408.3842986-1-congnt264@gmail.com>

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


      reply	other threads:[~2026-11-24  9:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261124095408.3842986-2-congnt264@gmail.com \
    --to=congnt264@gmail.com \
    --cc=konrad.dybcio@oss.qualcomm.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=quic_fenglinw@quicinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox