mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] net: ethernet: sunplus: check budget before calling napi_complete_done()
@ 2026-11-14 22:27 Janis Edvarts Lacis
  2026-11-15 15:50 ` Andrew Lunn
  2026-11-15 20:06 ` netdev-bot+sinfo
  0 siblings, 2 replies; 3+ messages in thread
From: Janis Edvarts Lacis @ 2026-11-14 22:27 UTC (permalink / raw)
  To: netdev
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, wellslutw,
	linux-kernel, Janis Edvarts Lacis

Sunplus drivers currently do napi_complete() after each rx/tx poll is
done without checking whether budget was exhausted or not. Interrupts
are also unmasked before the call to napi_complete().

Replace napi_complete() with napi_complete_done() and add a check for
budget_left. Call napi_complete_done() only when the budget has been
not exhausted fully, e.g. budget_left > 0 and unmask interrupts only when
napi_complete_done() returns true.

I do not have the hardware necessary, this patch is not tested on real
hardware.

Fixes: fd3040b9394c ("net: ethernet: Add driver for Sunplus SP7021")
Signed-off-by: Janis Edvarts Lacis <janislacis06@gmail.com>
---
 drivers/net/ethernet/sunplus/spl2sw_int.c | 26 ++++++++++++-----------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/sunplus/spl2sw_int.c b/drivers/net/ethernet/sunplus/spl2sw_int.c
index a37c9a4c281f..1aada11429d4 100644
--- a/drivers/net/ethernet/sunplus/spl2sw_int.c
+++ b/drivers/net/ethernet/sunplus/spl2sw_int.c
@@ -125,13 +125,14 @@ int spl2sw_rx_poll(struct napi_struct *napi, int budget)
 			h_desc = comm->rx_desc[queue] + rx_pos;
 	}
 
-	spin_lock_irqsave(&comm->int_mask_lock, flags);
-	mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
-	mask &= ~MAC_INT_RX;
-	writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
-	spin_unlock_irqrestore(&comm->int_mask_lock, flags);
+	if (budget_left > 0 && napi_complete_done(napi, budget - budget_left)) {
+		spin_lock_irqsave(&comm->int_mask_lock, flags);
+		mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
+		mask &= ~MAC_INT_RX;
+		writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
+		spin_unlock_irqrestore(&comm->int_mask_lock, flags);
+	}
 
-	napi_complete(napi);
 	return budget - budget_left;
 }
 
@@ -198,13 +199,14 @@ int spl2sw_tx_poll(struct napi_struct *napi, int budget)
 
 	spin_unlock(&comm->tx_lock);
 
-	spin_lock_irqsave(&comm->int_mask_lock, flags);
-	mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
-	mask &= ~MAC_INT_TX;
-	writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
-	spin_unlock_irqrestore(&comm->int_mask_lock, flags);
+	if (budget_left > 0 && napi_complete_done(napi, budget - budget_left)) {
+		spin_lock_irqsave(&comm->int_mask_lock, flags);
+		mask = readl(comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
+		mask &= ~MAC_INT_TX;
+		writel(mask, comm->l2sw_reg_base + L2SW_SW_INT_MASK_0);
+		spin_unlock_irqrestore(&comm->int_mask_lock, flags);
+	}
 
-	napi_complete(napi);
 	return budget - budget_left;
 }
 
-- 
2.43.0


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

* Re: [PATCH net] net: ethernet: sunplus: check budget before calling napi_complete_done()
  2026-11-14 22:27 [PATCH net] net: ethernet: sunplus: check budget before calling napi_complete_done() Janis Edvarts Lacis
@ 2026-11-15 15:50 ` Andrew Lunn
  2026-11-15 20:06 ` netdev-bot+sinfo
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2026-11-15 15:50 UTC (permalink / raw)
  To: Janis Edvarts Lacis
  Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, wellslutw,
	linux-kernel

On Sun, Nov 15, 2026 at 12:27:44AM +0200, Janis Edvarts Lacis wrote:
> Sunplus drivers currently do napi_complete() after each rx/tx poll is
> done without checking whether budget was exhausted or not. Interrupts
> are also unmasked before the call to napi_complete().
> 
> Replace napi_complete() with napi_complete_done() and add a check for
> budget_left. Call napi_complete_done() only when the budget has been
> not exhausted fully, e.g. budget_left > 0 and unmask interrupts only when
> napi_complete_done() returns true.
> 
> I do not have the hardware necessary, this patch is not tested on real
> hardware.
> 
> Fixes: fd3040b9394c ("net: ethernet: Add driver for Sunplus SP7021")
> Signed-off-by: Janis Edvarts Lacis <janislacis06@gmail.com>

Does this bother anybody? If not, net-next. No Fixes: tag.

Given that you have not tested this, how confident are you it is
correct?

	Andrew

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

* Re: [PATCH net] net: ethernet: sunplus: check budget before calling napi_complete_done()
  2026-11-14 22:27 [PATCH net] net: ethernet: sunplus: check budget before calling napi_complete_done() Janis Edvarts Lacis
  2026-11-15 15:50 ` Andrew Lunn
@ 2026-11-15 20:06 ` netdev-bot+sinfo
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-15 20:06 UTC (permalink / raw)
  To: Janis Edvarts Lacis
  Cc: netdev, andrew+netdev, davem, edumazet, kuba, pabeni, wellslutw,
	linux-kernel

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

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

end of thread, other threads:[~2026-11-15 20:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-14 22:27 [PATCH net] net: ethernet: sunplus: check budget before calling napi_complete_done() Janis Edvarts Lacis
2026-11-15 15:50 ` Andrew Lunn
2026-11-15 20:06 ` netdev-bot+sinfo

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®