All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Zijun Hu <zijun_hu@icloud.com>
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 v2 1/6] phy: core: Fix that API devm_phy_put() fails to release the phy
Date: Tue, 29 Oct 2024 14:40:01 +0100	[thread overview]
Message-ID: <ZyDlsWaA5aiRa_ry@hovoldconsulting.com> (raw)
In-Reply-To: <20241024-phy_core_fix-v2-1-fc0c63dbfcf3@quicinc.com>

On Thu, Oct 24, 2024 at 10:39:26PM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> For devm_phy_put(), its comment says it needs to invoke phy_put() to
> release the phy, but it does not invoke the function actually since
> devres_destroy() will not call devm_phy_release() at all which will
> call the function, and the missing phy_put() call will cause:

Please split the above up in at least two sentences to make it easier to
parse. Split it after devm_phy_release() and rephrase the latter part
(e.g. by dropping "at all which will call the function").
 
> - The phy fails to be released.
> - devm_phy_put() can not fully undo what API devm_phy_get() does.
> - Leak refcount of both the module and device for below typical usage:
> 
>   devm_phy_get(); // or its variant
>   ...
>   err = do_something();
>   if (err)
>       goto err_out;
>   ...
>   err_out:
>   devm_phy_put();
> 
>   The file(s) affected by this issue are shown below since they have such
>   typical usage.
>   drivers/pci/controller/cadence/pcie-cadence.c
>   drivers/net/ethernet/ti/am65-cpsw-nuss.c
> 
> Fixed by using devres_release() instead of devres_destroy() within the API
> 
> Fixes: ff764963479a ("drivers: phy: add generic PHY framework")
> Cc: stable@vger.kernel.org
> Cc: Lorenzo Pieralisi <lpieralisi@kernel.org>
> Cc: "Krzysztof Wilczyński" <kw@linux.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>

Diff itself looks good. Nice find.

Johan

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

WARNING: multiple messages have this Message-ID (diff)
From: Johan Hovold <johan@kernel.org>
To: Zijun Hu <zijun_hu@icloud.com>
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 v2 1/6] phy: core: Fix that API devm_phy_put() fails to release the phy
Date: Tue, 29 Oct 2024 14:40:01 +0100	[thread overview]
Message-ID: <ZyDlsWaA5aiRa_ry@hovoldconsulting.com> (raw)
In-Reply-To: <20241024-phy_core_fix-v2-1-fc0c63dbfcf3@quicinc.com>

On Thu, Oct 24, 2024 at 10:39:26PM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> For devm_phy_put(), its comment says it needs to invoke phy_put() to
> release the phy, but it does not invoke the function actually since
> devres_destroy() will not call devm_phy_release() at all which will
> call the function, and the missing phy_put() call will cause:

Please split the above up in at least two sentences to make it easier to
parse. Split it after devm_phy_release() and rephrase the latter part
(e.g. by dropping "at all which will call the function").
 
> - The phy fails to be released.
> - devm_phy_put() can not fully undo what API devm_phy_get() does.
> - Leak refcount of both the module and device for below typical usage:
> 
>   devm_phy_get(); // or its variant
>   ...
>   err = do_something();
>   if (err)
>       goto err_out;
>   ...
>   err_out:
>   devm_phy_put();
> 
>   The file(s) affected by this issue are shown below since they have such
>   typical usage.
>   drivers/pci/controller/cadence/pcie-cadence.c
>   drivers/net/ethernet/ti/am65-cpsw-nuss.c
> 
> Fixed by using devres_release() instead of devres_destroy() within the API
> 
> Fixes: ff764963479a ("drivers: phy: add generic PHY framework")
> Cc: stable@vger.kernel.org
> Cc: Lorenzo Pieralisi <lpieralisi@kernel.org>
> Cc: "Krzysztof Wilczyński" <kw@linux.com>
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>

Diff itself looks good. Nice find.

Johan

  reply	other threads:[~2024-10-29 13:42 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-24 14:39 [PATCH v2 0/6] phy: core: Fix bugs for several APIs and simplify an API Zijun Hu
2024-10-24 14:39 ` Zijun Hu
2024-10-24 14:39 ` [PATCH v2 1/6] phy: core: Fix that API devm_phy_put() fails to release the phy Zijun Hu
2024-10-24 14:39   ` Zijun Hu
2024-10-29 13:40   ` Johan Hovold [this message]
2024-10-29 13:40     ` Johan Hovold
2024-10-29 15:22     ` Zijun Hu
2024-10-29 15:22       ` Zijun Hu
2024-10-24 14:39 ` [PATCH v2 2/6] phy: core: Fix that API devm_of_phy_provider_unregister() fails to unregister the phy provider Zijun Hu
2024-10-24 14:39   ` Zijun Hu
2024-10-29 13:43   ` Johan Hovold
2024-10-29 13:43     ` Johan Hovold
2024-10-29 15:35     ` Zijun Hu
2024-10-29 15:35       ` Zijun Hu
2024-10-29 16:20       ` Johan Hovold
2024-10-29 16:20         ` Johan Hovold
2024-10-24 14:39 ` [PATCH v2 3/6] phy: core: Fix that API devm_phy_destroy() fails to destroy the phy Zijun Hu
2024-10-24 14:39   ` Zijun Hu
2024-10-29 13:45   ` Johan Hovold
2024-10-29 13:45     ` Johan Hovold
2024-10-29 15:38     ` Zijun Hu
2024-10-29 15:38       ` Zijun Hu
2024-10-24 14:39 ` [PATCH v2 4/6] phy: core: Fix an OF node refcount leakage in _of_phy_get() Zijun Hu
2024-10-24 14:39   ` Zijun Hu
2024-10-29 13:47   ` Johan Hovold
2024-10-29 13:47     ` Johan Hovold
2024-10-29 15:41     ` Zijun Hu
2024-10-29 15:41       ` Zijun Hu
2024-10-24 14:39 ` [PATCH v2 5/6] phy: core: Fix an OF node refcount leakage in of_phy_provider_lookup() Zijun Hu
2024-10-24 14:39   ` Zijun Hu
2024-10-29 13:48   ` Johan Hovold
2024-10-29 13:48     ` Johan Hovold
2024-10-24 14:39 ` [PATCH v2 6/6] phy: core: Simplify API of_phy_simple_xlate() implementation Zijun Hu
2024-10-24 14:39   ` Zijun Hu
2024-10-24 14:42   ` kernel test robot

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=ZyDlsWaA5aiRa_ry@hovoldconsulting.com \
    --to=johan@kernel.org \
    --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=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 \
    --cc=zijun_hu@icloud.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 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.