mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yige Jiang <yigejiang86@gmail.com>
To: Madalin Bucur <madalin.bucur@nxp.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Yige Jiang <yigejiang86@gmail.com>,
	Sean Anderson <sean.anderson@linux.dev>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net] fsl/fman: Fix device reference leak in fman_bind() and fman_port_bind()
Date: Thu, 26 Nov 2026 20:25:02 +0800	[thread overview]
Message-ID: <rc-b1-20261110-vc-176-5127b53b8eab@gmail.com> (raw)

fman_bind() and fman_port_bind() call get_device() and return the
device's driver data. They keep the reference even when the driver
data is NULL, which happens when mac_probe() runs before the FMan or
FMan port driver has set it. mac_probe() then fails and drops only the
reference from its own of_find_device_by_node() call, so the reference
taken by the bind helper is leaked on each such probe.

The FMan and port devices are created from the device tree and are not
normally removed, so the leak has no visible effect in practice. The
NULL return on the FMan side was pointed out as a probe ordering
problem in a Sashiko review that Simon Horman forwarded to netdev in
July 2026. The reference leak was not mentioned there.

Drop the reference in both helpers when they return NULL. mac_probe()
is their only caller, and its success path is unchanged.

Fixes: 3933961682a3 ("fsl/fman: Add FMan MAC driver")
Link: https://lore.kernel.org/r/20260703074324.907294-1-zhaojinming@uniontech.com
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
Based on linux-next next-20261109 (630059a5a632).
Compile-tested: arm64, GCC 14.2.0, W=1, CONFIG_FSL_FMAN=y, CONFIG_FSL_DPAA=y, CONFIG_COMPILE_TEST=y; baseline and patched fman.o and fman_port.o, no new warnings.
No hardware or runtime test was performed.

The path needs mac_probe() to run before the FMan or FMan port device
has its driver data set (probe ordering or module load order).

 drivers/net/ethernet/freescale/fman/fman.c      | 7 ++++++-
 drivers/net/ethernet/freescale/fman/fman_port.c | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fman/fman.c b/drivers/net/ethernet/freescale/fman/fman.c
index 46cc28895e56..35a8e25ba993 100644
--- a/drivers/net/ethernet/freescale/fman/fman.c
+++ b/drivers/net/ethernet/freescale/fman/fman.c
@@ -2493,7 +2493,12 @@ EXPORT_SYMBOL(fman_get_rx_extra_headroom);
  */
 struct fman *fman_bind(struct device *fm_dev)
 {
-	return (struct fman *)(dev_get_drvdata(get_device(fm_dev)));
+	struct fman *fman = dev_get_drvdata(get_device(fm_dev));
+
+	if (!fman)
+		put_device(fm_dev);
+
+	return fman;
 }
 EXPORT_SYMBOL(fman_bind);
 
diff --git a/drivers/net/ethernet/freescale/fman/fman_port.c b/drivers/net/ethernet/freescale/fman/fman_port.c
index 1b8fef69114e..5d96521066a5 100644
--- a/drivers/net/ethernet/freescale/fman/fman_port.c
+++ b/drivers/net/ethernet/freescale/fman/fman_port.c
@@ -1684,7 +1684,12 @@ EXPORT_SYMBOL(fman_port_enable);
  */
 struct fman_port *fman_port_bind(struct device *dev)
 {
-	return (struct fman_port *)(dev_get_drvdata(get_device(dev)));
+	struct fman_port *port = dev_get_drvdata(get_device(dev));
+
+	if (!port)
+		put_device(dev);
+
+	return port;
 }
 EXPORT_SYMBOL(fman_port_bind);
 

base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
-- 
2.50.1 (Apple Git-155)


                 reply	other threads:[~2026-11-26 12:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=rc-b1-20261110-vc-176-5127b53b8eab@gmail.com \
    --to=yigejiang86@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=madalin.bucur@nxp.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sean.anderson@linux.dev \
    /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®