mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: Nora Schiffer <nora.schiffer@ew.tq-group.com>
Cc: Pavel Machek <pavel@kernel.org>, Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Isai Gaspar <isaiezequiel.gaspar@nxp.com>,
	Marek Vasut <marex@denx.de>,
	Pieterjan Camerlynck <pieterjanca@gmail.com>,
	Javier Carrasco <javier.carrasco.cruz@gmail.com>,
	linux@ew.tq-group.com, linux-leds@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 04/10] leds: pca995x: Fix fwnode handle leaks in error paths
Date: Tue, 29 Sep 2026 10:20:44 +0100	[thread overview]
Message-ID: <179025017981.457255.5791421193775684526@kernel.org> (raw)
In-Reply-To: <3d38609c96d387aec7eaff7cdb19fc2d8eb32a3e.1790087890.git.nora.schiffer@ew.tq-group.com>

--- checkpatch.pl: clean (0 issues) ---

On Tue, 22 Sep 2026, Nora Schiffer wrote:

> Each entry in led_fwnodes needs to be put as long as no LED device has
> been created for it yet - not just in the creation loop, but also in the
> first loop that iterates over the child nodes.
>
> By clearing entries in led_fwnodes once they have been used, the same
> cleanup loop can be used to handle errors in both loops.
>
> Fixes: 82c5ada1f9d0 ("leds: pca995x: Fix device child node usage in pca995x_probe()")
> Signed-off-by: Nora Schiffer <nora.schiffer@ew.tq-group.com>
> ---
>  drivers/leds/leds-pca995x.c | 26 +++++++++++++++++---------
>  1 file changed, 17 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/leds/leds-pca995x.c b/drivers/leds/leds-pca995x.c
> index 8b05b3f12cf38..079ce3d8f1e49 100644
> --- a/drivers/leds/leds-pca995x.c
> +++ b/drivers/leds/leds-pca995x.c
> @@ -123,7 +123,7 @@ static int pca995x_probe(struct i2c_client *client)
>  	const struct pca995x_chipdef *chipdef;
>  	struct pca995x_chip *chip;
>  	struct pca995x_led *led;
> -	int i, j, reg, ret;
> +	int i, reg, ret;
>
>  	chipdef = device_get_match_data(&client->dev);
>
> @@ -144,10 +144,12 @@ static int pca995x_probe(struct i2c_client *client)
>  	device_for_each_child_node_scoped(dev, child) {
>  		ret = fwnode_property_read_u32(child, "reg", &reg);
>  		if (ret)
> -			return ret;
> +			goto err_put_nodes;
>
> -		if (reg < 0 || reg >= chipdef->num_leds || led_fwnodes[reg])
> -			return -EINVAL;
> +		if (reg < 0 || reg >= chipdef->num_leds || led_fwnodes[reg]) {
> +			ret = -EINVAL;
> +			goto err_put_nodes;
> +		}
>
>  		led = &chip->leds[reg];
>  		led_fwnodes[reg] = fwnode_handle_get(child);
> @@ -169,12 +171,12 @@ static int pca995x_probe(struct i2c_client *client)
>  						     &chip->leds[i].ldev,
>  						     &init_data);
>  		if (ret < 0) {
> -			for (j = i; j < chipdef->num_leds; j++)
> -				fwnode_handle_put(led_fwnodes[j]);
> -			return dev_err_probe(dev, ret,
> -					     "Could not register LED %s\n",
> -					     chip->leds[i].ldev.name);
> +			dev_err_probe(dev, ret, "Could not register LED %s\n",
> +				      chip->leds[i].ldev.name);
> +			goto err_put_nodes;
>  		}
> +
> +		led_fwnodes[i] = NULL;

Shouldn't we put this before removing it?

>  	}
>
>  	/* Disable LED all-call address and set normal mode */
> @@ -184,6 +186,12 @@ static int pca995x_probe(struct i2c_client *client)
>
>  	/* IREF Output current value for all LEDn outputs */
>  	return regmap_write(chip->regmap, chipdef->irefall, PCA995X_IREFALL_HALF_CFG);
> +
> +err_put_nodes:
> +	for (i = 0; i < chipdef->num_leds; i++)
> +		fwnode_handle_put(led_fwnodes[i]);
> +
> +	return ret;
>  }
>
>  static const struct i2c_device_id pca995x_id[] = {
> -- 
> TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
> Amtsgericht München, HRB 105018
> Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
> https://www.tq-group.com/
>
>

-- 
Lee Jones

  reply	other threads:[~2026-09-29  9:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 14:47 [PATCH v3 00/10] leds: pca995x: Minor fixes; reset, output-gain, error reporting and group brightness support Nora Schiffer
2026-09-22 14:47 ` [PATCH v3 01/10] dt-bindings: leds: pca995x: Describe reset-gpios property Nora Schiffer
2026-09-22 14:47 ` [PATCH v3 02/10] dt-bindings: leds: pca995x: Describe nxp,output-gain property Nora Schiffer
2026-09-22 14:47 ` [PATCH v3 03/10] leds: pca995x: Fix maximum LED index for 16-channel variants Nora Schiffer
2026-09-22 14:47 ` [PATCH v3 04/10] leds: pca995x: Fix fwnode handle leaks in error paths Nora Schiffer
2026-09-29  9:20   ` Lee Jones [this message]
2026-09-29  9:27     ` Nora Schiffer
2026-09-22 14:47 ` [PATCH v3 05/10] leds: pca995x: Write global registers before creating LED devices Nora Schiffer
2026-09-22 14:47 ` [PATCH v3 06/10] leds: pca995x: Add support for reset GPIO Nora Schiffer
2026-09-29  9:14   ` Lee Jones
2026-09-29  9:25     ` Nora Schiffer
2026-09-22 14:47 ` [PATCH v3 07/10] leds: pca995x: Make output gain configurable Nora Schiffer
2026-09-22 14:47 ` [PATCH v3 08/10] leds: pca995x: Add sysfs files for error reporting Nora Schiffer
2026-09-29 10:12   ` Lee Jones
2026-09-29 11:04     ` Nora Schiffer
2026-09-22 14:47 ` [PATCH v3 09/10] leds: pca995x: Do not use full on LED mode Nora Schiffer
2026-09-22 14:47 ` [PATCH v3 10/10] leds: pca995x: Add support for group brightness control Nora Schiffer
2026-09-29 10:13   ` Lee Jones
2026-09-29 11:06     ` Nora Schiffer

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=179025017981.457255.5791421193775684526@kernel.org \
    --to=lee@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=isaiezequiel.gaspar@nxp.com \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux@ew.tq-group.com \
    --cc=marex@denx.de \
    --cc=nora.schiffer@ew.tq-group.com \
    --cc=pavel@kernel.org \
    --cc=pieterjanca@gmail.com \
    --cc=robh@kernel.org \
    /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

all inboxes | Powered by JetHome®