From: Paolo Abeni <pabeni@redhat.com>
To: Aleksandr Mishin <amishin@t-argos.ru>,
Igal Liberman <igal.liberman@freescale.com>
Cc: Simon Horman <horms@kernel.org>,
Madalin Bucur <madalin.bucur@nxp.com>,
Sean Anderson <sean.anderson@seco.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
lvc-project@linuxtesting.org
Subject: Re: [PATCH net 2/2] fsl/fman: Fix refcount handling of fman-related devices
Date: Thu, 17 Oct 2024 12:01:01 +0200 [thread overview]
Message-ID: <a0aec660-c18b-4d85-b85b-58fce3668e64@redhat.com> (raw)
In-Reply-To: <20241015060122.25709-3-amishin@t-argos.ru>
On 10/15/24 08:01, Aleksandr Mishin wrote:
> In mac_probe() there are multiple calls to of_find_device_by_node(),
> fman_bind() and fman_port_bind() which takes references to of_dev->dev.
> Not all references taken by these calls are released later on error path
> in mac_probe() and in mac_remove() which lead to reference leaks.
>
> Add references release.
>
> Fixes: 3933961682a3 ("fsl/fman: Add FMan MAC driver")
> Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
> ---
> Compile tested only.
>
> drivers/net/ethernet/freescale/fman/mac.c | 62 +++++++++++++++++------
> 1 file changed, 47 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c
> index 9b863db0bf08..11da139082e1 100644
> --- a/drivers/net/ethernet/freescale/fman/mac.c
> +++ b/drivers/net/ethernet/freescale/fman/mac.c
> @@ -204,7 +204,7 @@ static int mac_probe(struct platform_device *_of_dev)
> if (err) {
> dev_err(dev, "failed to read cell-index for %pOF\n", dev_node);
> err = -EINVAL;
> - goto _return_of_node_put;
> + goto _return_dev_put;
We are after a succesful of_find_device_by_node and prior to
fman_bind(), mac_dev->fman_dev refcount is 1
> @@ -213,40 +213,51 @@ static int mac_probe(struct platform_device *_of_dev)
> if (!priv->fman) {
> dev_err(dev, "fman_bind(%pOF) failed\n", dev_node);
> err = -ENODEV;
> - goto _return_of_node_put;
> + goto _return_dev_put;
> }
>
> + /* Two references have been taken in of_find_device_by_node()
> + * and fman_bind(). Release one of them here. The second one
> + * will be released in mac_remove().
> + */
> + put_device(mac_dev->fman_dev);
> of_node_put(dev_node);
> + dev_node = NULL;
>
> /* Get the address of the memory mapped registers */
> mac_dev->res = platform_get_mem_or_io(_of_dev, 0);
> if (!mac_dev->res) {
> dev_err(dev, "could not get registers\n");
> - return -EINVAL;
> + err = -EINVAL;
> + goto _return_dev_put;
Here we are after a successful fman_bind(), mac_dev->fman_dev refcount
is 2. _return_dev_put will drop a single reference, this error path
looks buggy.
Similar issue for the _return_dev_arr_put error path below.
Cheers,
Paolo
next prev parent reply other threads:[~2024-10-17 10:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 6:01 [PATCH net 0/2] " Aleksandr Mishin
2024-10-15 6:01 ` [PATCH net 1/2] fsl/fman: Save device references taken in mac_probe() Aleksandr Mishin
2024-10-15 6:01 ` [PATCH net 2/2] fsl/fman: Fix refcount handling of fman-related devices Aleksandr Mishin
2024-10-17 10:01 ` Paolo Abeni [this message]
2024-10-17 10:53 ` Aleksandr Mishin
2024-10-21 9:20 ` [PATCH net 0/2] " patchwork-bot+netdevbpf
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=a0aec660-c18b-4d85-b85b-58fce3668e64@redhat.com \
--to=pabeni@redhat.com \
--cc=amishin@t-argos.ru \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=igal.liberman@freescale.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=madalin.bucur@nxp.com \
--cc=netdev@vger.kernel.org \
--cc=sean.anderson@seco.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
all inboxes | Powered by JetHome®