Linux on ARM based TI OMAP SoCs
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: Guangshuo Li <lgs201920130244@gmail.com>
Cc: Aaro Koskinen <aaro.koskinen@iki.fi>,
	Andreas Kemnade <andreas@kemnade.info>,
	Kevin Hilman <khilman@baylibre.com>,
	Roger Quadros <rogerq@kernel.org>,
	Tony Lindgren <tony@atomide.com>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Samuel Ortiz <sameo@linux.intel.com>,
	Peter Ujfalusi <peter.ujfalusi@ti.com>,
	linux-omap@vger.kernel.org, mfd@lists.linux.dev,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] mfd: twl6040: fix IRQ action memory leaks during teardown
Date: Wed, 28 Oct 2026 09:37:05 +0000	[thread overview]
Message-ID: <20261028093705.GK2195460@google.com> (raw)
In-Reply-To: <CANUHTR8Ypwpm+Qqmk-fob1=e040rRH5QGTs7gN6MWRKQYyOdCw@mail.gmail.com>

On Wed, 28 Oct 2026, Guangshuo Li wrote:

> Hi Lee,
> 
> On Wed, 28 Oct 2026 at 00:26, Lee Jones <lee@kernel.org> wrote:
> >
> > On Tue, 27 Oct 2026, Guangshuo Li wrote:
> >
> > > twl6040_remove() currently removes the regmap IRQ chip before
> > > removing the MFD child devices. This destroys the IRQ mappings
> > > before the child drivers can release their interrupt handlers.
> > >
> > > The parent driver also registers READY and thermal interrupt
> > > handlers using devm_request_threaded_irq(). These handlers are
> > > normally released by device-managed cleanup after remove returns,
> > > when the corresponding IRQ descriptors have already been removed.
> > >
> > > Consequently, free_irq() cannot find the IRQ descriptors and the
> > > allocated struct irqaction objects are not freed. The associated
> > > IRQ threads also cannot be stopped through the normal cleanup path.
> > >
> > > The probe error paths have a similar issue, as they destroy the IRQ
> > > chip before the device-managed IRQ handlers are released.
> > >
> > > Remove the MFD child devices first, then explicitly free the
> > > parent's READY and thermal IRQ handlers using devm_free_irq()
> > > before removing the regmap IRQ chip.
> > >
> > > Also update the probe error paths to release successfully requested
> > > IRQs before destroying their mappings.
> > >
> > > This issue was found by our static analysis tool under development.
> > >
> > > Fixes: ab7edb149c75 ("mfd: twl6040: Convert to use regmap_irq")
> > > Cc: stable@vger.kernel.org
> > > Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> > > ---
> > >  drivers/mfd/twl6040.c | 13 +++++++++----
> > >  1 file changed, 9 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/mfd/twl6040.c b/drivers/mfd/twl6040.c
> > > index 562a0f939f6e..7b05d21cd17d 100644
> > > --- a/drivers/mfd/twl6040.c
> > > +++ b/drivers/mfd/twl6040.c
> > > @@ -745,7 +745,7 @@ static int twl6040_probe(struct i2c_client *client)
> > >                                       "twl6040_irq_th", twl6040);
> > >       if (ret) {
> > >               dev_err(twl6040->dev, "Thermal IRQ request failed: %d\n", ret);
> > > -             goto readyirq_err;
> > > +             goto thirq_err;
> > >       }
> > >
> > >       /*
> > > @@ -791,10 +791,14 @@ static int twl6040_probe(struct i2c_client *client)
> > >       ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children,
> > >                             NULL, 0, NULL);
> > >       if (ret)
> > > -             goto readyirq_err;
> > > +             goto mfd_err;
> > >
> > >       return 0;
> > >
> > > +mfd_err:
> > > +     devm_free_irq(twl6040->dev, twl6040->irq_th, twl6040);
> > > +thirq_err:
> > > +     devm_free_irq(twl6040->dev, twl6040->irq_ready, twl6040);
> > >  readyirq_err:
> > >       regmap_del_irq_chip(twl6040->irq, twl6040->irq_data);
> > >  gpio_err:
> > > @@ -809,9 +813,10 @@ static void twl6040_remove(struct i2c_client *client)
> > >       if (twl6040->power_count)
> > >               twl6040_power(twl6040, 0);
> > >
> > > -     regmap_del_irq_chip(twl6040->irq, twl6040->irq_data);
> > > -
> > >       mfd_remove_devices(&client->dev);
> > > +     devm_free_irq(twl6040->dev, twl6040->irq_th, twl6040);
> > > +     devm_free_irq(twl6040->dev, twl6040->irq_ready, twl6040);
> > > +     regmap_del_irq_chip(twl6040->irq, twl6040->irq_data);
> >
> > Why not use more devm_*() handlers?
> >
> > devm_regmap_add_irq_chip()
> >
> > devm_free* eeks me out.  The point of devm_*() is that it's managed.
> >
> > >       regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies);
> > >  }
> > > --
> > > 2.43.0
> > >
> >
> > --
> > Lee Jones
> 
> Thanks for your suggestion. I'll look into using devm_*() APIs in v2.
> 
> Would you prefer that I submit the twl6040 and hi655x-pmic fixes as a
> single patch series in v2, or separately?

I'm not overly concerned.

-- 
Lee Jones

      reply	other threads:[~2026-10-28  9:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27  3:26 [PATCH] mfd: twl6040: fix IRQ action memory leaks during teardown Guangshuo Li
2026-10-27 15:33 ` Krzysztof Kozlowski
2026-10-27 16:22   ` Guangshuo Li
2026-10-27 16:44     ` Krzysztof Kozlowski
2026-10-27 16:56       ` Guangshuo Li
2026-10-27 16:26 ` Lee Jones
2026-10-27 16:40   ` Guangshuo Li
2026-10-28  9:37     ` Lee Jones [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=20261028093705.GK2195460@google.com \
    --to=lee@kernel.org \
    --cc=aaro.koskinen@iki.fi \
    --cc=andreas@kemnade.info \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=khilman@baylibre.com \
    --cc=lgs201920130244@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=mfd@lists.linux.dev \
    --cc=peter.ujfalusi@ti.com \
    --cc=rogerq@kernel.org \
    --cc=sameo@linux.intel.com \
    --cc=stable@vger.kernel.org \
    --cc=tony@atomide.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