From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796134997; b=Q7Nncm/XerYpgXLnMX1pbeiqiXptPHE7c4acdzSSSDJuV3YIWqe4LiCB9BCS3vrl8l1C mx25Lf0pLanEgoElqhrZ1TAIR1WZI8w8l8fuyhfm4wL0dbANQ4Nr2jlqVRMNQuRA7sBxJ SXSBjEz9mQvbpZnBS7cwPlaGHVuXwfHzJFObX9HCo6PafNOE544Vuh21nRbslfJDdVNZ2 czxlW+M5kKlRSgts438UBNqUXJJ3T473BGRLVxpQTm9YoBROHzAhIu0T0USaUGuNFh1a5 kvofbUgDvs0jRekS5I2BGJkJwWWxGO/kZt0hAnYHZaKL99m9ZmqYNRRVEMM+XvXhezg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796134997; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To: X-AI-Review-Draft; bh=nMGmlztYFY92wagVrv6n1zH5VGP5R9ibn81d01rLzzM=; b=gnVQXkNdcrtmm6UjLU3HTk5Q9HVtOwEG1cHXQg1a8rOqoXRJKFqaT5A/rsU1qD5IiGR/ vPPNxN3aFw5SxfCosmHTDdAeBsCLLnM49yxihVoRmgrw3mfQCDUqo/FodscVrgdyoG+uk FuYuelYMDk+hwwpKriMtwkrs0ykncNt7FrN7leFd7t0kMJ9BTN5e/RalZUMex/ownuhsh YTL7XaVjsPtmnzOqs1xwxXFjh5bjIPkTpPCoaDV/XYWyWxMmE+WX7d/V36sFwk3UCcPzJ 862fVEYJCT4VHJNQdAcNqmAAPok59NIyCBySGpGNcfueKwgPsq2JK0gILDmPe7NbBWQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YC4LxJRZ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33A1C606A325; Tue, 1 Dec 2026 14:23:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YC4LxJRZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FE681F00934; Tue, 1 Dec 2026 14:23:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796134996; bh=nMGmlztYFY92wagVrv6n1zH5VGP5R9ibn81d01rLzzM=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=YC4LxJRZ7MUSmuQn5qLJnURtwUljaBt3XCt1+yMhRDVRWvLTSej8OSXESEBjuxxOP 1I5JRYDIlgwVeqBymVx1zqxx2SZn/IZ6nI3T35wjGoIeSopLU0miLHq5dfg5+VoLvJ YnNPjjKMnqsWQuDqhtkKdrpCwoO3Y+eWHfVh0J4dtlOrZXZYan3+gLc5HUBi6ID9zB gktIttPoQxPCSMIyFPLLsP/JpkcafwSAeaJOOyyxPpLbZs1BdW8jMUDaOmTwvHBeoz aWgtiYIKMHvMXSuu2rfqwv1CfiC5WQxJhh+wBs/9g8BVscNlt/7ZrOqDkrigD11WJ9 51yEOnsExiGyg== Date: Tue, 1 Dec 2026 14:23:10 +0000 From: Lee Jones To: Fenglin Wu Cc: linux-arm-msm@vger.kernel.org, Pavel Machek , Griffin Kroah-Hartman , Marijn Suijten , Bjorn Andersson , Anjelique Melendez , Guru Das Srinagesh , Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= , Jonathan Corbet , Shuah Khan , Randy Dunlap , David Collins , Subbaraman Narayanamurthy , Kamal Wadhwa , Pavel Machek , linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [PATCH v3 1/4] leds: rgb: leds-qcom-lpg: Fix single-entry LUT leak Message-ID: <179568565555.32537.11528409319338694015@kernel.org> References: <20261122-led-qcom-leds-multiple-fixes-and-pwm-fm-support-v3-0-f911edd40a31@oss.qualcomm.com> <20261122-led-qcom-leds-multiple-fixes-and-pwm-fm-support-v3-1-f911edd40a31@oss.qualcomm.com> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261122-led-qcom-leds-multiple-fixes-and-pwm-fm-support-v3-1-f911edd40a31@oss.qualcomm.com> X-AI-Review-Draft: <20261122-led-qcom-leds-multiple-fixes-and-pwm-fm-support-v3-1-f911edd40a31@oss.qualcomm.com> On Sun, 22 Nov 2026, Fenglin Wu wrote: > 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 whether each channel uses a LUT separately > from the index range. Mark every channel using the shared allocation, > release the bitmap allocation once through the first channel, and clear > the LUT state for all channels during cleanup. > > Also, avoid ping-pong compression for two-step patterns to prevent > programming an unsafe single-entry LUT range. > > Fixes: 24e2d05d1b689 ("leds: Add driver for Qualcomm LPG") > Closes: https://lore.kernel.org/linux-leds/7e474cdf-fcb2-468d-844d-f8afb5976d16@oss.qualcomm.com/ > Signed-off-by: Fenglin Wu > --- > drivers/leds/rgb/leds-qcom-lpg.c | 30 +++++++++++++++++++----------- > 1 file changed, 19 insertions(+), 11 deletions(-) > > diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c > index 24ffe079f221..5a63f3bc5dcf 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 uses 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) > @@ -624,7 +630,7 @@ static void lpg_sdam_apply_lut_control(struct lpg_channel *chan) > unsigned int hi_pause, lo_pause; > struct lpg *lpg = chan->lpg; > > - if (!chan->ramp_enabled || chan->pattern_lo_idx == chan->pattern_hi_idx) > + if (!chan->ramp_enabled || !chan->has_lut) > return; > > hi_pause = DIV_ROUND_UP(chan->ramp_hi_pause_ms, chan->ramp_tick_ms); > @@ -668,7 +674,7 @@ static void lpg_apply_lut_control(struct lpg_channel *chan) > unsigned int hi_idx = chan->pattern_hi_idx; > u16 step = chan->ramp_tick_ms; > > - if (!chan->ramp_enabled || chan->pattern_lo_idx == chan->pattern_hi_idx) > + if (!chan->ramp_enabled || !chan->has_lut) > return; > > hi_pause = DIV_ROUND_UP(chan->ramp_hi_pause_ms, step); > @@ -709,7 +715,7 @@ static void lpg_apply_control(struct lpg_channel *chan) > if (chan->enabled) > ctrl |= LPG_ENABLE_CONTROL_OUTPUT; > > - if (chan->pattern_lo_idx != chan->pattern_hi_idx) > + if (chan->has_lut) > ctrl |= LPG_ENABLE_CONTROL_RAMP_GEN; > else > ctrl |= LPG_ENABLE_CONTROL_SRC_PWM; > @@ -818,7 +824,7 @@ static void lpg_brightness_set(struct lpg_led *led, struct led_classdev *cdev, > if (brightness == LED_OFF) { > chan->enabled = false; > chan->ramp_enabled = false; > - } else if (chan->pattern_lo_idx != chan->pattern_hi_idx) { > + } else if (chan->has_lut) { > lpg_calc_freq(chan, NSEC_PER_MSEC); > lpg_sdam_configure_triggers(chan, 1); > > @@ -1043,7 +1049,7 @@ static int lpg_pattern_set(struct lpg_led *led, struct led_pattern *led_pattern, > */ > > /* Detect palindromes and use "ping pong" to reduce LUT usage */ > - if (lpg->lut_base) { > + if (lpg->lut_base && len > 2) { A concern from AI: Wait, if we are only detecting palindromes when 'len > 2', then 'ping_pong' remains initialized to 'true' for 2-step patterns when 'lpg->lut_base' is set, which still compresses 'actual_len' to 1 right below. Also, once 2-step patterns are never compressed to a single LUT entry, is it ever possible for a valid pattern to have 'pattern_lo_idx == pattern_hi_idx', or is the whole 'has_lut' addition in this patch unnecessary? > for (i = 0; i < len / 2; i++) { > brightness_a = pattern[i].brightness; > brightness_b = pattern[len - i - 1].brightness; > @@ -1118,6 +1124,7 @@ 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; > + chan->has_lut = true; > } > > out_unlock: > @@ -1176,7 +1183,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]; > @@ -1184,6 +1191,7 @@ static int lpg_pattern_clear(struct lpg_led *led) > lpg_clear_pbs_trigger(chan->lpg, chan->lut_mask); > chan->pattern_lo_idx = 0; > chan->pattern_hi_idx = 0; > + chan->has_lut = false; > } > > mutex_unlock(&lpg->lock); > > -- > 2.43.0 > > -- Lee Jones