From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Heiner Kallweit <hkallweit1@gmail.com>,
"Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>,
Jakub Kicinski <kuba@kernel.org>, Sasha Levin <sashal@kernel.org>,
andrew@lunn.ch, olteanv@gmail.com, netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 6.17-6.1] net: phy: fixed_phy: let fixed_phy_unregister free the phy_device
Date: Sat, 25 Oct 2025 11:53:54 -0400 [thread overview]
Message-ID: <20251025160905.3857885-3-sashal@kernel.org> (raw)
In-Reply-To: <20251025160905.3857885-1-sashal@kernel.org>
From: Heiner Kallweit <hkallweit1@gmail.com>
[ Upstream commit a0f849c1cc6df0db9083b4c81c05a5456b1ed0fb ]
fixed_phy_register() creates and registers the phy_device. To be
symmetric, we should not only unregister, but also free the phy_device
in fixed_phy_unregister(). This allows to simplify code in users.
Note wrt of_phy_deregister_fixed_link():
put_device(&phydev->mdio.dev) and phy_device_free(phydev) are identical.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://patch.msgid.link/ad8dda9a-10ed-4060-916b-3f13bdbb899d@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
YES
- Fix rationale and scope
- The change fixes an API asymmetry and a potential memory leak:
`fixed_phy_register()` allocates and registers a `phy_device`, but
pre‑patch `fixed_phy_unregister()` only removed it without freeing.
The commit makes `fixed_phy_unregister()` also free the
`phy_device`, preventing leaks and simplifying callers.
- The change is small and localized to fixed PHY/MDIO code; it does
not alter uAPI or architecture.
- Core change
- `drivers/net/phy/fixed_phy.c:230` now frees the `phy_device` after
removal:
- Calls `phy_device_remove(phy)`, `of_node_put(...)`,
`fixed_phy_del(...)`, and then `phy_device_free(phy)` to drop the
device reference and free when the refcount reaches zero.
- `phy_device_free()` is just a `put_device(&phydev->mdio.dev)`:
- `drivers/net/phy/phy_device.c:212` confirms that
`phy_device_free()` equals a `put_device`, matching the commit
note about identical behavior.
- Callers adjusted to avoid double-free
- `drivers/net/dsa/dsa_loop.c:398` removes the explicit
`phy_device_free(phydevs[i])` after
`fixed_phy_unregister(phydevs[i])`.
- `drivers/net/mdio/of_mdio.c:475` now calls only
`fixed_phy_unregister(phydev)` followed by
`put_device(&phydev->mdio.dev)` at `drivers/net/mdio/of_mdio.c:477`,
which correctly drops the extra reference obtained by
`of_phy_find_device(np)` (see `drivers/net/mdio/of_mdio.c:471`).
This is safe because `fixed_phy_unregister()`’s `phy_device_free()`
and the extra `put_device()` account for two separate refs (the
device’s own and the one grabbed by `of_phy_find_device()`).
- Other in-tree users remain correct and benefit
- Callers which already did not free explicitly remain correct and now
won’t leak:
- Example: `drivers/net/ethernet/faraday/ftgmac100.c:1763` calls
`fixed_phy_unregister(phydev)` (after `phy_disconnect()`), and
does not call `phy_device_free()`.
- `drivers/net/ethernet/hisilicon/hibmcge/hbg_mdio.c:236` similarly
calls only `fixed_phy_unregister((struct phy_device *)data)`.
- We searched for all in-tree callers of `fixed_phy_unregister()` and
`of_phy_deregister_fixed_link()` and found no remaining explicit
frees which would cause a double free.
- Risk and stable suitability
- Minimal regression risk: change is contained, behavior is well-
defined, and in‑tree callers are updated or already compatible. No
architectural changes; no uAPI impact.
- Positive impact: fixes a likely leak for paths that didn’t free
after unregister (e.g., NCSI fixed PHY path in `ftgmac100`).
- Meets stable criteria: it’s a bug fix (memory management), small and
self-contained, with low risk of regression.
drivers/net/dsa/dsa_loop.c | 9 +++------
drivers/net/mdio/of_mdio.c | 1 -
drivers/net/phy/fixed_phy.c | 1 +
3 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/net/dsa/dsa_loop.c b/drivers/net/dsa/dsa_loop.c
index d8a35f25a4c82..ad907287a853a 100644
--- a/drivers/net/dsa/dsa_loop.c
+++ b/drivers/net/dsa/dsa_loop.c
@@ -386,13 +386,10 @@ static struct mdio_driver dsa_loop_drv = {
static void dsa_loop_phydevs_unregister(void)
{
- unsigned int i;
-
- for (i = 0; i < NUM_FIXED_PHYS; i++)
- if (!IS_ERR(phydevs[i])) {
+ for (int i = 0; i < NUM_FIXED_PHYS; i++) {
+ if (!IS_ERR(phydevs[i]))
fixed_phy_unregister(phydevs[i]);
- phy_device_free(phydevs[i]);
- }
+ }
}
static int __init dsa_loop_init(void)
diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c
index 98f667b121f7d..d8ca63ed87194 100644
--- a/drivers/net/mdio/of_mdio.c
+++ b/drivers/net/mdio/of_mdio.c
@@ -473,6 +473,5 @@ void of_phy_deregister_fixed_link(struct device_node *np)
fixed_phy_unregister(phydev);
put_device(&phydev->mdio.dev); /* of_phy_find_device() */
- phy_device_free(phydev); /* fixed_phy_register() */
}
EXPORT_SYMBOL(of_phy_deregister_fixed_link);
diff --git a/drivers/net/phy/fixed_phy.c b/drivers/net/phy/fixed_phy.c
index 033656d574b89..b8bec7600ef8e 100644
--- a/drivers/net/phy/fixed_phy.c
+++ b/drivers/net/phy/fixed_phy.c
@@ -309,6 +309,7 @@ void fixed_phy_unregister(struct phy_device *phy)
phy_device_remove(phy);
of_node_put(phy->mdio.dev.of_node);
fixed_phy_del(phy->mdio.addr);
+ phy_device_free(phy);
}
EXPORT_SYMBOL_GPL(fixed_phy_unregister);
--
2.51.0
next parent reply other threads:[~2025-10-25 16:09 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20251025160905.3857885-1-sashal@kernel.org>
2025-10-25 15:53 ` Sasha Levin [this message]
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17-5.4] ipv6: np->rxpmtu race annotation Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17-6.6] net: stmmac: Correctly handle Rx checksum offload errors Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17-6.12] PCI/ERR: Update device error_state already after reset Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17-6.1] selftests: net: replace sleeps in fcnal-test with waits Sasha Levin
2025-10-25 15:54 ` [PATCH AUTOSEL 6.17-5.4] selftests/net: Replace non-standard __WORDSIZE with sizeof(long) * 8 Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-6.12] bnxt_en: Add Hyper-V VF ID Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-5.4] selftests/net: Ensure assert() triggers in psock_tpacket.c Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-5.4] net: When removing nexthops, don't call synchronize_net if it is not necessary Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17] netlink: specs: fou: change local-v6/peer-v6 check Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-6.1] smsc911x: add second read of EEPROM mac when possible corruption seen Sasha Levin
2025-10-28 12:53 ` Colin Foster
2025-11-04 13:55 ` Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-5.4] net: sh_eth: Disable WoL if system can not suspend Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17] bnxt_en: Add fw log trace support for 5731X/5741X chips Sasha Levin
2025-10-25 15:55 ` [PATCH AUTOSEL 6.17-5.10] udp_tunnel: use netdev_warn() instead of netdev_WARN() Sasha Levin
2025-10-25 15:56 ` [PATCH AUTOSEL 6.17] tcp: Update bind bucket state on port release Sasha Levin
2025-10-25 15:56 ` [PATCH AUTOSEL 6.17-6.1] net: bridge: Install FDB for bridge MAC on VLAN 0 Sasha Levin
2025-10-25 15:56 ` [PATCH AUTOSEL 6.17] selftest: net: Fix error message if empty variable Sasha Levin
2025-10-25 15:56 ` [PATCH AUTOSEL 6.17] net: phy: dp83640: improve phydev and driver removal handling Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-5.4] selftests: Disable dad for ipv6 in fcnal-test.sh Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-6.6] net: phy: clear link parameters on admin link down Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17] net: Prevent RPS table overwrite of active flows Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-5.10] r8169: set EEE speed down ratio to 1 Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-5.4] rds: Fix endianness annotation for RDS_MPATH_HASH Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-6.12] net: stmmac: est: Drop frames causing HLBS error Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-6.12] net: ipv4: allow directed broadcast routes to use dst hint Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-6.12] net: dsa: felix: support phy-mode = "10g-qxgmii" Sasha Levin
2025-10-25 15:57 ` [PATCH AUTOSEL 6.17-5.4] net: ipv6: fix field-spanning memcpy warning in AH output Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17-6.12] net: dsa: microchip: Set SPI as bus interface during reset for KSZ8463 Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17] net/mlx5e: Prevent entering switchdev mode with inconsistent netns Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17-6.12] microchip: lan865x: add ndo_eth_ioctl handler to enable PHY ioctl support Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17] Octeontx2-af: Broadcast XON on all channels Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17] hinic3: Queue pair endianness improvements Sasha Levin
2025-10-25 15:58 ` [PATCH AUTOSEL 6.17-6.12] tcp: use dst_dev_rcu() in tcp_fastopen_active_disable_ofo_check() Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17] selftests: net: lib.sh: Don't defer failed commands Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17] ptp_ocp: make ptp_ocp driver compatible with PTP_EXTTS_REQUEST2 Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17-5.10] selftests: traceroute: Use require_command() Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17-5.10] net: stmmac: Check stmmac_hw_setup() in stmmac_resume() Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17-5.10] ipv6: Add sanity checks on ipv6_devconf.rpl_seg_enabled Sasha Levin
2025-10-25 15:59 ` [PATCH AUTOSEL 6.17-6.1] net/mlx5e: Don't query FEC statistics when FEC is disabled Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17] bng_en: make bnge_alloc_ring() self-unwind on failure Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-5.4] page_pool: Clamp pool size to max 16K pages Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17] selftests: drv-net: hds: restore hds settings Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-6.12] selftests: traceroute: Return correct value on failure Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-5.4] bridge: Redirect to backup port when port is administratively down Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-6.12] net: devmem: expose tcp_recvmsg_locked errors Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17] net: phy: clear EEE runtime state in PHY_HALTED/PHY_ERROR Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-6.12] selftests: mptcp: join: allow more time to send ADD_ADDR Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-5.10] net: phy: marvell: Fix 88e1510 downshift counter errata Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17] selftests: net: make the dump test less sensitive to mem accounting Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17-5.4] net: nfc: nci: Increase NCI_DATA_TIMEOUT to 3000 ms Sasha Levin
2025-10-25 16:00 ` [PATCH AUTOSEL 6.17] hinic3: Fix missing napi->dev in netif_queue_set_napi Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17-5.4] selftests: Replace sleep with slowwait Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17-6.12] inet_diag: annotate data-races in inet_diag_bc_sk() Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17-5.15] page_pool: always add GFP_NOWARN for ATOMIC allocations Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17-5.4] net/cls_cgroup: Fix task_get_classid() during qdisc run Sasha Levin
2025-10-25 16:01 ` [PATCH AUTOSEL 6.17-5.15] ptp: Limit time setting of PTP clocks Sasha Levin
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=20251025160905.3857885-3-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=andrew@lunn.ch \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=patches@lists.linux.dev \
--cc=rmk+kernel@armlinux.org.uk \
--cc=stable@vger.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;
as well as URLs for NNTP newsgroup(s).