public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Ma Ke <make24@iscas.ac.cn>
Cc: jic23@kernel.org, dlechner@baylibre.com, nuno.sa@analog.com,
	andy@kernel.org, error27@gmail.com, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] iio: trigger: Fix error handling in viio_trigger_alloc
Date: Wed, 5 Nov 2025 17:07:35 +0200	[thread overview]
Message-ID: <aQtoNxBstUI-c6qp@smile.fi.intel.com> (raw)
In-Reply-To: <aQtnfzUKHc0fY52_@smile.fi.intel.com>

On Wed, Nov 05, 2025 at 05:04:32PM +0200, Andy Shevchenko wrote:
> On Wed, Nov 05, 2025 at 05:47:14PM +0800, Ma Ke wrote:
> > viio_trigger_alloc() initializes the device with device_initialize()
> > but uses kfree() directly in error paths, which bypasses the device's
> > release callback iio_trig_release(). This could lead to memory leaks
> > and inconsistent device state.
> > 
> > Replace kfree(trig) with put_device(&trig->dev) in error paths to
> > ensure proper cleanup through the device's release callback.
> 
> Now when irq_alloc_descs() fails, trig->subirq_base becomes negative and
> in the release callback it will pass the
> 
>         if (trig->subirq_base) {
> 
> Is it a problem?
> 
> The release function also misses mutex_destroy().

Ah, and if kvasprintf() fails, the error path will call irq_free_descs() and
then one more time in the release callback.

You finding is good, but the fix needs to be crafted thoughtfully.

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2025-11-05 15:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-05  9:47 [PATCH] iio: trigger: Fix error handling in viio_trigger_alloc Ma Ke
2025-11-05 15:04 ` Andy Shevchenko
2025-11-05 15:07   ` 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=aQtoNxBstUI-c6qp@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=error27@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=make24@iscas.ac.cn \
    --cc=nuno.sa@analog.com \
    --cc=stable@vger.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