linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Haotian Zhang <vulab@iscas.ac.cn>
Cc: Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>,
	Markus.Elfring@web.de, linux-leds@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] leds: netxbig: fix GPIO descriptor leak in error paths
Date: Tue, 18 Nov 2025 21:01:58 +0100	[thread overview]
Message-ID: <aRzQtvOhYRaWCiFA@black.igk.intel.com> (raw)
In-Reply-To: <20251031021620.781-1-vulab@iscas.ac.cn>

On Fri, Oct 31, 2025 at 10:16:20AM +0800, Haotian Zhang wrote:
> The function netxbig_gpio_ext_get() acquires GPIO descriptors but
> fails to release them when errors occur mid-way through initialization.
> The cleanup callback registered by devm_add_action_or_reset() only
> runs on success, leaving acquired GPIOs leaked on error paths.
> 
> Add goto-based error handling to release all acquired GPIOs before
> returning errors.

...

>  	data = devm_kcalloc(dev, num_data, sizeof(*data), GFP_KERNEL);
> +	if (!data) {
> +		ret = -ENOMEM;
> +		goto err_free_addr;
> +	}
> +
> +	gpio_ext->data = data;
> +	gpio_ext->num_data = 0;
>  
>  	for (i = 0; i < num_data; i++) {
>  		gpiod = gpiod_get_index(gpio_ext_dev, "data", i,
>  					GPIOD_OUT_LOW);
>  		if (IS_ERR(gpiod))
> +			goto err_free_data;
>  		gpiod_set_consumer_name(gpiod, "GPIO extension data");
>  		data[i] = gpiod;
> +		gpio_ext->num_data++;
>  	}

While fixing one issue, this brings wrong order of the devm_ and non-devm
resource cleaning. This may lead in some cases to the crash at ->remove() or on
error path at ->probe().

I think this needs much deeper refactoring, and rethinking. Easiest approach is
to get rid of devm_ allocations altogether with a huge comment why.

That said, NAK to it in _this_ form.
(However I see it is already applied, so perhaps it will be fixed by some
 followups)

-- 
With Best Regards,
Andy Shevchenko



      parent reply	other threads:[~2025-11-18 20:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-28  8:21 [PATCH] leds: netxbig: fix GPIO descriptor leak in error paths Haotian Zhang
2025-10-29 12:55 ` Markus Elfring
2025-10-30  2:53 ` [PATCH v2] " Haotian Zhang
2025-10-30 10:00   ` Markus Elfring
2025-10-30 18:06   ` kernel test robot
2025-10-30 22:29   ` kernel test robot
2025-10-31  2:16 ` [PATCH v3] " Haotian Zhang
2025-11-13 13:52   ` (subset) " Lee Jones
2025-11-18 20:01   ` Andy Shevchenko [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=aRzQtvOhYRaWCiFA@black.igk.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=Markus.Elfring@web.de \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=vulab@iscas.ac.cn \
    /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;
as well as URLs for NNTP newsgroup(s).