linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: Petr Mladek <pmladek@suse.com>
Cc: linux-kernel@vger.kernel.org, rafael@kernel.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	linux-acpi@vger.kernel.org, devicetree@vger.kernel.org,
	Rob Herring <robh@kernel.org>
Subject: Re: [PATCH v2 1/6] device property: Add functions for accessing node's parents
Date: Fri, 29 Mar 2019 15:04:36 +0200	[thread overview]
Message-ID: <20190329130436.4fxzki5kljprhyai@kekkonen.localdomain> (raw)
In-Reply-To: <20190328141036.mbns3ei4agnginsg@pathway.suse.cz>

Hi Petr,

On Thu, Mar 28, 2019 at 03:10:36PM +0100, Petr Mladek wrote:
> On Wed 2019-03-27 16:20:37, Sakari Ailus wrote:
> > Hi Petr,
> > 
> > On Wed, Mar 27, 2019 at 01:26:25PM +0100, Petr Mladek wrote:
> > > On Tue 2019-03-26 14:41:01, Sakari Ailus wrote:
> > > > Add two convenience functions for accessing node's parents:
> > > > 
> > > > fwnode_count_parents() returns the number of parent nodes a given node
> > > > has. fwnode_get_nth_parent() returns node's parent at a given distance
> > > > from the node itself.
> > > > 
> > > > Also reorder fwnode_get_parent() in property.c according to the same order
> > > > as in property.h.
> > > > 
> > > > diff --git a/drivers/base/property.c b/drivers/base/property.c
> > > > index 8b91ab380d14..61eb6ceacc3f 100644
> > > > --- a/drivers/base/property.c
> > > > +++ b/drivers/base/property.c
> > > > @@ -554,17 +567,49 @@ struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode)
> > > >  EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
> > > >  
> > > >  /**
> > > > - * fwnode_get_parent - Return parent firwmare node
> > > > - * @fwnode: Firmware whose parent is retrieved
> > > > + * fwnode_count_parents - Return the number of parents a node has
> > > > + * @fwnode: The node the parents of which are to be counted
> > > >   *
> > > > - * Return parent firmware node of the given node if possible or %NULL if no
> > > > - * parent was available.
> > > > + * Returns the number of parents a node has.
> > > >   */
> > > > -struct fwnode_handle *fwnode_get_parent(const struct fwnode_handle *fwnode)
> > > > +unsigned int fwnode_count_parents(struct fwnode_handle *fwnode)
> > > >  {
> > > > -	return fwnode_call_ptr_op(fwnode, get_parent);
> > > > +	unsigned int count;
> > > > +
> > > > +	fwnode_handle_get(fwnode);
> > > > +
> > > > +	for (count = 0; fwnode; count++)
> > > > +		fwnode = fwnode_get_next_parent(fwnode);
> > > 
> > > Is it guaranteed that all parents stay when
> > > fwnode_get_next_parent() releases the reference count
> > > for each counted member?
> > 
> > fwnode_get_next_parent() only releases the child node after it has acquired
> > the parent. The only implementation with refcounting for single nodes is
> > actually OF.
> 
> I am still a bit confused. The function is later used the following way:
> 
> 	for (depth = fwnode_count_parents(fwnode); depth >= 0; depth--) {
> 		struct fwnode_handle *__fwnode =
> 			fwnode_get_nth_parent(fwnode, depth);
> 
> 		buf = string(buf, end, fwnode_get_name_prefix(__fwnode),
> 			     default_str_spec);
> 		buf = string(buf, end, fwnode_get_name(__fwnode),
> 			     default_str_spec);
> 
> 		fwnode_handle_put(__fwnode);
> 	}
> 
> It uses the number to walk the hierarchy over and over again to print
> the path from root.
> 
> I would expect that parents could not get removed until all children
> are removed. And that the most bottom child (fwnode) must not get
> removed. Otherwise we would access freed memory in each cycle.
> 
> Then there is a question why we need to get the reference of the
> parents
> at all.
> 
> It might be because we do not need touch refcounting of the parents
> in this scenario. But we are re-using existing functions where
> the ref-counting hang-over is important.
> 
> Or we really need to increase refcounting of parents. Then it looks
> suspicious because we want to traverse the same path several times
> and always have only one node locked (refcounted).

I hope I understand your concern better this time.

You basically have to have a reference to a node until you're done
accessing it. The refcounting in the fwnode framework is based on the OF
API --- otherwise you couldn't access OF nodes using the framework. ACPI
does not have those (as you can't dynamically remove nodes). The newly
added swnode does have refcounting of individual nodes as well.

Even if a node's parent did disappear while printing an fwnode full name,
it'd mean that

1) fwnode_count_parents() returned an incorrect value (less than expected)
   or

2) some of the node names could be NULL if node references could not be
   obtained.

