From: Philipp Zabel <p.zabel@pengutronix.de>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: airlied@linux.ie, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] drm/imx: Fix of_node ref counting
Date: Mon, 05 Sep 2016 10:06:37 +0200 [thread overview]
Message-ID: <1473062797.2456.26.camel@pengutronix.de> (raw)
In-Reply-To: <1473062516.2456.25.camel@pengutronix.de>
Am Montag, den 05.09.2016, 10:01 +0200 schrieb Philipp Zabel:
> Hi Christophe,
>
> Am Sonntag, den 04.09.2016, 08:45 +0200 schrieb Christophe JAILLET:
> > This code is spurious.
> > It takes a ref on a node, then call 'of_node_put' on it and then store
> > this node somewhere.
>
> The node pointer is not stored. Note that np is not dereferenced at all,
> we just compare the pointer value against dev->of_node.
> It doesn't matter whether we drop the reference before or after that.
>
> > It is likely that taking the ref on the parent node and releasing the child
> > node was expected instead.
>
> Initially, np is assigned to the void *data parameter. The caller holds
> the reference to that, and we are not allowed to decrement its refcount
> (as of_get_next_parent does). Otherwise the iterator calling this match
> function would drop references of all the device_nodes it compares
> against.
>
> > So, use 'of_get_next_parent' instead. It does all this in just one
> > function call.
> >
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > ---
> > Un-tested
> > ---
> > drivers/gpu/drm/imx/imx-drm-core.c | 6 ++----
> > 1 file changed, 2 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/imx/imx-drm-core.c b/drivers/gpu/drm/imx/imx-drm-core.c
> > index 438bac8fbc2b..60fb388c80f8 100644
> > --- a/drivers/gpu/drm/imx/imx-drm-core.c
> > +++ b/drivers/gpu/drm/imx/imx-drm-core.c
> > @@ -449,10 +449,8 @@ static int compare_of(struct device *dev, void *data)
> > }
> >
> > /* Special case for LDB, one device for two channels */
> > - if (of_node_cmp(np->name, "lvds-channel") == 0) {
> > - np = of_get_parent(np);
> > - of_node_put(np);
> > - }
>
> This could have been written as:
>
> bool match;
>
> /* Special case for LDB, one device for two channels */
> if (of_node_cmp(np->name, "lvds-channel") == 0) {
> struct device_node *parent = of_get_parent(np);
>
> match = dev->of_node == parent;
> of_node_put(parent);
> } else {
> match = dev->of_node == np;
> }
>
> return match;
>
> which does exactly the same. Maybe the reuse of np and the pointer
> comparison after of_node_put warrants a comment.
Actually, maybe we should just do
- if (of_node_cmp(np->name, "lvds-channel") == 0) {
- np = of_get_parent(np);
- of_node_put(np);
- }
+ if (of_node_cmp(np->name, "lvds-channel") == 0)
+ np = np->parent;
regards
Philipp
prev parent reply other threads:[~2016-09-05 8:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-04 6:45 [PATCH] drm/imx: Fix of_node ref counting Christophe JAILLET
2016-09-05 8:01 ` Philipp Zabel
2016-09-05 8:06 ` Philipp Zabel [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=1473062797.2456.26.camel@pengutronix.de \
--to=p.zabel@pengutronix.de \
--cc=airlied@linux.ie \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.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).