mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zijun Hu <zijun_hu@icloud.com>
To: Johan Hovold <johan@kernel.org>
Cc: "Vinod Koul" <vkoul@kernel.org>,
	"Kishon Vijay Abraham I" <kishon@kernel.org>,
	"Felipe Balbi" <balbi@ti.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rob Herring" <robh@kernel.org>, "Arnd Bergmann" <arnd@arndb.de>,
	"Lee Jones" <lee@kernel.org>,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Christophe JAILLET" <christophe.jaillet@wanadoo.fr>,
	stable@vger.kernel.org, linux-phy@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	"Zijun Hu" <quic_zijuhu@quicinc.com>
Subject: Re: [PATCH v4 4/6] phy: core: Fix an OF node refcount leakage in _of_phy_get()
Date: Wed, 6 Nov 2024 23:28:37 +0800	[thread overview]
Message-ID: <0699ed24-9603-48f5-b5bd-859dbed1da5c@icloud.com> (raw)
In-Reply-To: <ZypT18RpHSd_Vb-o@hovoldconsulting.com>

On 2024/11/6 01:20, Johan Hovold wrote:
> On Sat, Nov 02, 2024 at 11:53:46AM +0800, Zijun Hu wrote:
>> From: Zijun Hu <quic_zijuhu@quicinc.com>
>>
>> _of_phy_get() will directly return when suffers of_device_is_compatible()
>> error, but it forgets to decrease refcount of OF node @args.np before error
>> return, the refcount was increased by previous of_parse_phandle_with_args()
>> so causes the OF node's refcount leakage.
>>
>> Fix by decreasing the refcount via of_node_put() before the error return.
>>
>> Fixes: b7563e2796f8 ("phy: work around 'phys' references to usb-nop-xceiv devices")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
>> ---
>>  drivers/phy/phy-core.c | 9 ++++++---
>>  1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
>> index 52ca590a58b9..3127c5d9c637 100644
>> --- a/drivers/phy/phy-core.c
>> +++ b/drivers/phy/phy-core.c
>> @@ -624,13 +624,15 @@ static struct phy *_of_phy_get(struct device_node *np, int index)
>>  	struct of_phandle_args args;
>>  
>>  	ret = of_parse_phandle_with_args(np, "phys", "#phy-cells",
>> -		index, &args);
>> +					 index, &args);
> 
> This is an unrelated change which do not belong in this patch (and even
> more so as it is a fix that is marked for backporting).
> 

make sense.
will remove it for next revision. (^^)

>>  	if (ret)
>>  		return ERR_PTR(-ENODEV);
>>  
>>  	/* This phy type handled by the usb-phy subsystem for now */
>> -	if (of_device_is_compatible(args.np, "usb-nop-xceiv"))
>> -		return ERR_PTR(-ENODEV);
>> +	if (of_device_is_compatible(args.np, "usb-nop-xceiv")) {
>> +		phy = ERR_PTR(-ENODEV);
>> +		goto out_put_node;
>> +	}
>>  
>>  	mutex_lock(&phy_provider_mutex);
>>  	phy_provider = of_phy_provider_lookup(args.np);
>> @@ -652,6 +654,7 @@ static struct phy *_of_phy_get(struct device_node *np, int index)
>>  
>>  out_unlock:
>>  	mutex_unlock(&phy_provider_mutex);
>> +out_put_node:
>>  	of_node_put(args.np);
>>  
>>  	return phy;A
> 
> With the above fixed:
> 
> Reviewed-by: Johan Hovold <johan+linaro@kernel.org>


  reply	other threads:[~2024-11-06 15:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-02  3:53 [PATCH v4 0/6] phy: core: Fix bugs for several APIs and simplify an API Zijun Hu
2024-11-02  3:53 ` [PATCH v4 1/6] phy: core: Fix that API devm_phy_put() fails to release the phy Zijun Hu
2024-11-05 17:13   ` Johan Hovold
2024-11-02  3:53 ` [PATCH v4 2/6] phy: core: Fix that API devm_of_phy_provider_unregister() fails to unregister the phy provider Zijun Hu
2024-11-05 17:15   ` Johan Hovold
2024-11-02  3:53 ` [PATCH v4 3/6] phy: core: Fix that API devm_phy_destroy() fails to destroy the phy Zijun Hu
2024-11-05 17:17   ` Johan Hovold
2024-11-02  3:53 ` [PATCH v4 4/6] phy: core: Fix an OF node refcount leakage in _of_phy_get() Zijun Hu
2024-11-05 17:20   ` Johan Hovold
2024-11-06 15:28     ` Zijun Hu [this message]
2024-11-02  3:53 ` [PATCH v4 5/6] phy: core: Fix an OF node refcount leakage in of_phy_provider_lookup() Zijun Hu
2024-11-02  3:53 ` [PATCH v4 6/6] phy: core: Simplify API of_phy_simple_xlate() implementation Zijun Hu

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=0699ed24-9603-48f5-b5bd-859dbed1da5c@icloud.com \
    --to=zijun_hu@icloud.com \
    --cc=arnd@arndb.de \
    --cc=balbi@ti.com \
    --cc=bhelgaas@google.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=kishon@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kw@linux.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=lpieralisi@kernel.org \
    --cc=pabeni@redhat.com \
    --cc=quic_zijuhu@quicinc.com \
    --cc=robh@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=vkoul@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

all inboxes | Powered by JetHome®