From: Vladimir Oltean <olteanv@gmail.com>
To: Xiang Yang <xiangyang@huaweicloud.com>
Cc: clement.leger@bootlin.com, hkallweit1@gmail.com,
linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, f.fainelli@gmail.com,
linux-renesas-soc@vger.kernel.org, netdev@vger.kernel.org,
xiangyang3@huawei.com
Subject: Re: [PATCH -next] net: pcs: Add missing put_device call in miic_create
Date: Tue, 8 Aug 2023 13:53:17 +0300 [thread overview]
Message-ID: <20230808105317.66o2gv66q2q3ulhl@skbuf> (raw)
In-Reply-To: <20230807134714.2048214-1-xiangyang@huaweicloud.com>
On Mon, Aug 07, 2023 at 01:47:14PM +0000, Xiang Yang wrote:
> From: Xiang Yang <xiangyang3@huawei.com>
>
> The reference of pdev->dev is taken by of_find_device_by_node, so
> it should be released when error out.
>
> Fixes: 7dc54d3b8d91 ("net: pcs: add Renesas MII converter driver")
> Signed-off-by: Xiang Yang <xiangyang3@huawei.com>
> ---
Ok, but if of_find_device_by_node() requires a subsequent call to
put_device(), then doesn't this mean that in the non-error case, the
pdev refcount remains elevated, and will thus never be freed?
I would expect another put_device(&pdev->dev) after the device_link_add(),
which itself takes another set of references on the supplier and
consumer devs, which are sufficient for this driver's runtime operation.
Also, "if (!pdev)" and "if (!platform_get_drvdata(pdev)" here need
different treatment. One needs to call put_device(&pdev->dev) and the
other one doesn't.
pdev = of_find_device_by_node(pcs_np);
of_node_put(pcs_np);
if (!pdev || !platform_get_drvdata(pdev))
return ERR_PTR(-EPROBE_DEFER);
pw-bot: cr
> drivers/net/pcs/pcs-rzn1-miic.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c
> index e5d642c67a2c..d097f123635a 100644
> --- a/drivers/net/pcs/pcs-rzn1-miic.c
> +++ b/drivers/net/pcs/pcs-rzn1-miic.c
> @@ -318,8 +318,10 @@ struct phylink_pcs *miic_create(struct device *dev, struct device_node *np)
> return ERR_PTR(-EPROBE_DEFER);
>
> miic_port = kzalloc(sizeof(*miic_port), GFP_KERNEL);
> - if (!miic_port)
> + if (!miic_port) {
> + put_device(&pdev->dev);
> return ERR_PTR(-ENOMEM);
> + }
>
> miic = platform_get_drvdata(pdev);
> device_link_add(dev, miic->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
> --
> 2.34.1
>
next prev parent reply other threads:[~2023-08-08 16:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-07 13:47 [PATCH -next] net: pcs: Add missing put_device call in miic_create Xiang Yang
2023-08-08 10:53 ` Vladimir Oltean [this message]
2023-08-08 10:54 ` Vladimir Oltean
2023-08-08 11:56 ` Xiang Yang
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=20230808105317.66o2gv66q2q3ulhl@skbuf \
--to=olteanv@gmail.com \
--cc=clement.leger@bootlin.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=xiangyang3@huawei.com \
--cc=xiangyang@huaweicloud.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