[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZiDwZGY-MF5OdVmH@smile.fi.intel.com>
Date: Thu, 18 Apr 2024 13:05:24 +0300
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: Dan Carpenter <dan.carpenter@...aro.org>
Cc: Zeng Heng <zengheng4@...wei.com>, linus.walleij@...aro.org,
linux-kernel@...r.kernel.org, xiexiuqi@...wei.com,
linux-gpio@...r.kernel.org, weiyongjun1@...wei.com,
liwei391@...wei.com
Subject: Re: [PATCH] pinctrl: devicetree: fix refcount leak in
pinctrl_dt_to_map()
On Wed, Apr 17, 2024 at 08:49:42PM +0300, Dan Carpenter wrote:
> On Wed, Apr 17, 2024 at 08:12:23PM +0300, Andy Shevchenko wrote:
> > On Wed, Apr 17, 2024 at 06:38:46PM +0300, Dan Carpenter wrote:
> > > On Wed, Apr 17, 2024 at 06:30:59PM +0300, Andy Shevchenko wrote:
> > > > On Mon, Apr 15, 2024 at 06:53:28PM +0800, Zeng Heng wrote:
..
> > > > > for (state = 0; ; state++) {
> > > > > /* Retrieve the pinctrl-* property */
> > > > > propname = kasprintf(GFP_KERNEL, "pinctrl-%d", state);
> > > > > - if (!propname)
> > > > > - return -ENOMEM;
> > > > > + if (!propname) {
> > > > > + ret = -ENOMEM;
> > > > > + goto err;
> > > > > + }
> > > > > prop = of_find_property(np, propname, &size);
> > > > > kfree(propname);
> > > > > if (!prop) {
> > > > > if (state == 0) {
> > > > > - of_node_put(np);
> > > > > - return -ENODEV;
> > > > > + ret = -ENODEV;
> > > > > + goto err;
> > > >
> > > > Has it been tested? How on earth is this a correct change?
> > > >
> > > > We iterate over state numbers until we have properties available. This chunk is
> > > > _successful_ exit path, we may not free parsed maps! Am I wrong?
> > >
> > > In this path state == 0 so we haven't had a successful iteration yet.
> >
> > Ah, indeed, this is not a status. Okay, makes sense, but calling that free
> > function for the purpose of the putting of_node seems an overkill...
>
> Sure, that's one way to look at it, but it's suspicious looking when
> there is a direct return which is surrounded by gotos. As I write this,
> I remember that Smatch has a warning for code like that.
>
> Probably we should add a comment to say:
>
> /* Return -ENODEV if the property 'pinctrl-0' is not present. */
Good idea, go for it!
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists