Linux LED subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fenglin Wu" <fenglin.wu@oss.qualcomm.com>
Cc: linux-leds@vger.kernel.org, lee@kernel.org
Subject: Re: [PATCH 2/4] leds: rgb: leds-qcom-lpg: Fix LED color balancing in HW pattern mode
Date: Tue, 17 Nov 2026 09:50:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-218529@kernel.org> (raw)
In-Reply-To: <20261117-led-qcom-leds-multiple-fixes-and-pwm-fm-support-v1-2-7a862240683f@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] leds: qcom-lpg: unupdated brightness in lpg_pattern_mc_set()
  stops pattern
- [Medium] leds: qcom-lpg: lpg_pattern_mc_update() scales LUTs by
  intensity not brightness
--

commit a4d32f1ef168124af51072d5038cd7e0df021524
Author: Fenglin Wu <fenglin.wu@oss.qualcomm.com>

leds: rgb: leds-qcom-lpg: Fix LED color balancing in HW pattern mode

This commit scales multicolor hardware patterns per LPG channel and caches
the normalized pattern so per-channel LUTs can be rebuilt when brightness
or multi_intensity changes.

> diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c
> index e14a3316bf221..175b3680766f1 100644
> --- a/drivers/leds/rgb/leds-qcom-lpg.c
> +++ b/drivers/leds/rgb/leds-qcom-lpg.c
[ ... ]
> @@ -876,18 +900,25 @@ static int lpg_brightness_single_set(struct led_classdev *cdev,
>  	return 0;
>  }
>  
> +static int lpg_pattern_mc_update(struct lpg_led *led);
> +
>  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;
>  }
[ ... ]
> @@ -1152,24 +1197,133 @@ static int lpg_pattern_single_set(struct led_classdev *cdev,
[ ... ]
> +/* 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;
> +	struct lpg_channel *chan;
> +	unsigned int lo_idx, hi_idx;
> +	unsigned int i, j;
> +	int ret;
> +
> +	ret = lpg_pattern_stop(led);
> +	if (ret)
> +		return ret;
> +
> +	for (i = 0; i < led->num_channels; i++)
> +		lpg_lut_free(led->channels[i]);
> +
> +	/* Rebuild each channel from the unscaled pattern and current intensity. */
> +	for (i = 0; i < led->num_channels; i++) {
> +		chan = led->channels[i];
> +		if (!mc->subled_info[i].brightness)
> +			continue;
> +
> +		for (j = 0; j < pattern->len; j++) {
> +			scaled[j].brightness = DIV_ROUND_CLOSEST(
> +				(u32)pattern->data[j].brightness * mc->subled_info[i].intensity,
> +				cdev->max_brightness);
> +			scaled[j].delta_t = pattern->data[j].delta_t;
> +		}

[Severity: Medium]
Should scaled[j].brightness multiply by mc->subled_info[i].brightness
instead of mc->subled_info[i].intensity?

When lpg_brightness_mc_set() runs, led_mc_calc_color_components() stores
the brightness-adjusted channel values in mc->subled_info[i].brightness,
leaving mc->subled_info[i].intensity unchanged.  Using .intensity here
means changing brightness while a pattern is active never scales the
programmed LUT values; instead, channels stay at full intensity until
mc->subled_info[i].brightness rounds down to 0 and abruptly shuts the
channel off, skewing the color balance.

[ ... ]
> +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;
> +
>  	led_mc_calc_color_components(mc, LED_FULL);
> +	ret = lpg_pattern_mc_update(led);
> +	if (ret) {
> +		led->pattern.len = 0;
> +		return ret;
> +	}
> +
>  	lpg_brightness_set(led, cdev, mc->subled_info);
>  
>  	return 0;
>  }

[Severity: High]
Does leaving cdev->brightness at 0 in lpg_pattern_mc_set() cause a later
multi_intensity write to stop the running pattern?

cdev->brightness is set to 0 when the pattern trigger activates (or at
probe when default-state is not "on"), and pattern_trig_start_pattern() ->
lpg_pattern_mc_set() never updates it.  If userspace then writes to
multi_intensity while the pattern is running, multi_intensity_store()
calls led_set_brightness(cdev, cdev->brightness) with 0, which invokes
lpg_brightness_mc_set(cdev, 0), zeroes every mc->subled_info[i].brightness,
frees all per-channel LUTs in lpg_pattern_mc_update(), and disables all
channels.

Also, on LUT-backed LPG hardware where cdev->max_brightness is 511
(LPG_RESOLUTION_9BIT - 1), passing LED_FULL (255) instead of
cdev->max_brightness to led_mc_calc_color_components() rounds
mc->subled_info[i].brightness down to 0 when intensity is 1, leaving that
channel disabled.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-led-qcom-leds-multiple-fixes-and-pwm-fm-support-v1-0-7a862240683f@oss.qualcomm.com?part=2

  reply	other threads:[~2026-11-17  9:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17  9:31 [PATCH 0/4] leds: leds-qcom-lpg: Add several fixes and the PWM frequency mode support Fenglin Wu
2026-11-17  9:31 ` [PATCH 1/4] leds: rgb: leds-qcom-lpg: Fix single-entry LUT leak Fenglin Wu
2026-11-17  9:46   ` sashiko-bot
2026-11-17  9:31 ` [PATCH 2/4] leds: rgb: leds-qcom-lpg: Fix LED color balancing in HW pattern mode Fenglin Wu
2026-11-17  9:50   ` sashiko-bot [this message]
2026-11-17  9:31 ` [PATCH 3/4] leds: rgb: leds-qcom-lpg: add mutex lock in lpg_pwm_get_state() Fenglin Wu
2026-11-17  9:40   ` sashiko-bot
2026-11-17  9:31 ` [PATCH 4/4] leds: rgb: leds-qcom-lpg: Add PWM frequency mode support Fenglin Wu
2026-11-17  9:51   ` sashiko-bot

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=sashiko-outbox-218529@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=fenglin.wu@oss.qualcomm.com \
    --cc=lee@kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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