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=1796135084; b=ZAsbfUjZh3b8Y2leZjlqowIzV4IiIC905LfrcJiu56e8fiqjSeAxh49QwHdT6vjc69k9 2BETlABxjosIfXex+VHc8RDZ2zjYDIzg/zKIrR3hFssJCJ2H9B+o+Hr81fUTpe5dL0Hl3 EskkMe1Wajpfjbp2csaY5hBO3oRu8T27M5dwDRvFzmrepe2HWD2pc/rkcWVOgjYIV7CQ7 r1/H1Un1rBR0wAzo2CthuDRADFnUh51hyYsQVkckwMyOQ5p9jfnKM5j4Rx4DyJmwLD3Aa bMR7Hub/c5+yCO79Z7ObLKwmss3Agd+RTMDd1ApaHAX6/r4bs1uWqD6EQ5otV2975Tg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796135084; 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=GjNe6nMUgbOnzoYNv5sibqwSM/ZqOqflfZE3NItAPq8=; b=ndPEeeut4tq8+ZmLOmMoYmOF3/iePEw3rC7DywoTvvL+MnAKt1GZEBdUOYi9IvbadZOU jWcU78qOQ28KV9ItCHjDXeBGyy8jnU5Eftpur4AL78wFEP5tIbOSaid38T4tR91USTCQj U04b5SKx+4bP0ucMDy7IuUwVMrbxsEkRuJfO5T9Mb1SpmADhgtNIRq8Rfh6eCwSJFjsbO axmaVWERr4NpCd/sCmILj7G5Zy2x9yDBSWW7468GoK5kB0bNQ58KslDgUGr9+bbVapRhF gp1mIrdSrPBitvdFGad6PRMZbQNUTW55equ7aLKfvGnCACdZQvNZC1/wDyt/4cHbMdQ== 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=bpLmY5hr; 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 7A300606A31A; Tue, 1 Dec 2026 14:24:44 +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=bpLmY5hr Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC1161F000C1; Tue, 1 Dec 2026 14:24:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796135083; bh=GjNe6nMUgbOnzoYNv5sibqwSM/ZqOqflfZE3NItAPq8=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=bpLmY5hrBPYRv1FdTZqs90fzamuwNp8imiYCBJo9fpESZGrSZMKiFQA54ek5mj7M2 NRvHq7DOWVT9ekACVwvTgO9q6MhHW7ONYN/JMYtwqoYD4M5l4A5FCvqy100QoAC1ZS S4sGWwnAsLsoqnoGGy09A0tYAofeqW21lTztBT53p9bNXoYl3nHGIx0F5Zj7clk/LW s47ZKnMvJzGSzrB0VvfDT+ejWq1+YoQe00RvpHtTpFdZMNTMv0BsZyg+REpL7ymn9B aErdBlQSLaGVxemBi5go2/TrvrfF3/2mvlDzzMP0ElWIFZpJVvD/AG3q/njHwkJp1A egrZK3+9u4+cA== Date: Tue, 1 Dec 2026 14:24:37 +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 2/4] leds: rgb: leds-qcom-lpg: Fix LED color balancing in HW pattern mode Message-ID: <179568561811.32537.12779758747288611716@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-2-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-2-f911edd40a31@oss.qualcomm.com> X-AI-Review-Draft: <20261122-led-qcom-leds-multiple-fixes-and-pwm-fm-support-v3-2-f911edd40a31@oss.qualcomm.com> On Sun, 22 Nov 2026, Fenglin Wu wrote: > The multicolor hardware-pattern path has two related issues. > > First, lpg_pattern_set() programs one unscaled LUT and assigns it to > every LPG channel. RGB and multicolor LEDs therefore replay identical > brightness values regardless of multi_intensity, making the output > white-balanced rather than preserving the requested color. > > Fix this by normalizing the requested pattern once, scaling its > brightness values for each enabled sub-LED, and allocating and > programming a separate LUT range for every active LPG channel. Stop the > channels before replacing or releasing their LUTs, and roll back all > per-channel allocations if an update fails. > > Second, a pattern is scaled only when it is installed. Updating > brightness or multi_intensity while it is active leaves already-enabled > channels with stale LUT values. A channel that was disabled when the > pattern was installed has no LUT and falls back to static PWM when it is > enabled later. > > Fix this by caching the normalized, unscaled pattern and repeat state. > On each multicolor brightness callback, stop the running pattern, > release its per-channel LUTs, rebuild them from the current sub-LED > intensities, and restart the active channels. Clear the cached active > state when the pattern is removed. > > The second issue was identified and fixed by OpenAI Codex when I used > it to review the original change. > > Both of the fixes have been tested on a Maili QRD device and confirmed > that the HW pattern of a multicolor LED could be scaled and refreshed > correctly whenever hw_pattern, brightness, multi_intensity were updated. > > Fixes: 24e2d05d1b68 ("leds: Add driver for Qualcomm LPG") > Fixes: 6ab1f766a80a ("leds: rgb: leds-qcom-lpg: Add support for PPG through single SDAM") > Fixes: 5e9ff626861a ("leds: rgb: leds-qcom-lpg: Include support for PPG with dedicated LUT SDAM") > Signed-off-by: Fenglin Wu > --- > Documentation/leds/leds-qcom-lpg.rst | 9 + > drivers/leds/rgb/leds-qcom-lpg.c | 324 ++++++++++++++++++++++++++++------- > 2 files changed, 275 insertions(+), 58 deletions(-) > > diff --git a/Documentation/leds/leds-qcom-lpg.rst b/Documentation/leds/leds-qcom-lpg.rst > index d6a76c38c581..e83d8dde7eab 100644 > --- a/Documentation/leds/leds-qcom-lpg.rst > +++ b/Documentation/leds/leds-qcom-lpg.rst > @@ -39,6 +39,15 @@ described below). As the LPG hardware is not able to perform the linear > transitions expected by the leds-trigger-pattern format, each entry in the > pattern must be followed a zero-length entry of the same brightness. > > +For multicolor LEDs, each pattern brightness value is scaled by the component > +brightness calculated from the global ``brightness`` and ``multi_intensity`` > +values. A component whose calculated brightness is zero does not have a LUT > +range allocated. Consequently, if ``hw_pattern`` is configured while global > +brightness is zero, the pattern is cached but no LUT range is programmed until > +a brightness or intensity update produces a nonzero component brightness. > +Changing either value while a hardware pattern is active rebuilds the > +per-component LUT ranges. > + > Simple pattern:: > > "255 500 255 0 0 500 0 0" > diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c > index 5a63f3bc5dcf..eec942f2af6c 100644 > --- a/drivers/leds/rgb/leds-qcom-lpg.c > +++ b/drivers/leds/rgb/leds-qcom-lpg.c > @@ -151,11 +151,32 @@ struct lpg_channel { > bool has_lut; > }; > > +/** > + * struct lpg_pattern - The LPG pattern normalized from the LED pattern > + * @data: The pattern data array > + * @len: number of entries to write to the LUT > + * @delta_t: common step duration in ms > + * @lo_pause: low-pause duration in ms > + * @hi_pause: high-pause duration in ms > + * @ping_pong: true if the pattern support reverse > + */ > +struct lpg_pattern { > + struct led_pattern *data; > + unsigned int len; > + unsigned int delta_t; > + unsigned int lo_pause; > + unsigned int hi_pause; > + bool ping_pong; > +}; > + > /** > * struct lpg_led - logical LED object > * @lpg: lpg context reference > * @cdev: LED class device > * @mcdev: Multicolor LED class device > + * @pattern: unscaled active multicolor pattern; zero length when inactive > + * @scaled_pattern: scratch buffer for per-channel LUT updates > + * @pattern_oneshot: whether the cached pattern is played only once > * @channels: list of channels associated with the LED > * @num_channels: number of @channels > */ > @@ -164,6 +185,9 @@ struct lpg_led { > > struct led_classdev cdev; > struct led_classdev_mc mcdev; > + struct lpg_pattern pattern; > + struct led_pattern *scaled_pattern; > + bool pattern_oneshot; > > unsigned int num_channels; > struct lpg_channel *channels[] __counted_by(num_channels); > @@ -179,6 +203,7 @@ struct lpg_led { > * @lut_base: base address of the LUT block (optional) > * @lut_size: number of entries in the LUT block > * @lut_bitmap: allocation bitmap for LUT entries > + * @lut_bitmap_tmp: scratch bitmap for LUT allocation preflight > * @pbs_dev: PBS device > * @lpg_chan_sdam: LPG SDAM peripheral device > * @lut_sdam: LUT SDAM peripheral device > @@ -203,6 +228,7 @@ struct lpg { > u32 lut_base; > u32 lut_size; > unsigned long *lut_bitmap; > + unsigned long *lut_bitmap_tmp; > > struct pbs_dev *pbs_dev; > struct nvmem_device *lpg_chan_sdam; > @@ -876,18 +902,25 @@ static int lpg_brightness_single_set(struct led_classdev *cdev, > return 0; > } > > +static int lpg_pattern_mc_update(struct lpg_led *led); No forward declarations please. Didn't we already discuss this? > static int lpg_brightness_mc_set(struct led_classdev *cdev, > enum led_brightness value) > { > struct led_classdev_mc *mc = lcdev_to_mccdev(cdev); > struct lpg_led *led = container_of(mc, struct lpg_led, mcdev); > + int ret = 0; > > - mutex_lock(&led->lpg->lock); > + guard(mutex)(&led->lpg->lock); > > led_mc_calc_color_components(mc, value); > - lpg_brightness_set(led, cdev, mc->subled_info); > + if (led->pattern.len) { > + ret = lpg_pattern_mc_update(led); > + if (ret) > + return ret; > + } > > - mutex_unlock(&led->lpg->lock); > + lpg_brightness_set(led, cdev, mc->subled_info); > > return 0; > } > @@ -966,23 +999,16 @@ static int lpg_blink_mc_set(struct led_classdev *cdev, > return ret; > } > > -static int lpg_pattern_set(struct lpg_led *led, struct led_pattern *led_pattern, > - u32 len, int repeat) > +static int lpg_prepare_pattern(struct lpg *lpg, > + struct led_pattern *led_pattern, u32 len, > + int repeat, struct lpg_pattern *prep) > { > - struct lpg_channel *chan; > - struct lpg *lpg = led->lpg; > - struct led_pattern *pattern; > unsigned int brightness_a; > unsigned int brightness_b; > - unsigned int hi_pause = 0; > - unsigned int lo_pause = 0; > unsigned int actual_len; > unsigned int delta_t; > - unsigned int lo_idx; > - unsigned int hi_idx; > unsigned int i; > bool ping_pong = true; > - int ret = -EINVAL; > > /* Hardware only support oneshot or indefinite loops */ > if (repeat != -1 && repeat != 1) > @@ -1002,15 +1028,16 @@ static int lpg_pattern_set(struct lpg_led *led, struct led_pattern *led_pattern, > if (len % 2) > return -EINVAL; > > - pattern = kzalloc_objs(*pattern, len / 2); > + struct led_pattern *pattern __free(kfree) = kzalloc_objs(*pattern, len / 2); > + > if (!pattern) > return -ENOMEM; > > for (i = 0; i < len; i += 2) { > if (led_pattern[i].brightness != led_pattern[i + 1].brightness) > - goto out_free_pattern; > + return -EINVAL; > if (led_pattern[i + 1].delta_t != 0) > - goto out_free_pattern; > + return -EINVAL; > > pattern[i / 2].brightness = led_pattern[i].brightness; > pattern[i / 2].delta_t = led_pattern[i].delta_t; > @@ -1023,7 +1050,7 @@ static int lpg_pattern_set(struct lpg_led *led, struct led_pattern *led_pattern, > * through the entire LUT, so prohibit this. > */ > if (len < 2) > - goto out_free_pattern; > + return -EINVAL; > > /* > * The LPG plays patterns with at a fixed pace, a "low pause" can be > @@ -1080,13 +1107,13 @@ static int lpg_pattern_set(struct lpg_led *led, struct led_pattern *led_pattern, > * specify hi pause. Reject other variations. > */ > if (i != actual_len - 1) > - goto out_free_pattern; > + return -EINVAL; > } > } > > /* LPG_RAMP_DURATION_REG is a 9bit */ > if (delta_t >= BIT(9)) > - goto out_free_pattern; > + return -EINVAL; > > /* > * Find "low pause" and "high pause" in the pattern in the LUT case. > @@ -1094,44 +1121,65 @@ static int lpg_pattern_set(struct lpg_led *led, struct led_pattern *led_pattern, > * duration of all steps. > */ > if (lpg->lut_base || lpg->lut_sdam) { > - lo_pause = pattern[0].delta_t; > - hi_pause = pattern[actual_len - 1].delta_t; > + prep->lo_pause = pattern[0].delta_t; > + prep->hi_pause = pattern[actual_len - 1].delta_t; > } else { > if (delta_t != pattern[0].delta_t || delta_t != pattern[actual_len - 1].delta_t) > - goto out_free_pattern; > + return -EINVAL; > + prep->lo_pause = 0; > + prep->hi_pause = 0; > } > > + prep->data = no_free_ptr(pattern); > + prep->len = actual_len; > + prep->delta_t = delta_t; > + prep->ping_pong = ping_pong; > > - mutex_lock(&lpg->lock); > + return 0; > +} > + > +static int lpg_pattern_set(struct lpg_led *led, struct led_pattern *led_pattern, > + u32 len, int repeat) > +{ > + struct lpg_channel *chan; > + struct lpg *lpg = led->lpg; > + struct lpg_pattern pattern; > + unsigned int lo_idx; > + unsigned int hi_idx; > + unsigned int i; > + int ret; > + > + ret = lpg_prepare_pattern(lpg, led_pattern, len, repeat, &pattern); > + if (ret < 0) >From v1: if (ret)? > + return ret; > + > + struct led_pattern *prep_data __free(kfree) = pattern.data; > + > + guard(mutex)(&lpg->lock); > > if (lpg->lut_base) > - ret = lpg_lut_store(lpg, pattern, actual_len, &lo_idx, &hi_idx); > + ret = lpg_lut_store(lpg, prep_data, pattern.len, &lo_idx, &hi_idx); > else > - ret = lpg_lut_store_sdam(lpg, pattern, actual_len, &lo_idx, &hi_idx); > + ret = lpg_lut_store_sdam(lpg, prep_data, pattern.len, &lo_idx, &hi_idx); > > if (ret < 0) > - goto out_unlock; > + return ret; > > for (i = 0; i < led->num_channels; i++) { > chan = led->channels[i]; > > - chan->ramp_tick_ms = delta_t; > - chan->ramp_ping_pong = ping_pong; > + chan->ramp_tick_ms = pattern.delta_t; > + chan->ramp_ping_pong = pattern.ping_pong; > chan->ramp_oneshot = repeat != -1; > > - chan->ramp_lo_pause_ms = lo_pause; > - chan->ramp_hi_pause_ms = hi_pause; > + chan->ramp_lo_pause_ms = pattern.lo_pause; > + chan->ramp_hi_pause_ms = pattern.hi_pause; > > chan->pattern_lo_idx = lo_idx; > chan->pattern_hi_idx = hi_idx; > chan->has_lut = true; > } > > -out_unlock: > - mutex_unlock(&lpg->lock); > -out_free_pattern: > - kfree(pattern); > - > return ret; > } > > @@ -1151,50 +1199,196 @@ static int lpg_pattern_single_set(struct led_classdev *cdev, > return 0; > } > > -static int lpg_pattern_mc_set(struct led_classdev *cdev, > - struct led_pattern *pattern, u32 len, > - int repeat) > +/* Caller must hold lpg->lock. Stop all readers before releasing their LUTs. */ > +static int lpg_pattern_stop(struct lpg_led *led) > { > - struct led_classdev_mc *mc = lcdev_to_mccdev(cdev); > - struct lpg_led *led = container_of(mc, struct lpg_led, mcdev); > + struct lpg *lpg = led->lpg; > + struct lpg_channel *chan; > unsigned int triled_mask = 0; > - int ret, i; > + unsigned int i; > + int ret; > > for (i = 0; i < led->num_channels; i++) > triled_mask |= led->channels[i]->triled_mask; > - triled_set(led->lpg, triled_mask, 0); > - > - ret = lpg_pattern_set(led, pattern, len, repeat); > - if (ret < 0) > + ret = triled_set(lpg, triled_mask, 0); > + if (ret) > return ret; > > - led_mc_calc_color_components(mc, LED_FULL); > - lpg_brightness_set(led, cdev, mc->subled_info); > + for (i = 0; i < led->num_channels; i++) { > + chan = led->channels[i]; > + ret = lpg_sdam_configure_triggers(chan, 0); > + if (ret < 0) As above, etc. Below too: > + return ret; > + ret = regmap_update_bits(lpg->map, chan->base + PWM_ENABLE_CONTROL_REG, > + LPG_ENABLE_CONTROL_OUTPUT | > + LPG_ENABLE_CONTROL_RAMP_GEN, 0); > + if (ret) > + return ret; > + ret = lpg_clear_pbs_trigger(lpg, chan->lut_mask); > + if (ret) > + return ret; > + > + chan->enabled = false; > + chan->ramp_enabled = false; > + } > > return 0; > } > > -static int lpg_pattern_clear(struct lpg_led *led) > +/* Caller must hold lpg->lock. */ > +static int lpg_pattern_mc_preflight(struct lpg_led *led) > { > + struct led_classdev_mc *mc = &led->mcdev; > + struct lpg_pattern *pattern = &led->pattern; > + struct lpg *lpg = led->lpg; > struct lpg_channel *chan; > + unsigned int idx; > + unsigned int i; > + int len; > + > + bitmap_copy(lpg->lut_bitmap_tmp, lpg->lut_bitmap, lpg->lut_size); > + > + for (i = 0; i < led->num_channels; i++) { > + chan = led->channels[i]; > + if (!chan->has_lut) > + continue; > + > + len = chan->pattern_hi_idx - chan->pattern_lo_idx + 1; > + bitmap_clear(lpg->lut_bitmap_tmp, chan->pattern_lo_idx, len); > + } > + > + for (i = 0; i < led->num_channels; i++) { > + if (!mc->subled_info[i].brightness) > + continue; > + > + idx = bitmap_find_next_zero_area(lpg->lut_bitmap_tmp, lpg->lut_size, > + 0, pattern->len, 0); > + if (idx >= lpg->lut_size) > + return lpg->lut_base ? -ENOMEM : -ENOSPC; > + > + bitmap_set(lpg->lut_bitmap_tmp, idx, pattern->len); > + } > + > + return 0; > +} > + > +/* Caller must hold lpg->lock. */ > +static int lpg_pattern_mc_update(struct lpg_led *led) > +{ > + struct led_classdev_mc *mc = &led->mcdev; > + struct led_classdev *cdev = &mc->led_cdev; > + struct lpg_pattern *pattern = &led->pattern; > + struct led_pattern *scaled = led->scaled_pattern; > struct lpg *lpg = led->lpg; > - int i; > + struct lpg_channel *chan; > + unsigned int lo_idx, hi_idx; > + unsigned int i, j; > + int ret; > > - mutex_lock(&lpg->lock); > + ret = lpg_pattern_mc_preflight(led); > + if (ret) > + return ret; > > - chan = led->channels[0]; > - lpg_lut_free(chan); > + ret = lpg_pattern_stop(led); > + if (ret) > + return ret; > + > + for (i = 0; i < led->num_channels; i++) > + lpg_lut_free(led->channels[i]); > > for (i = 0; i < led->num_channels; i++) { > chan = led->channels[i]; > - lpg_sdam_configure_triggers(chan, 0); > - lpg_clear_pbs_trigger(chan->lpg, chan->lut_mask); > - chan->pattern_lo_idx = 0; > - chan->pattern_hi_idx = 0; > - chan->has_lut = false; > + > + /* Ignore pattern config for 0 brightness channel */ > + if (!mc->subled_info[i].brightness) > + continue; > + > + /* Rebuild the pattern based on component brightness. */ > + for (j = 0; j < pattern->len; j++) { > + scaled[j].brightness = > + DIV_ROUND_CLOSEST((u32)pattern->data[j].brightness * > + mc->subled_info[i].brightness, > + cdev->max_brightness); > + scaled[j].delta_t = pattern->data[j].delta_t; > + } > + > + if (lpg->lut_base) > + ret = lpg_lut_store(lpg, scaled, pattern->len, &lo_idx, &hi_idx); > + else > + ret = lpg_lut_store_sdam(lpg, scaled, pattern->len, &lo_idx, &hi_idx); > + if (ret < 0) > + goto out_free; > + > + chan->ramp_tick_ms = pattern->delta_t; > + chan->ramp_ping_pong = pattern->ping_pong; > + chan->ramp_oneshot = led->pattern_oneshot; > + chan->ramp_lo_pause_ms = pattern->lo_pause; > + chan->ramp_hi_pause_ms = pattern->hi_pause; > + chan->pattern_lo_idx = lo_idx; > + chan->pattern_hi_idx = hi_idx; > + chan->has_lut = true; > } > > - mutex_unlock(&lpg->lock); > + return 0; > + > +out_free: > + for (i = 0; i < led->num_channels; i++) > + lpg_lut_free(led->channels[i]); > + return ret; > +} > + > +static int lpg_pattern_mc_set(struct led_classdev *cdev, > + struct led_pattern *led_pattern, u32 len, > + int repeat) > +{ > + struct led_classdev_mc *mc = lcdev_to_mccdev(cdev); > + struct lpg_led *led = container_of(mc, struct lpg_led, mcdev); > + struct lpg *lpg = led->lpg; > + struct lpg_pattern pattern; > + int ret; > + > + ret = lpg_prepare_pattern(lpg, led_pattern, len, repeat, &pattern); > + if (ret < 0) > + return ret; > + > + struct led_pattern *prep_data __free(kfree) = pattern.data; > + > + if (pattern.len > lpg->lut_size) > + return -EINVAL; > + > + guard(mutex)(&lpg->lock); > + > + memcpy(led->pattern.data, prep_data, pattern.len * sizeof(*prep_data)); > + pattern.data = led->pattern.data; > + led->pattern = pattern; > + led->pattern_oneshot = repeat != -1; > + > + ret = lpg_pattern_mc_update(led); > + if (ret) { > + led->pattern.len = 0; > + return ret; > + } > + > + lpg_brightness_set(led, cdev, mc->subled_info); > + > + return 0; > +} > + > +static int lpg_pattern_clear(struct lpg_led *led) > +{ > + struct lpg *lpg = led->lpg; > + unsigned int i; > + int ret; > + > + guard(mutex)(&lpg->lock); > + > + ret = lpg_pattern_stop(led); > + if (ret) > + return ret; > + > + for (i = 0; i < led->num_channels; i++) > + lpg_lut_free(led->channels[i]); > + led->pattern.len = 0; > > return 0; > } > @@ -1433,6 +1627,17 @@ static int lpg_add_led(struct lpg *lpg, struct fwnode_handle *fw) > > /* Register pattern accessors if we have a LUT block or when using PPG */ > if (lpg->lut_base || lpg->lpg_chan_sdam) { > + led->pattern.data = devm_kcalloc(lpg->dev, lpg->lut_size, > + sizeof(*led->pattern.data), GFP_KERNEL); > + if (!led->pattern.data) > + return -ENOMEM; > + > + led->scaled_pattern = devm_kcalloc(lpg->dev, lpg->lut_size, > + sizeof(*led->scaled_pattern), > + GFP_KERNEL); > + if (!led->scaled_pattern) > + return -ENOMEM; > + > cdev->pattern_set = lpg_pattern_mc_set; > cdev->pattern_clear = lpg_pattern_mc_clear; > } > @@ -1549,6 +1754,9 @@ static int lpg_init_lut(struct lpg *lpg) > lpg->lut_bitmap = devm_bitmap_zalloc(lpg->dev, lpg->lut_size, GFP_KERNEL); > if (!lpg->lut_bitmap) > return -ENOMEM; > + lpg->lut_bitmap_tmp = devm_bitmap_zalloc(lpg->dev, lpg->lut_size, GFP_KERNEL); > + if (!lpg->lut_bitmap_tmp) > + return -ENOMEM; > > return 0; > } > > -- > 2.43.0 > > -- Lee Jones