From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>,
Maxime Chevallier <maxime.chevallier@bootlin.com>,
Huacai Chen <chenhuacai@loongson.cn>,
Jakub Kicinski <kuba@kernel.org>, Sasha Levin <sashal@kernel.org>,
mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com,
rmk+kernel@armlinux.org.uk, andrew@lunn.ch, 0x1207@gmail.com,
pabeni@redhat.com, alexandre.f.demers@gmail.com,
netdev@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH AUTOSEL 6.17-5.10] net: stmmac: Check stmmac_hw_setup() in stmmac_resume()
Date: Sat, 25 Oct 2025 11:59:22 -0400 [thread overview]
Message-ID: <20251025160905.3857885-331-sashal@kernel.org> (raw)
In-Reply-To: <20251025160905.3857885-1-sashal@kernel.org>
From: Tiezhu Yang <yangtiezhu@loongson.cn>
[ Upstream commit 6896c2449a1858acb643014894d01b3a1223d4e5 ]
stmmac_hw_setup() may return 0 on success and an appropriate negative
integer as defined in errno.h file on failure, just check it and then
return early if failed in stmmac_resume().
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
Link: https://patch.msgid.link/20250811073506.27513-2-yangtiezhu@loongson.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
YES
- What it fixes
- The resume path ignores the return value of stmmac_hw_setup(), which
is documented to return 0 on success or -errno on failure. See the
function signature and comment in
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3396. Inside that
function, critical steps like stmmac_init_dma_engine() can fail and
return -errno (e.g., invalid DMA configuration, failed reset), see
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3410.
- In the current resume path, the return from stmmac_hw_setup() is not
checked: drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:8033. The
code then proceeds to run initialization and enablement sequences
(e.g., stmmac_init_coalesce(), stmmac_set_rx_mode(),
stmmac_enable_all_queues(), stmmac_enable_all_dma_irq()), which
operate on hardware that may not be properly initialized after a
failure, risking hangs or crashes. These calls are at
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:8034,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:8035,
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:8039, and
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:8040,
respectively.
- The open path already does the right thing by checking the return
value and bailing on failure with an error message
(drivers/net/ethernet/stmicro/stmmac/stmmac_main.c:3977). The resume
path should be consistent with this.
- What the patch changes
- It assigns the return value of stmmac_hw_setup() to ret and checks
for errors. On error it logs and returns early after correctly
releasing the held locks (mutex_unlock and rtnl_unlock). This
prevents further use of uninitialized DMA/MAC state and keeps error
handling consistent with the open path.
- Scope and risk
- Minimal and contained: only the stmmac driver, no API/ABI changes,
no feature additions. The change is a straightforward error-path fix
and mirrors existing patterns in __stmmac_open().
- Locking is handled correctly: the new early-return path explicitly
releases both the private mutex and rtnl lock before returning,
avoiding deadlocks.
- User impact: prevents resume-time failures from cascading into
deeper faults by stopping early and reporting a clear error.
- Context and applicability
- Many stmmac glue drivers call stmmac_resume() directly, so this
affects a broad set of platforms (e.g.,
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c:1183,
drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c:2066).
- The fix does not depend on newer phylink changes (e.g.,
phylink_prepare_resume()). While newer mainline code refines phylink
sequencing, this error check is orthogonal and safe to apply to
stable branches that don’t have those changes.
- The stmmac_resume() in current stable series has the same
problematic pattern (call stmmac_hw_setup() without checking its
return), so the patch is directly relevant.
- Stable rules assessment
- Fixes a real bug that can lead to faults after resume.
- Small, localized change with minimal regression risk.
- No architectural or user-visible feature changes.
- Affects only the stmmac driver; well-scoped for backporting.
Conclusion: This is a clear, low-risk bug fix that prevents unsafe
continuation after hardware initialization failures during resume. It
should be backported to stable kernels.
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 7b16d1207b80c..b9f55e4e360fb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -7977,7 +7977,14 @@ int stmmac_resume(struct device *dev)
stmmac_free_tx_skbufs(priv);
stmmac_clear_descriptors(priv, &priv->dma_conf);
- stmmac_hw_setup(ndev, false);
+ ret = stmmac_hw_setup(ndev, false);
+ if (ret < 0) {
+ netdev_err(priv->dev, "%s: Hw setup failed\n", __func__);
+ mutex_unlock(&priv->lock);
+ rtnl_unlock();
+ return ret;
+ }
+
stmmac_init_coalesce(priv);
phylink_rx_clk_stop_block(priv->phylink);
stmmac_set_rx_mode(ndev);
--
2.51.0
next prev parent reply other threads:[~2025-10-25 16:24 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 ` [PATCH AUTOSEL 6.17-6.1] net: phy: fixed_phy: let fixed_phy_unregister free the phy_device Sasha Levin
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 ` Sasha Levin [this message]
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-331-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=0x1207@gmail.com \
--cc=alexandre.f.demers@gmail.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andrew@lunn.ch \
--cc=chenhuacai@loongson.cn \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=maxime.chevallier@bootlin.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=patches@lists.linux.dev \
--cc=rmk+kernel@armlinux.org.uk \
--cc=stable@vger.kernel.org \
--cc=yangtiezhu@loongson.cn \
/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).