[PATCH 1/4] leds: rgb: leds-qcom-lpg: Fix single-entry LUT leak

From: Fenglin Wu

Date: Tue Nov 17 2026 - 04:32:48 EST


The LUT resource cleanup path currently treats identical high and
low indices as an unallocated range and skips clearing the bitmap
allocation. However, with a 2-step palindrome pattern, the high
and low indices are identical, which can leak the LUT resource
because the bitmap allocation remains uncleared.

Resolve this by tracking LUT ownership separately from the index
range. Designate the first channel as the owner of shared
allocations and each active multicolor channel as the owner
of its per-channel allocation, then track this ownership state
for both normal cleanup and allocation.

Fixes: 24e2d05d1b689 ("leds: Add driver for Qualcomm LPG")
Closes: https://lore.kernel.org/linux-leds/7e474cdf-fcb2-468d-844d-f8afb5976d16@xxxxxxxxxxxxxxxx/
Signed-off-by: Fenglin Wu <fenglin.wu@xxxxxxxxxxxxxxxx>
---
drivers/leds/rgb/leds-qcom-lpg.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c
index 24ffe079f221..e14a3316bf22 100644
--- a/drivers/leds/rgb/leds-qcom-lpg.c
+++ b/drivers/leds/rgb/leds-qcom-lpg.c
@@ -111,6 +111,7 @@ struct lpg_data;
* @ramp_hi_pause_ms: pause (in milliseconds) after iterating over pattern
* @pattern_lo_idx: start index of associated pattern
* @pattern_hi_idx: last index of associated pattern
+ * @has_lut: channel has the associated LUT allocation
*/
struct lpg_channel {
struct lpg *lpg;
@@ -147,6 +148,7 @@ struct lpg_channel {

unsigned int pattern_lo_idx;
unsigned int pattern_hi_idx;
+ bool has_lut;
};

/**
@@ -393,15 +395,19 @@ static int lpg_lut_store(struct lpg *lpg, struct led_pattern *pattern,
return 0;
}

-static void lpg_lut_free(struct lpg *lpg, unsigned int lo_idx, unsigned int hi_idx)
+static void lpg_lut_free(struct lpg_channel *chan)
{
+ struct lpg *lpg = chan->lpg;
int len;

- len = hi_idx - lo_idx + 1;
- if (len == 1)
- return;
+ if (chan->has_lut) {
+ len = chan->pattern_hi_idx - chan->pattern_lo_idx + 1;
+ bitmap_clear(lpg->lut_bitmap, chan->pattern_lo_idx, len);
+ }

- bitmap_clear(lpg->lut_bitmap, lo_idx, len);
+ chan->pattern_lo_idx = 0;
+ chan->pattern_hi_idx = 0;
+ chan->has_lut = false;
}

static int lpg_lut_sync(struct lpg *lpg, unsigned int mask)
@@ -1118,6 +1124,8 @@ static int lpg_pattern_set(struct lpg_led *led, struct led_pattern *led_pattern,

chan->pattern_lo_idx = lo_idx;
chan->pattern_hi_idx = hi_idx;
+ /* The 1st channel owns the LUT while other channels share it */
+ chan->has_lut = i == 0;
}

out_unlock:
@@ -1176,7 +1184,7 @@ static int lpg_pattern_clear(struct lpg_led *led)
mutex_lock(&lpg->lock);

chan = led->channels[0];
- lpg_lut_free(lpg, chan->pattern_lo_idx, chan->pattern_hi_idx);
+ lpg_lut_free(chan);

for (i = 0; i < led->num_channels; i++) {
chan = led->channels[i];

--
2.43.0