Linux-RISC-V Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v3] net: spacemit: Check netif_running() in emac_set_pauseparam()
@ 2025-11-03  2:02 Vivian Wang
  2025-11-03 15:12 ` Andrew Lunn
  2025-11-04  1:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Vivian Wang @ 2025-11-03  2:02 UTC (permalink / raw)
  To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Yixun Lan, Maxime Chevallier, Troy Mitchell,
	Vadim Fedorenko, Vivian Wang
  Cc: netdev, linux-riscv, spacemit, linux-kernel

Currently, emac_set_pauseparam() will oops if userspace calls it while
the interface is not up, because phydev is NULL, but it is still
accessed in emac_set_fc() and emac_set_fc_autoneg().

Check for netif_running(dev) in emac_set_pauseparam() before proceeding.

Fixes: bfec6d7f2001 ("net: spacemit: Add K1 Ethernet MAC")
Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
---
This more urgent problem was discovered while trying to fix
emac_set_pauseparam() (v1 of that has already been sent to the mailing
lists [1], but it was still bad), so I decided to send this patch for
the net tree now so that this oops will not happen on 6.18. A future
version of the proper flow control implementation will be sent to
net-next.

[1]: https://lore.kernel.org/spacemit/20251030-k1-ethernet-fix-autoneg-v1-1-baa572607ccc@iscas.ac.cn
---
Changes in v3:
- Check netif_running() instead (Andrew)
- Add back blurb about the attempt to fix flow control for context
- Link to v2: https://lore.kernel.org/r/20251101-k1-ethernet-remove-fc-v2-1-014ac3bc280e@iscas.ac.cn

Changes in v2:
- Reduced patch to only contain checking IFF_UP to avoid the oops. More
  invasive changes will be sent to net-next in the future. (Andrew)
- Link to v1: https://lore.kernel.org/r/20251031-k1-ethernet-remove-fc-v1-1-1ae3f1d6508c@iscas.ac.cn
---
 drivers/net/ethernet/spacemit/k1_emac.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/spacemit/k1_emac.c b/drivers/net/ethernet/spacemit/k1_emac.c
index e1c5faff3b71..220eb5ce7583 100644
--- a/drivers/net/ethernet/spacemit/k1_emac.c
+++ b/drivers/net/ethernet/spacemit/k1_emac.c
@@ -1441,6 +1441,9 @@ static int emac_set_pauseparam(struct net_device *dev,
 	struct emac_priv *priv = netdev_priv(dev);
 	u8 fc = 0;
 
+	if (!netif_running(dev))
+		return -ENETDOWN;
+
 	priv->flow_control_autoneg = pause->autoneg;
 
 	if (pause->autoneg) {

---
base-commit: 3a8660878839faadb4f1a6dd72c3179c1df56787
change-id: 20251031-k1-ethernet-remove-fc-82fd67d889a6

Best regards,
-- 
Vivian "dramforever" Wang


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net v3] net: spacemit: Check netif_running() in emac_set_pauseparam()
  2025-11-03  2:02 [PATCH net v3] net: spacemit: Check netif_running() in emac_set_pauseparam() Vivian Wang
@ 2025-11-03 15:12 ` Andrew Lunn
  2025-11-04  1:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2025-11-03 15:12 UTC (permalink / raw)
  To: Vivian Wang
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Yixun Lan, Maxime Chevallier, Troy Mitchell,
	Vadim Fedorenko, netdev, linux-riscv, spacemit, linux-kernel

On Mon, Nov 03, 2025 at 10:02:49AM +0800, Vivian Wang wrote:
> Currently, emac_set_pauseparam() will oops if userspace calls it while
> the interface is not up, because phydev is NULL, but it is still
> accessed in emac_set_fc() and emac_set_fc_autoneg().
> 
> Check for netif_running(dev) in emac_set_pauseparam() before proceeding.
> 
> Fixes: bfec6d7f2001 ("net: spacemit: Add K1 Ethernet MAC")
> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net v3] net: spacemit: Check netif_running() in emac_set_pauseparam()
  2025-11-03  2:02 [PATCH net v3] net: spacemit: Check netif_running() in emac_set_pauseparam() Vivian Wang
  2025-11-03 15:12 ` Andrew Lunn
@ 2025-11-04  1:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-11-04  1:40 UTC (permalink / raw)
  To: Vivian Wang
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, dlan,
	maxime.chevallier, troy.mitchell, vadim.fedorenko, netdev,
	linux-riscv, spacemit, linux-kernel

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 03 Nov 2025 10:02:49 +0800 you wrote:
> Currently, emac_set_pauseparam() will oops if userspace calls it while
> the interface is not up, because phydev is NULL, but it is still
> accessed in emac_set_fc() and emac_set_fc_autoneg().
> 
> Check for netif_running(dev) in emac_set_pauseparam() before proceeding.
> 
> Fixes: bfec6d7f2001 ("net: spacemit: Add K1 Ethernet MAC")
> Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
> 
> [...]

Here is the summary with links:
  - [net,v3] net: spacemit: Check netif_running() in emac_set_pauseparam()
    https://git.kernel.org/netdev/net/c/5556f23478e6

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-04  1:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-03  2:02 [PATCH net v3] net: spacemit: Check netif_running() in emac_set_pauseparam() Vivian Wang
2025-11-03 15:12 ` Andrew Lunn
2025-11-04  1:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox