From: Andrew Jeffery <andrew@aj.id.au>
To: Mykola Kostenok <c_mykolak@mellanox.com>, Joel Stanley <joel@jms.id.au>
Cc: "linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
Jaghathiswari Rankappagounder Natarajan <jaghu@google.com>,
Jean Delvare <jdelvare@suse.com>, Ohad Oz <ohado@mellanox.com>,
Vadim Pasternak <vadimp@mellanox.com>,
Patrick Venture <venture@google.com>,
OpenBMC Maillist <openbmc@lists.ozlabs.org>,
Rob Herring <robh+dt@kernel.org>,
Guenter Roeck <linux@roeck-us.net>
Subject: Re: [patch v3] hwmon: (aspeed-pwm-tacho) cooling device support.
Date: Thu, 27 Jul 2017 15:31:25 +0930 [thread overview]
Message-ID: <1501135285.5179.16.camel@aj.id.au> (raw)
In-Reply-To: <DB5PR05MB1224F329AA1C5BA4B37B4B86EFB90@DB5PR05MB1224.eurprd05.prod.outlook.com>
[-- Attachment #1: Type: text/plain, Size: 2791 bytes --]
Hi Mykola,
I know you've sent out subsequent versions, but I wanted to address one
of your arguments here:
On Wed, 2017-07-26 at 11:08 +0000, Mykola Kostenok wrote:
> > > @@ -834,10 +946,12 @@ static int aspeed_pwm_tacho_probe(struct
> > > platform_device *pdev)
> > >
> > > for_each_child_of_node(np, child) {
> > > ret = aspeed_create_fan(dev, child, priv);
> > > - of_node_put(child);
> > > - if (ret)
> > > + if (ret) {
> > > + of_node_put(child);
> > > return ret;
> > > + }
> > > }
> > > + of_node_put(child);
> >
> > I'm not sure about these.
> >
> > Cheers,
> >
> > Joel
>
> If CONFIG_OF_UNITTEST is set, system initialization fails on this of_node_put.
> I checked and found that for_each_child_of_node is macro witch use __of_get_next_child
> in cycle. __of_get_next_child do of_node_put previous child but not last.
>
> static struct device_node *__of_get_next_child(const struct device_node *node,
> struct device_node *prev)
> {
> struct device_node *next;
>
> if (!node)
> return NULL;
>
> next = prev ? prev->sibling : node->child;
> for (; next; next = next->sibling)
> if (of_node_get(next))
> break;
> of_node_put(prev);
> return next;
> }
> #define __for_each_child_of_node(parent, child) \
> for (child = __of_get_next_child(parent, NULL); child != NULL; \
> child = __of_get_next_child(parent, child))
>
> So inside cycle we should not use of_node_put on each child. We must use it only on last child in cycle.
I was just looking at this myself for a different driver, and I don't
think this argument is right. The natural terminating condition of the
loop is child == NULL. child == NULL occurs if we have zero-or-more-
children; the child is always initialised as part of the loop header
and would be NULL if there are no children. If we have more than one
child, the reference to the last valid child is passed to of_node_put()
in __of_get_next_child() in order to return the terminating NULL. Given
__of_get_next_child() is passed the last node and the result is NULL,
the call to of_node_put() after the loop is always invoked on NULL,
which performs an early return.
As such I think it is unnecessary.
Cheers,
Andrew
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
next prev parent reply other threads:[~2017-07-27 6:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-25 14:17 [patch v3] hwmon: (aspeed-pwm-tacho) cooling device support Mykola Kostenok
2017-07-26 6:48 ` Joel Stanley
2017-07-26 11:08 ` Mykola Kostenok
2017-07-27 6:01 ` Andrew Jeffery [this message]
2017-07-27 8:36 ` Mykola Kostenok
2017-07-27 8:49 ` Andrew Jeffery
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=1501135285.5179.16.camel@aj.id.au \
--to=andrew@aj.id.au \
--cc=c_mykolak@mellanox.com \
--cc=jaghu@google.com \
--cc=jdelvare@suse.com \
--cc=joel@jms.id.au \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=ohado@mellanox.com \
--cc=openbmc@lists.ozlabs.org \
--cc=robh+dt@kernel.org \
--cc=vadimp@mellanox.com \
--cc=venture@google.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