[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z0uHJJKMog-REw1D@smile.fi.intel.com>
Date: Sat, 30 Nov 2024 23:44:04 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Dmitry Torokhov <dmitry.torokhov@...il.com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J . Wysocki" <rafael.j.wysocki@...el.com>,
Sakari Ailus <sakari.ailus@...ux.intel.com>,
Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
Daniel Scally <djrscally@...il.com>, linux-acpi@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] device property: do not leak child nodes when using
NULL/error pointers
On Fri, Nov 29, 2024 at 11:16:54PM -0800, Dmitry Torokhov wrote:
> On Fri, Nov 29, 2024 at 04:50:15PM +0200, Andy Shevchenko wrote:
> > On Thu, Nov 28, 2024 at 03:04:50PM -0800, Dmitry Torokhov wrote:
> > > On Thu, Nov 28, 2024 at 03:13:16PM +0200, Andy Shevchenko wrote:
> > > > On Wed, Nov 27, 2024 at 09:39:34PM -0800, Dmitry Torokhov wrote:
...
> > > > > @@ struct fwnode_handle *device_get_next_child_node(const struct device *dev,
> > > > > const struct fwnode_handle *fwnode = dev_fwnode(dev);
> > > > > struct fwnode_handle *next;
> > > >
> > > > > - if (IS_ERR_OR_NULL(fwnode))
> > > > > + if (IS_ERR_OR_NULL(fwnode)) {
> > > > > + fwnode_handle_put(child);
> > > > > return NULL;
> > > > > + }
> > > >
> > > > > /* Try to find a child in primary fwnode */
> > > > > next = fwnode_get_next_child_node(fwnode, child);
> > > >
> > > > So, why not just moving the original check (w/o dropping the reference) here?
> > > > Wouldn't it have the same effect w/o explicit call to the fwnode_handle_put()?
> > >
> > > Because if you rely on check in fwnode_get_next_child_node() you would
> > > not know if it returned NULL because there are no more children or
> > > because the node is invalid. In the latter case you can't dereference
> > > fwnode->secondary.
> >
> > Yes, so, how does it contradict my proposal?
>
> I guess I misunderstood your proposal then. Could you please explain it
> in more detail?
Current code (in steps):
if (IS_ERR_OR_NULL()) check
trying primary
trying secondary if previous is NULL
My proposal
trying primary
return if not NULL
if (IS_ERR_OR_NULL()) check in its current form (no put op)
trying secondary
After your first patch IIUC this is possible as trying primary will put child uncoditionally.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists