Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: linusw@kernel.org
Cc: ulli.kroll@googlemail.com, andrew+netdev@lunn.ch,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, mirq-linux@rere.qmqm.pl, mhun512@gmail.com,
	netdev@vger.kernel.org
Subject: Re: [PATCH net-next v2 11/11] net: ethernet: cortina: Use guard helpers for locking
Date: Wed, 30 Sep 2026 02:50:46 +0000	[thread overview]
Message-ID: <179073664681.434549.10297325133888163725@kernel.org> (raw)
In-Reply-To: <20260928-gemini-ethernet-fixes-3-v2-11-758a795d7a78@kernel.org>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The patch goes against netdev's documented policy on cleanup.h
  and on standalone clean-ups.
- [Low] gmac_rx() now mixes goto-based cleanup with a cleanup.h helper,
  which subsystem/cleanup.md and include/linux/cleanup.h (lines 148-153)…

--

net: ethernet: cortina: Use guard helpers for locking

This commit converts the spinlock lock and unlock pairs in the Gemini
ethernet driver to guard() and scoped_guard() from linux/cleanup.h. The
goto based unlock path in geth_freeq_claim() is replaced with early
returns. No functional change is intended.

> diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
> index 910de9925949..4fdd7478601f 100644
> --- a/drivers/net/ethernet/cortina/gemini.c
> +++ b/drivers/net/ethernet/cortina/gemini.c

[ ... ]