Both would result into garbled output in that case. I have to admit I'm not
sure if this is possible with OF.

-- 
Kind regards,

Sakari Ailus
sakari.ailus@linux.intel.com

  reply	other threads:[~2019-03-29 13:04 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-26 12:41 [PATCH v2 0/6] Device property improvements, add %pfw format specifier Sakari Ailus
2019-03-26 12:41 ` [PATCH v2 1/6] device property: Add functions for accessing node's parents Sakari Ailus
2019-03-27 12:26   ` Petr Mladek
2019-03-27 14:20     ` Sakari Ailus
2019-03-28  9:38       ` Rafael J. Wysocki
2019-03-28 11:13         ` Sakari Ailus
2019-03-28 14:52           ` Rafael J. Wysocki
2019-03-29 13:15             ` Sakari Ailus
2019-03-29 14:15               ` Andy Shevchenko
2019-03-29 14:46                 ` Sakari Ailus
2019-03-29 23:00               ` Rafael J. Wysocki
2019-03-28 14:10       ` Petr Mladek
2019-03-29 13:04         ` Sakari Ailus [this message]
2019-03-29 14:14           ` Andy Shevchenko
2019-03-29 15:31             ` Sakari Ailus
2019-03-26 12:41 ` [PATCH v2 2/6] device property: Add fwnode_get_name for returning the name of a node Sakari Ailus
2019-03-28  9:45   ` Rafael J. Wysocki
2019-03-28 11:31     ` Sakari Ailus
2019-03-31  6:42   ` Rob Herring
2019-03-26 12:41 ` [PATCH v2 3/6] device property: Add a function to obtain a node's prefix Sakari Ailus
2019-03-26 13:16   ` Andy Shevchenko
2019-03-26 13:32     ` Sakari Ailus
2019-03-27 12:36       ` Petr Mladek
2019-03-28 11:43         ` Sakari Ailus
2019-03-31  6:42   ` Rob Herring
2019-03-26 12:41 ` [PATCH v2 4/6] lib/vsprintf: Remove support for %pF and %pf in favour of %pS and %ps Sakari Ailus
2019-03-26 12:41 ` [PATCH v2 5/6] lib/vsprintf: Make use of fwnode API to obtain node names and separators Sakari Ailus
2019-03-26 12:41 ` [PATCH v2 6/6] lib/vsprintf: Add %pfw conversion specifier for printing fwnode names Sakari Ailus
2019-03-26 13:11   ` Rasmus Villemoes
2019-03-26 13:24     ` Andy Shevchenko
2019-03-26 13:31       ` Sakari Ailus
2019-03-28 14:29       ` Petr Mladek
2019-03-29 13:10         ` Sakari Ailus
2019-03-26 20:18   ` Joe Perches
     [not found]     ` <20190328114845.giusyarjibvg5ru7@kekkonen.localdomain>
2019-03-28 11:51       ` Sakari Ailus

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=20190329130436.4fxzki5kljprhyai@kekkonen.localdomain \
    --to=sakari.ailus@linux.intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.com \
    --cc=rafael@kernel.org \
    --cc=robh@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;
as well as URLs for NNTP newsgroup(s).