[PATCH net v2] net: calxeda: disable timeout work across ring teardown

From: Hongyan Xu

Date: Sun Nov 15 2026 - 06:48:59 EST


Both the watchdog and the TPS interrupt can queue timeout work. A simple
cancel cannot exclude them during a direct MTU stop/open cycle, and
waiting for the worker after disabling NAPI can deadlock on a second
napi_disable.

Initialize timeout work disabled, enable it only after ring allocation and
NAPI initialization, and disable and drain it before stopping NAPI. Keep
the NAPI-before-TX-disable order so neither a poll nor the recovery worker
can wake TX after its final shutdown. Synchronize the IRQ and re-mask it
after NAPI has stopped, and perform a final work drain before freeing
private state.

Track allocated rings and NAPI enablement explicitly, and give interface
down and system suspend separate references on the work disable counter.
Each path then disables once and enables once, so a concurrent suspend and
ifdown cannot leave the recovery work disabled forever. A failed MTU
reopen must not disable NAPI or work a second time, or free ring pointers
left by a failed allocation.

Found by the author's in-house static analysis tool.

Fixes: 85c10f282861 ("net: add calxeda xgmac ethernet driver")
Cc: stable@xxxxxxxxxxxxxxx
Link: https://lore.kernel.org/all/20260928134115.1957-1-getshell@xxxxxxxxxx/
Signed-off-by: Hongyan Xu <getshell@xxxxxxxxxx>
Signed-off-by: Zehao Gao <gaozehao@xxxxxxxxx>
---

Discovery: found by the author's in-house static analysis tool.

drivers/net/ethernet/calxeda/xgmac.c | 60 +++++++++++++++++++++++++---
1 file changed, 54 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/calxeda/xgmac.c b/drivers/net/ethernet/calxeda/xgmac.c
index a2410fb..61ffdbe 100644
--- a/drivers/net/ethernet/calxeda/xgmac.c
+++ b/drivers/net/ethernet/calxeda/xgmac.c
@@ -380,6 +380,10 @@ struct xgmac_priv {
char tx_pause;
int wolopts;
struct work_struct tx_timeout_work;
+ bool rings_ready;
+ bool napi_enabled;
+ bool work_disabled_down;
+ bool work_disabled_pm;
};

/* XGMAC Configuration Settings */
@@ -1027,6 +1031,12 @@ static int xgmac_open(struct net_device *dev)
xgmac_mac_enable(ioaddr);

napi_enable(&priv->napi);
+ priv->napi_enabled = true;
+ priv->rings_ready = true;
+ if (priv->work_disabled_down) {
+ enable_work(&priv->tx_timeout_work);
+ priv->work_disabled_down = false;
+ }
netif_start_queue(dev);

/* Enable interrupts */
@@ -1046,9 +1056,21 @@ static int xgmac_stop(struct net_device *dev)
{
struct xgmac_priv *priv = netdev_priv(dev);

- if (readl(priv->base + XGMAC_DMA_INTR_ENA))
+ if (!priv->rings_ready)
+ return 0;
+
+ if (!priv->work_disabled_down) {
+ disable_work_sync(&priv->tx_timeout_work);
+ priv->work_disabled_down = true;
+ }
+ if (priv->napi_enabled) {
napi_disable(&priv->napi);
+ priv->napi_enabled = false;
+ }

+ writel(0, priv->base + XGMAC_DMA_INTR_ENA);
+ synchronize_irq(dev->irq);
+ /* An in-flight interrupt may have restored the interrupt mask. */
writel(0, priv->base + XGMAC_DMA_INTR_ENA);

netif_tx_disable(dev);
@@ -1058,6 +1080,7 @@ static int xgmac_stop(struct net_device *dev)

/* Release and free the Rx/Tx resources */
xgmac_free_dma_desc_rings(priv);
+ priv->rings_ready = false;

return 0;
}
@@ -1713,6 +1736,8 @@ static int xgmac_probe(struct platform_device *pdev)
ndev->ethtool_ops = &xgmac_ethtool_ops;
spin_lock_init(&priv->stats_lock);
INIT_WORK(&priv->tx_timeout_work, xgmac_tx_timeout_work);
+ disable_work(&priv->tx_timeout_work);
+ priv->work_disabled_down = true;

priv->device = &pdev->dev;
priv->dev = ndev;
@@ -1830,6 +1855,7 @@ static void xgmac_remove(struct platform_device *pdev)
free_irq(priv->pmt_irq, ndev);

unregister_netdev(ndev);
+ disable_work_sync(&priv->tx_timeout_work);
netif_napi_del(&priv->napi);

iounmap(priv->base);
@@ -1858,11 +1884,18 @@ static int xgmac_suspend(struct device *dev)
struct xgmac_priv *priv = netdev_priv(ndev);
u32 value;

- if (!ndev || !netif_running(ndev))
+ if (!ndev || !netif_running(ndev) || !priv->rings_ready)
return 0;

netif_device_detach(ndev);
- napi_disable(&priv->napi);
+ if (!priv->work_disabled_pm) {
+ disable_work_sync(&priv->tx_timeout_work);
+ priv->work_disabled_pm = true;
+ }
+ if (priv->napi_enabled) {
+ napi_disable(&priv->napi);
+ priv->napi_enabled = false;
+ }
writel(0, priv->base + XGMAC_DMA_INTR_ENA);

if (device_may_wakeup(priv->device)) {
@@ -1884,18 +1917,33 @@ static int xgmac_resume(struct device *dev)
struct xgmac_priv *priv = netdev_priv(ndev);
void __iomem *ioaddr = priv->base;

- if (!netif_running(ndev))
+ if (!netif_running(ndev) || !priv->rings_ready) {
+ /* Drop the reference taken by suspend, even when the
+ * interface was brought down while the system slept.
+ */
+ if (priv->work_disabled_pm) {
+ enable_work(&priv->tx_timeout_work);
+ priv->work_disabled_pm = false;
+ }
return 0;
+ }

xgmac_pmt(ioaddr, 0);

- /* Enable the MAC and DMA */
+ /* Enable NAPI and timeout recovery before interrupt publication. */
+ if (!priv->napi_enabled) {
+ napi_enable(&priv->napi);
+ priv->napi_enabled = true;
+ }
+ if (priv->work_disabled_pm) {
+ enable_work(&priv->tx_timeout_work);
+ priv->work_disabled_pm = false;
+ }
xgmac_mac_enable(ioaddr);
writel(DMA_INTR_DEFAULT_MASK, ioaddr + XGMAC_DMA_STATUS);
writel(DMA_INTR_DEFAULT_MASK, ioaddr + XGMAC_DMA_INTR_ENA);

netif_device_attach(ndev);
- napi_enable(&priv->napi);

return 0;
}
--
2.50.1.windows.1