linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: "kishon@ti.com" <kishon@ti.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-renesas-soc@vger.kernel.org" 
	<linux-renesas-soc@vger.kernel.org>
Subject: RE: [PATCH] phy: renesas: rcar-gen2: Fix memory leak at error paths
Date: Wed, 27 Feb 2019 08:53:35 +0000	[thread overview]
Message-ID: <TY2PR01MB4812FABCB851C22F4295B9D4D8740@TY2PR01MB4812.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1902270920300.2671@hadrien>

Hello,

> From: Julia Lawall, Sent: Wednesday, February 27, 2019 5:25 PM
> 
> On Wed, 27 Feb 2019, Yoshihiro Shimoda wrote:
> 
> > This patch fixes memory leak at error paths of the probe function.
> > In for_each_child_of_node, if the loop returns, the driver should
> > call of_put_node() before returns.
> >
> > Reported-by: Julia Lawall <julia.lawall@lip6.fr>
> > Fixes: 1233f59f745 ("phy: Renesas R-Car Gen2 PHY driver")
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > ---
> >  drivers/phy/renesas/phy-rcar-gen2.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/phy/renesas/phy-rcar-gen2.c b/drivers/phy/renesas/phy-rcar-gen2.c
> > index 72eeb06..570b4e4 100644
> > --- a/drivers/phy/renesas/phy-rcar-gen2.c
> > +++ b/drivers/phy/renesas/phy-rcar-gen2.c
> > @@ -285,6 +285,7 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev)
> >  		error = of_property_read_u32(np, "reg", &channel_num);
> >  		if (error || channel_num > 2) {
> >  			dev_err(dev, "Invalid \"reg\" property\n");
> > +			of_node_put(np);
> >  			return error;
> >  		}
> >  		channel->select_mask = select_mask[channel_num];
> > @@ -300,6 +301,7 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev)
> >  						   &rcar_gen2_phy_ops);
> >  			if (IS_ERR(phy->phy)) {
> >  				dev_err(dev, "Failed to create PHY\n");
> > +				of_node_put(np);
> >  				return PTR_ERR(phy->phy);
> >  			}
> >  			phy_set_drvdata(phy->phy, phy);
> 
> Hello,
> 
> I was concerned about the assignment channel->of_node = np;.  Because
> channels is allocated with a devm function, it will get freed on an error
> return, so this pointer doesn't matter.  But don't you need an of_node_get
> on this assignment?  Does the fact that you haven't seen a problem with
> this in testing mean that the field is actually never accessed?

The channel->of_node will be used in the rcar_gen2_phy_xlate() as drv->channels[i].of_node.
The assignment is not used for any device tree APIs, just comparing the pointer.
So, I don't think this driver needs an of_node_get() on this assignment.
Is my understanding incorrect?

---
static struct phy *rcar_gen2_phy_xlate(struct device *dev,
				       struct of_phandle_args *args)
{
	struct rcar_gen2_phy_driver *drv;
	struct device_node *np = args->np;
	int i;

	drv = dev_get_drvdata(dev);
	if (!drv)
		return ERR_PTR(-EINVAL);

	for (i = 0; i < drv->num_channels; i++) {
		if (np == drv->channels[i].of_node)	// <--- here only
			break;
	}

	if (i >= drv->num_channels || args->args[0] >= 2)
		return ERR_PTR(-ENODEV);

	return drv->channels[i].phys[args->args[0]].phy;
}
---

Best regards,
Yoshihiro Shimoda

> julia

  reply	other threads:[~2019-02-27  8:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-27  7:00 [PATCH] phy: renesas: rcar-gen2: Fix memory leak at error paths Yoshihiro Shimoda
2019-02-27  8:25 ` Julia Lawall
2019-02-27  8:53   ` Yoshihiro Shimoda [this message]
2019-02-27 10:53     ` Geert Uytterhoeven
2019-02-27 20:55     ` Julia Lawall
2019-02-27 10:47 ` Geert Uytterhoeven

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=TY2PR01MB4812FABCB851C22F4295B9D4D8740@TY2PR01MB4812.jpnprd01.prod.outlook.com \
    --to=yoshihiro.shimoda.uh@renesas.com \
    --cc=julia.lawall@lip6.fr \
    --cc=kishon@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@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).