Linux LED subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Volodymyr Chapman" <volodymyrchapman@gmail.com>
Cc: linux-leds@vger.kernel.org, lee@kernel.org
Subject: Re: [PATCH] leds: flash: Add driver for the TI LM3554
Date: Mon, 16 Nov 2026 18:29:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-217499@kernel.org> (raw)
In-Reply-To: <20261116180809.26946-1-volodymyrchapman@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] leds: lm3554: torch state desynchronization in
  lm3554_strobe_set()
- [Medium] leds: lm3554: enable GPIO left high on regmap init failure in
  lm3554_probe()
- [Low] leds: lm3554: unupdated brightness.val in
  lm3554_flash_brightness_set()
--

commit 4af70dcd92412fb10987222afa3600daf61a796e
Author: Volodymyr Chapman <volodymyrchapman@gmail.com>

leds: flash: Add driver for the TI LM3554

This commit adds an I2C flash LED class driver for the Texas Instruments
LM3554 flash LED controller used on the Lenovo ThinkPad 10.

> diff --git a/drivers/leds/flash/leds-lm3554.c b/drivers/leds/flash/leds-lm3554.c
> new file mode 100644
> index 0000000000000..70c526df35827
> --- /dev/null
> +++ b/drivers/leds/flash/leds-lm3554.c

[ ... ]

> +static int lm3554_flash_brightness_set(struct led_classdev_flash *fled_cdev,
> +				       u32 brightness)
> +{
> +	struct lm3554 *lm3554 = fled_cdev_to_lm3554(fled_cdev);
> +	unsigned int i;
> +
> +	/* Use the highest setting which does not exceed the requested current */
> +	for (i = ARRAY_SIZE(lm3554_flash_ua) - 1; i > 0; i--)
> +		if (lm3554_flash_ua[i] <= brightness)
> +			break;
> +
> +	guard(mutex)(&lm3554->lock);
> +
> +	return regmap_update_bits(lm3554->regmap, LM3554_REG_FLASH,
> +				  LM3554_FLASH_CURRENT,
> +				  FIELD_PREP(LM3554_FLASH_CURRENT, i));
> +}

[Severity: Low]
Should lm3554_flash_brightness_set() also update fled_cdev->brightness.val
to lm3554_flash_ua[i]?

Because lm3554_probe() sets fled_cdev.brightness.step to 1 and
lm3554_flash_ops does not implement flash_brightness_get, led_clamp_align()
leaves fled_cdev->brightness.val at the unrounded value written by
userspace, so reading flash_brightness from sysfs returns the requested
microamp value rather than the discrete current programmed into the chip.

[ ... ]

> +static int lm3554_strobe_set(struct led_classdev_flash *fled_cdev, bool state)
> +{
> +	struct lm3554 *lm3554 = fled_cdev_to_lm3554(fled_cdev);
> +	unsigned int flags;
> +	int ret;
> +
> +	guard(mutex)(&lm3554->lock);
> +
> +	if (!state)
> +		return lm3554_set_mode(lm3554, LM3554_MODE_SHUTDOWN);
> +
> +	/* Clear old flags, the timeout flag would otherwise stay set */
> +	ret = regmap_read(lm3554->regmap, LM3554_REG_FLAGS, &flags);
> +	if (ret)
> +		return ret;
> +
> +	return lm3554_set_mode(lm3554, LM3554_MODE_FLASH);
> +}

[Severity: Medium]
Can writing flash_strobe while the torch is active leave
fled_cdev->led_cdev.brightness out of sync with the hardware state?

LM3554_MODE is shared between shutdown, torch and flash modes.  Calling
lm3554_strobe_set() while the torch is on turns the torch off (immediately
when state is false, or when the flash timeout expires and clears the mode
bits to shutdown when state is true), but led_cdev.brightness remains
non-zero.  Sysfs brightness reads then report the stale torch level while
the LED is off, and a subsequent suspend/resume cycle via
LED_CORE_SUSPENDRESUME restores led_cdev.brightness and turns the torch
back on.

[ ... ]

> +	lm3554->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH);
> +	if (IS_ERR(lm3554->enable_gpio))
> +		return dev_err_probe(dev, PTR_ERR(lm3554->enable_gpio),
> +				     "getting enable GPIO\n");
> +
> +	lm3554->regmap = devm_regmap_init_i2c(client, &lm3554_regmap_config);
> +	if (IS_ERR(lm3554->regmap))
> +		return PTR_ERR(lm3554->regmap);
> +
> +	ret = devm_add_action_or_reset(dev, lm3554_power_off, lm3554);

[Severity: Medium]
Does an error from devm_regmap_init_i2c() leave enable_gpio asserted high?

devm_gpiod_get() drives enable_gpio high before devm_regmap_init_i2c(),
while lm3554_power_off() is only registered afterwards.  If
devm_regmap_init_i2c() fails, devres releases the GPIO descriptor without
driving the line low, leaving the chip powered on.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116180809.26946-1-volodymyrchapman@gmail.com?part=1

      reply	other threads:[~2026-11-16 18:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 18:08 [PATCH] leds: flash: Add driver for the TI LM3554 Volodymyr Chapman
2026-11-16 18:29 ` sashiko-bot [this message]

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-217499@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=volodymyrchapman@gmail.com \
    /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