> @@ -790,10 +778,11 @@ static struct page *geth_freeq_claim(struct gemini_ethernet *geth,
>  
>  	index = geth_freeq_mapping_index(geth, mapping);
>  
> -	spin_lock_irqsave(&geth->freeq_lock, flags);
> +	guard(spinlock_irqsave)(&geth->freeq_lock);
> +
>  	gpage = xa_load(&geth->freeq_mappings, index);
>  	if (!gpage || !gpage->page || !gpage->fragments)
> -		goto err_unlock;
> +		return NULL;

[Severity: Low]
Does this conversion fit the netdev guidance on cleanup.h?
Documentation/process/maintainer-netdev.rst says:

  Use of guard() is discouraged within any function longer than 20 lines,
  scoped_guard() is considered more readable. Using normal lock/unlock is
  still (weakly) preferred.

geth_freeq_claim() is about 46 lines long. Its function-scope guard()
covers xa_load(), xa_erase(), dma_unmap_single_attrs() and put_page().
There are also two early return NULL exits, which now release freeq_lock
implicitly.

gmac_update_hw_stats(), gmac_enable_irq() and the gemini_port_irq()
hardirq handler are also longer than 20 lines and now use a
function-scope guard().

The same document also says:

  Netdev discourages patches which perform simple clean-ups, which are not
  in the context of other work.

The commit message only says "Use cleanup guard helpers to scope the
driver's spinlocks automatically". The patch has no functional change, and
it touches the RX and IRQ paths in gmac_rx(), gmac_irq() and
gemini_port_irq(). That may make stable backports harder.

Would it be better to keep the explicit spin_lock_irqsave() and
spin_unlock_irqrestore() calls in the longer functions? Or use
scoped_guard() there, or fold this into other work on the driver?

[ ... ]

> @@ -1622,17 +1593,16 @@ static unsigned int gmac_rx(struct net_device *netdev, unsigned int budget,

[ ... ]

> -	spin_lock_irqsave(&geth->irq_lock, flags);
> -	rw.bits32 = readl(ptr_reg);
> -	/* Reset interrupt as all packages until here are taken into account */
> -	writel(DEFAULT_Q0_INT_BIT << netdev->dev_id,
> -	       geth->base + GLOBAL_INTERRUPT_STATUS_1_REG);
> -	spin_unlock_irqrestore(&geth->irq_lock, flags);
> +	scoped_guard(spinlock_irqsave, &geth->irq_lock) {
> +		rw.bits32 = readl(ptr_reg);
> +		/* Reset interrupt as all packages until here are taken into account */
> +		writel(DEFAULT_Q0_INT_BIT << netdev->dev_id,
> +		       geth->base + GLOBAL_INTERRUPT_STATUS_1_REG);
> +	}
>  
>  	r = rw.bits.rptr;
>  	w = rw.bits.wptr;

[Severity: Low]
Does this mix goto based cleanup with a cleanup.h helper in gmac_rx()?

Before this patch gmac_rx() used only gotos. Its RX loop already relies on
goto based cleanup through the err_length, err_drop and next_desc labels:

err_drop:
		if (skb) {
			napi_free_frags(&port->napi);
			skb = NULL;
			frag_nr = 0;
		}

		if (page)
			put_page(page);

include/linux/cleanup.h says:

  the expectation is that usage of "goto" and cleanup helpers is never
  mixed in the same function. I.e. for a given routine, convert all
  resources that need a "goto" cleanup to scope-based cleanup, or
  convert none of them.

Nothing goes wrong today. The scoped_guard() block closes before the while
loop, and none of the gotos cross its scope.

If the locked section were later moved into the loop, or changed to
guard(), those gotos would jump across a cleanup scope.

Could gmac_rx() keep the explicit spin_lock_irqsave() and
spin_unlock_irqrestore() pair? Another option is to move the locked rwptr
read and interrupt ack into a small helper.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928-gemini-ethernet-fixes-3-v2-0-758a795d7a78%40kernel.org

  reply	other threads:[~2026-09-30  2:50 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28  8:50 [PATCH net-next v2 00/11] net: ethernet: cortina: Fix Gemini RX buffer management Linus Walleij
2026-09-28  8:50 ` [PATCH net-next v2 01/11] net: ethernet: cortina: Keep shared free queue parent-owned Linus Walleij
2026-09-30  2:50   ` netdev-bot+sashiko
2026-09-28  8:50 ` [PATCH net-next v2 02/11] net: ethernet: cortina: Drain free queue IRQ before resize Linus Walleij
2026-09-30  2:50   ` netdev-bot+sashiko
2026-09-28  8:50 ` [PATCH net-next v2 03/11] net: ethernet: cortina: Correct free queue DMA mappings Linus Walleij
2026-09-30  2:50   ` netdev-bot+sashiko
2026-09-28  8:50 ` [PATCH net-next v2 04/11] net: ethernet: cortina: Index free queue fragments with XArray Linus Walleij
2026-09-30  2:50   ` netdev-bot+sashiko
2026-09-28  8:50 ` [PATCH net-next v2 05/11] net: ethernet: cortina: Preserve in-flight free queue pages Linus Walleij
2026-09-30  2:50   ` netdev-bot+sashiko
2026-09-28  8:50 ` [PATCH net-next v2 06/11] net: ethernet: cortina: Rotate free queue page allocation Linus Walleij
2026-09-28  8:50 ` [PATCH net-next v2 07/11] net: ethernet: cortina: Synchronize RX fragments for the CPU Linus Walleij
2026-09-30  2:50   ` netdev-bot+sashiko
2026-09-28  8:50 ` [PATCH net-next v2 08/11] net: ethernet: cortina: Validate RX fragment lengths Linus Walleij
2026-09-30  2:50   ` netdev-bot+sashiko
2026-09-28  8:50 ` [PATCH net-next v2 09/11] net: ethernet: cortina: Release partial RX frames on stop Linus Walleij
2026-09-30  2:50   ` netdev-bot+sashiko
2026-09-28  8:50 ` [PATCH net-next v2 10/11] net: ethernet: cortina: Scale Gemini RX queues to system memory Linus Walleij
2026-09-28  8:50 ` [PATCH net-next v2 11/11] net: ethernet: cortina: Use guard helpers for locking Linus Walleij
2026-09-30  2:50   ` netdev-bot+sashiko [this message]
2026-10-01  9:51 ` [PATCH net-next v2 00/11] net: ethernet: cortina: Fix Gemini RX buffer management Paolo Abeni
2026-10-01 11:33   ` Linus Walleij

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=179073664681.434549.10297325133888163725@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linusw@kernel.org \
    --cc=mhun512@gmail.com \
    --cc=mirq-linux@rere.qmqm.pl \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ulli.kroll@googlemail.com \
    /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