leds: flash: qcom: correct the cleanup indexing
PATCH 1/2 leds: flash: qcom: correct the cleanup indexing
The cleanup of the flash controller walks the registered LEDs and frees the slots it finds. It counted the entries first and decremented the count before it used the index, so the last entry was left registered and the next registration reused the slot.
Do not stop the cleanup on a NULL slot: torch-only LEDs and configurations without the V4L2 wrapper may leave NULL entries, which v4l2_flash_release() already accepts.
device on the platform with multiple LEDs")
Original patch by slwyts <[email protected]>.
--- drivers/leds/flash/leds-qcom-flash.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/leds/flash/leds-qcom-flash.c +17 -2
@@ -654,7 +654,11 @@ qcom_flash_intensity_to_led_brightness(struct v4l2_flash *v4l2_flash, s32 intensif (!current_ma)return LED_OFF ; -return (current_ma *LED_FULL ) / led->max_torch_current_ma; +/* brightness_set() converts back with integer division. Round this +* encoding up so an exact 5mA/channel control step is not lost to a +* second truncation. The PMIC still rounds current down to its step. +*/ +return DIV_ROUND_UP (current_ma *LED_FULL , led->max_torch_current_ma); } static s32 qcom_flash_brightness_to_led_intensity(struct v4l2_flash *v4l2_flash,
@@ -662,8 +666,19 @@ static s32 qcom_flash_brightness_to_led_intensity(struct v4l2_flash *v4l2_flash, {struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;struct qcom_flash_led *led =flcdev_to_qcom_fled (fled_cdev); +u32 current_ma, steps; + +if (!brightness) +return 0 ; -return (brightness * led->max_torch_current_ma *UA_PER_MA ) /LED_FULL ; +/* Mirror brightness_set() then set_flash_current(): the total mA are +* split per channel, and ITARGET=0 is a nonzero 5mA minimum. Return the +* quantized total, not the unrepresentable LED scale fraction. Thermal +* limiting can still reduce the current during brightness_set(). +*/ + current_ma = brightness * led->max_torch_current_ma /LED_FULL ; + steps = (current_ma *UA_PER_MA / led->chan_count +1 ) /TORCH_IRES_UA ; +return max_t (u32, steps,1 ) *TORCH_IRES_UA * led->chan_count; }static const struct v4l2_flash_ops qcom_v4l2_flash_ops = {
Signature · 1 line
2.54.0 (Apple Git-157)
Lee Jones
maintainer--- checkpatch.pl (1 issue) ---
Line 12: WARNING: Please use correct Fixes: style 'Fixes: <12+ chars of sha1> ("<title line>")' - ie: 'Fixes: 96a2e242a5dc ("leds: flash: Add driver to support flash LED module in QCOM PMICs")'
----------------------------------
Quoted 8 lines · On Sun, 01 Nov 2026, Ch1rpy wrote:
The cleanup of the flash controller walks the registered LEDs and frees the slots it finds. It counted the entries first and decremented the count before it used the index, so the last entry was left registered and the next registration reused the slot.
Do not stop the cleanup on a NULL slot: torch-only LEDs and configurations without the V4L2 wrapper may leave NULL entries, which
v4l2_flash_release()already accepts.
This commit message describes a completely different change (which appears to already be upstream as commit 75565a889829 ("leds: flash: leds-qcom-flash:
Release all V4L2 flash devices")) from the brightness/intensity conversion changes in the diff below.
Quoted 2 lines
Fixes 96a2e242a5dc ("leds: flash: qcom: Fix cleanup of LED flashdevice on the platform with multiple LEDs")
Please don't wrap Fixes: lines, also the commit ID doesn't match the subject? What on earth is going on with this commit?
Quoted 4 lines
Original patch by slwyts <[email protected]>.
Signed-off-by Ch1rpy <[email protected]>
Please use your full, real name in the 'Signed-off-by:' tag (and 'From:' header), as required by Documentation/process/submitting-patches.rst.
Quoted 9 lines
--- drivers/leds/flash/leds-qcom-flash.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)drivers/leds/flash/leds-qcom-flash.c +0
-0
drivers/leds/flash/leds-qcom-flash.c qcom_flash_intensity_to_led_brightness(struct v4l2_flash *v4l2_flash, s32 intens · line 660
Quoted 8 lines
drivers/leds/flash/leds-qcom-flash.c +4
-1@@ -654,7 +654,11 @@ qcom_flash_intensity_to_led_brightness(struct v4l2_flash *v4l2_flash, s32 intensif (!current_ma)return LED_OFF ; -return (current_ma *LED_FULL ) / led->max_torch_current_ma; +/* brightness_set() converts back with integer division. Round this +* encoding up so an exact 5mA/channel control step is not lost to a +* second truncation. The PMIC still rounds current down to its step. +*/
This is an incorrect multi-line comment format.
Quoted 28 lines
drivers/leds/flash/leds-qcom-flash.c +13
-1+return DIV_ROUND_UP (current_ma *LED_FULL , led->max_torch_current_ma); } static s32 qcom_flash_brightness_to_led_intensity(struct v4l2_flash *v4l2_flash,@@ -662,8 +666,19 @@ static s32 qcom_flash_brightness_to_led_intensity(struct v4l2_flash *v4l2_flash, {struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev;struct qcom_flash_led *led =flcdev_to_qcom_fled (fled_cdev); +u32 current_ma, steps; + +if (!brightness) +return 0 ; -return (brightness * led->max_torch_current_ma *UA_PER_MA ) /LED_FULL ; +/* Mirror brightness_set() then set_flash_current(): the total mA are +* split per channel, and ITARGET=0 is a nonzero 5mA minimum. Return the +* quantized total, not the unrepresentable LED scale fraction. Thermal +* limiting can still reduce the current during brightness_set(). +*/ + current_ma = brightness * led->max_torch_current_ma /LED_FULL ; + steps = (current_ma *UA_PER_MA / led->chan_count +1 ) /TORCH_IRES_UA ; +return max_t (u32, steps,1 ) *TORCH_IRES_UA * led->chan_count; }static const struct v4l2_flash_ops qcom_v4l2_flash_ops = {Signature · 1 line
2.54.0 (Apple Git-157)
Signature · 1 line
Lee Jones