Linux LED subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: kr494167@gmail.com
Cc: linux-leds@vger.kernel.org, lee@kernel.org
Subject: Re: [PATCH v2] leds: lp5860: fix LED teardown ordering using devm_add_action_or_reset()
Date: Thu, 06 Aug 2026 15:03:08 +0000	[thread overview]
Message-ID: <20260806150309.D22311F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806145527.114844-1-kr494167@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Unconditional self-deadlock during probe due to incorrect lock lifetime using `guard(mutex)`.
- [Low] Undeclared variable `ret` used in `lp5860_probe()`.
--

--- Patch [1]: [PATCH v2] leds: lp5860: fix LED teardown ordering using devm_add_action_or_reset() ---
commit fa14917dcf9d1637bf1292a82596892d65e73078
Author: Surendra Singh Chouhan <kr494167@gmail.com>

leds: lp5860: fix LED teardown ordering using devm_add_action_or_reset()

The driver previously disabled the chip in its remove callback before devres
unregistered the LEDs. This patch fixes the teardown ordering by registering a
devm action to disable the chip, ensuring it happens after LED unregistration.
It also converts mutex initialization to use devm_mutex_init().

> diff --git a/drivers/leds/rgb/leds-lp5860-core.c b/drivers/leds/rgb/leds-lp5860-core.c
> index fd0e2f6e6e0f4..bbe299e36ad53 100644
> --- a/drivers/leds/rgb/leds-lp5860-core.c
> +++ b/drivers/leds/rgb/leds-lp5860-core.c
[ ... ]
> @@ -197,38 +204,24 @@ int lp5860_device_init(struct device *dev)
>  	if (ret)
>  		return ret;
>  
> +	ret = devm_add_action_or_reset(dev, lp5860_disable_action, lp);
> +	if (ret)
> +		return ret;
> +
>  	/*
>  	 * Set to 8-bit PWM data without VSYNC.
>  	 * Data is sent out for display instantly after received.
>  	 */
> -	mutex_lock(&lp->lock);
> +	guard(mutex)(&lp->lock);
>  	ret = regmap_update_bits(lp->regmap, LP5860_REG_DEV_INITIAL, LP5860_MODE_MASK,
>  				 LP5860_MODE_1 << LP5860_MODE_SHIFT);
>  	if (ret)
> -		goto err_disable;
> -	mutex_unlock(&lp->lock);
> -
> -	ret = lp5860_init_dt(lp);
> -	if (ret)
> -		goto err_disable;
> -
> -	return 0;
> +		return ret;
>  
> -err_disable:
> -	mutex_unlock(&lp->lock);
> -	lp5860_chip_enable(lp, LP5860_CHIP_DISABLE);
> -	return ret;
> +	return lp5860_init_dt(lp);

[Severity: High]
Does this code introduce a self-deadlock during probe?

By replacing the explicit mutex_lock/unlock with guard(mutex), the lock
lifetime is extended to the end of lp5860_device_init(). This means the
lock is held while calling lp5860_init_dt().

However, lp5860_init_dt() eventually calls lp5860_set_mc_brightness(),
which attempts to acquire the exact same lock:

drivers/leds/rgb/leds-lp5860-core.c:lp5860_set_mc_brightness() {
    ...
    guard(mutex)(&led->chip->lock);
    ...
}

Since Linux mutexes are non-recursive, will this cause an unconditional
deadlock during initialization?

>  }
>  EXPORT_SYMBOL_GPL(lp5860_device_init);
>  
> diff --git a/drivers/leds/rgb/leds-lp5860-spi.c b/drivers/leds/rgb/leds-lp5860-spi.c
> index 5e0c44854a680..13ad90362d5f0 100644
> --- a/drivers/leds/rgb/leds-lp5860-spi.c
> +++ b/drivers/leds/rgb/leds-lp5860-spi.c
[ ... ]
> @@ -61,22 +61,15 @@ static int lp5860_probe(struct spi_device *spi)
>  				     "Failed to initialise Regmap.\n");
>  
>  	lp5860->dev = dev;
> -	mutex_init(&lp5860->lock);
> +	ret = devm_mutex_init(dev, &lp5860->lock);
> +	if (ret)
> +		return ret;

[Severity: Low]
Is the ret variable declared in lp5860_probe()?

It looks like the local variable ret was never declared in this function,
which will cause a build failure.

>  
>  	spi_set_drvdata(spi, lp5860);
>  
>  	return lp5860_device_init(dev);
>  }

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

  reply	other threads:[~2026-08-06 15:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 14:55 [PATCH v2] leds: lp5860: fix LED teardown ordering using devm_add_action_or_reset() kr494167
2026-08-06 15:03 ` sashiko-bot [this message]
2026-08-12 11:49   ` Lee Jones

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=20260806150309.D22311F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kr494167@gmail.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