From: Brian Norris <computersforpeace@gmail.com>
To: linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 1/7] phy: brcmstb-sata: add missing of_node_put
Date: Tue, 17 Nov 2015 18:30:36 +0000 [thread overview]
Message-ID: <20151117183036.GF8456@google.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1511171846120.2455@hadrien>
On Tue, Nov 17, 2015 at 06:48:39PM +0100, Julia Lawall wrote:
> On Tue, 17 Nov 2015, Brian Norris wrote:
> > On Tue, Nov 17, 2015 at 07:12:22AM +0100, Julia Lawall wrote:
> > > On Mon, 16 Nov 2015, Brian Norris wrote:
> > > > diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> > > > index fc48fac003a6..8df29caeeef9 100644
> > > > --- a/drivers/phy/phy-core.c
> > > > +++ b/drivers/phy/phy-core.c
> > > > @@ -697,6 +697,7 @@ struct phy *phy_create(struct device *dev, struct device_node *node,
> > > > phy->dev.class = phy_class;
> > > > phy->dev.parent = dev;
> > > > phy->dev.of_node = node ?: dev->of_node;
> > > > + of_node_get(phy->dev.of_node);
> > >
> > > Why not put of_node_get around dev->of_node?
> >
> > Like this?
> >
> > phy->dev.of_node = node ?: of_node_get(dev->of_node);
> >
> > Or this?
> >
> > phy->dev.of_node = of_node_get(node ?: dev->of_node);
> >
> > The former wouldn't do what I proposed; if this PHY device is created
> > with a sub-node of 'dev' rather than dev->of_node, then the caller will
> > pass it in as the 2nd argument to phy_create (i.e., 'node'), and then I
> > expect it's the PHY core's responsibility to refcount it.
> >
> > I'd be fine with the latter. Looks a little better, I suppose.
>
> I proposed it because I was worried that the of_node field could end up
> containing something that had been freed. But probably this is not
> possible?
AIUI, the caller of phy_create() should already have a refcount on both
'dev->of_node' and 'node' (if applicable), so nobody should be freeing
it from underneath us right here. But *after* phy_create() returns,
there's no guarantee the caller will hold a reference for us.
So even if it's ever possible, I'd consider it a bug in the caller, not
in phy_create().
> If it is not possible, then the ?: in the function argument is
> probably a bit ugly...
OK, then I'll go with my first proposal.
> Is this something that should be checked for elsewhere?
I expect the same sort of problem shows up plenty of other places. I
don't think many people use CONFIG_OF_DYNAMIC, so the effects of these
failures probably aren't felt by many.
Brian
WARNING: multiple messages have this Message-ID (diff)
From: computersforpeace@gmail.com (Brian Norris)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/7] phy: brcmstb-sata: add missing of_node_put
Date: Tue, 17 Nov 2015 10:30:36 -0800 [thread overview]
Message-ID: <20151117183036.GF8456@google.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1511171846120.2455@hadrien>
On Tue, Nov 17, 2015 at 06:48:39PM +0100, Julia Lawall wrote:
> On Tue, 17 Nov 2015, Brian Norris wrote:
> > On Tue, Nov 17, 2015 at 07:12:22AM +0100, Julia Lawall wrote:
> > > On Mon, 16 Nov 2015, Brian Norris wrote:
> > > > diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> > > > index fc48fac003a6..8df29caeeef9 100644
> > > > --- a/drivers/phy/phy-core.c
> > > > +++ b/drivers/phy/phy-core.c
> > > > @@ -697,6 +697,7 @@ struct phy *phy_create(struct device *dev, struct device_node *node,
> > > > phy->dev.class = phy_class;
> > > > phy->dev.parent = dev;
> > > > phy->dev.of_node = node ?: dev->of_node;
> > > > + of_node_get(phy->dev.of_node);
> > >
> > > Why not put of_node_get around dev->of_node?
> >
> > Like this?
> >
> > phy->dev.of_node = node ?: of_node_get(dev->of_node);
> >
> > Or this?
> >
> > phy->dev.of_node = of_node_get(node ?: dev->of_node);
> >
> > The former wouldn't do what I proposed; if this PHY device is created
> > with a sub-node of 'dev' rather than dev->of_node, then the caller will
> > pass it in as the 2nd argument to phy_create (i.e., 'node'), and then I
> > expect it's the PHY core's responsibility to refcount it.
> >
> > I'd be fine with the latter. Looks a little better, I suppose.
>
> I proposed it because I was worried that the of_node field could end up
> containing something that had been freed. But probably this is not
> possible?
AIUI, the caller of phy_create() should already have a refcount on both
'dev->of_node' and 'node' (if applicable), so nobody should be freeing
it from underneath us right here. But *after* phy_create() returns,
there's no guarantee the caller will hold a reference for us.
So even if it's ever possible, I'd consider it a bug in the caller, not
in phy_create().
> If it is not possible, then the ?: in the function argument is
> probably a bit ugly...
OK, then I'll go with my first proposal.
> Is this something that should be checked for elsewhere?
I expect the same sort of problem shows up plenty of other places. I
don't think many people use CONFIG_OF_DYNAMIC, so the effects of these
failures probably aren't felt by many.
Brian
WARNING: multiple messages have this Message-ID (diff)
From: Brian Norris <computersforpeace@gmail.com>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: Kishon Vijay Abraham I <kishon@ti.com>,
kernel-janitors@vger.kernel.org,
Gregory Fong <gregory.0xf0@gmail.com>,
Florian Fainelli <f.fainelli@gmail.com>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Russell King - ARM Linux <linux@arm.linux.org.uk>,
Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
Andrew Lunn <andrew@lunn.ch>, Bjorn Helgaas <bhelgaas@google.com>,
Jason Cooper <jason@lakedaemon.net>
Subject: Re: [PATCH 1/7] phy: brcmstb-sata: add missing of_node_put
Date: Tue, 17 Nov 2015 10:30:36 -0800 [thread overview]
Message-ID: <20151117183036.GF8456@google.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1511171846120.2455@hadrien>
On Tue, Nov 17, 2015 at 06:48:39PM +0100, Julia Lawall wrote:
> On Tue, 17 Nov 2015, Brian Norris wrote:
> > On Tue, Nov 17, 2015 at 07:12:22AM +0100, Julia Lawall wrote:
> > > On Mon, 16 Nov 2015, Brian Norris wrote:
> > > > diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> > > > index fc48fac003a6..8df29caeeef9 100644
> > > > --- a/drivers/phy/phy-core.c
> > > > +++ b/drivers/phy/phy-core.c
> > > > @@ -697,6 +697,7 @@ struct phy *phy_create(struct device *dev, struct device_node *node,
> > > > phy->dev.class = phy_class;
> > > > phy->dev.parent = dev;
> > > > phy->dev.of_node = node ?: dev->of_node;
> > > > + of_node_get(phy->dev.of_node);
> > >
> > > Why not put of_node_get around dev->of_node?
> >
> > Like this?
> >
> > phy->dev.of_node = node ?: of_node_get(dev->of_node);
> >
> > Or this?
> >
> > phy->dev.of_node = of_node_get(node ?: dev->of_node);
> >
> > The former wouldn't do what I proposed; if this PHY device is created
> > with a sub-node of 'dev' rather than dev->of_node, then the caller will
> > pass it in as the 2nd argument to phy_create (i.e., 'node'), and then I
> > expect it's the PHY core's responsibility to refcount it.
> >
> > I'd be fine with the latter. Looks a little better, I suppose.
>
> I proposed it because I was worried that the of_node field could end up
> containing something that had been freed. But probably this is not
> possible?
AIUI, the caller of phy_create() should already have a refcount on both
'dev->of_node' and 'node' (if applicable), so nobody should be freeing
it from underneath us right here. But *after* phy_create() returns,
there's no guarantee the caller will hold a reference for us.
So even if it's ever possible, I'd consider it a bug in the caller, not
in phy_create().
> If it is not possible, then the ?: in the function argument is
> probably a bit ugly...
OK, then I'll go with my first proposal.
> Is this something that should be checked for elsewhere?
I expect the same sort of problem shows up plenty of other places. I
don't think many people use CONFIG_OF_DYNAMIC, so the effects of these
failures probably aren't felt by many.
Brian
next prev parent reply other threads:[~2015-11-17 18:30 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-16 11:33 [PATCH 0/7] add missing of_node_put Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-16 11:33 ` [PATCH 1/7] phy: brcmstb-sata: " Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-17 1:38 ` Brian Norris
2015-11-17 1:38 ` Brian Norris
2015-11-17 1:38 ` Brian Norris
2015-11-17 6:12 ` Julia Lawall
2015-11-17 6:12 ` Julia Lawall
2015-11-17 6:12 ` Julia Lawall
2015-11-17 17:44 ` Brian Norris
2015-11-17 17:44 ` Brian Norris
2015-11-17 17:44 ` Brian Norris
2015-11-17 17:48 ` Julia Lawall
2015-11-17 17:48 ` Julia Lawall
2015-11-17 17:48 ` Julia Lawall
2015-11-17 18:30 ` Brian Norris [this message]
2015-11-17 18:30 ` Brian Norris
2015-11-17 18:30 ` Brian Norris
2015-11-17 18:34 ` Brian Norris
2015-11-17 18:34 ` Brian Norris
2015-11-17 18:34 ` Brian Norris
2015-11-17 22:33 ` Julia Lawall
2015-11-17 22:33 ` Julia Lawall
2015-11-17 22:33 ` Julia Lawall
2015-11-18 19:05 ` device_node lifetime (was: Re: [PATCH 1/7] phy: brcmstb-sata: add missing of_node_put) Brian Norris
2015-11-18 19:05 ` Brian Norris
2015-11-18 19:05 ` Brian Norris
2015-11-18 19:05 ` Brian Norris
2015-11-18 20:39 ` Julia Lawall
2015-11-18 20:39 ` Julia Lawall
2015-11-18 20:39 ` Julia Lawall
2015-11-18 20:39 ` Julia Lawall
2015-11-19 18:44 ` Rob Herring
2015-11-19 18:44 ` Rob Herring
2015-11-19 18:44 ` Rob Herring
2015-11-19 19:14 ` Russell King - ARM Linux
2015-11-19 19:14 ` Russell King - ARM Linux
2015-11-19 19:14 ` Russell King - ARM Linux
2015-11-19 22:58 ` Rob Herring
2015-11-27 14:14 ` [PATCH 1/7] phy: brcmstb-sata: add missing of_node_put Kishon Vijay Abraham I
2015-11-27 14:26 ` Kishon Vijay Abraham I
2015-11-27 14:14 ` Kishon Vijay Abraham I
2015-11-16 11:33 ` [PATCH 2/7] phy: mt65xx-usb3: " Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-16 11:33 ` [PATCH 3/7] phy: berlin-sata: " Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-19 20:48 ` Sebastian Hesselbarth
2015-11-19 20:48 ` Sebastian Hesselbarth
2015-11-16 11:33 ` [PATCH 4/7] phy: rockchip-usb: " Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-18 19:27 ` Heiko Stübner
2015-11-18 19:27 ` Heiko Stübner
2015-11-18 19:27 ` Heiko Stübner
2015-11-18 19:31 ` Brian Norris
2015-11-18 19:31 ` Brian Norris
2015-11-18 19:31 ` Brian Norris
2015-11-18 19:46 ` Heiko Stübner
2015-11-18 19:46 ` Heiko Stübner
2015-11-18 19:46 ` Heiko Stübner
2015-11-18 19:46 ` Heiko Stübner
2015-11-18 20:38 ` Julia Lawall
2015-11-18 20:38 ` Julia Lawall
2015-11-18 20:38 ` Julia Lawall
2015-11-18 20:40 ` Heiko Stübner
2015-11-18 20:40 ` Heiko Stübner
2015-11-18 20:40 ` Heiko Stübner
2015-11-18 21:42 ` Heiko Stübner
2015-11-18 21:42 ` Heiko Stübner
2015-11-18 21:42 ` Heiko Stübner
2015-11-16 11:33 ` [PATCH 5/7] phy: miphy28lp: " Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-16 11:33 ` [PATCH 6/7] phy: miphy365x: " Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-16 11:33 ` [PATCH 7/7] phy: cygnus: pcie: " Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-16 11:33 ` Julia Lawall
2015-11-16 17:12 ` Ray Jui
2015-11-16 17:12 ` Ray Jui
2015-11-16 17:12 ` Ray Jui
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=20151117183036.GF8456@google.com \
--to=computersforpeace@gmail.com \
--cc=linux-arm-kernel@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.