Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: b.lane130@outlook.com
Cc: bharat@chelsio.com, andrew+netdev@lunn.ch, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	netdev@vger.kernel.org
Subject: Re: [PATCH] net: cxgb3: complete the cleanup operations on error paths
Date: Mon, 23 Nov 2026 17:13:59 +0000	[thread overview]
Message-ID: <179545403948.3135.3451259084551088603@kernel.org> (raw)
In-Reply-To: <BN8PR06MB6177F1B73B4D37AC2315B428A4462@BN8PR06MB6177.namprd06.prod.outlook.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The new unwind under out_close_led in init_one()
  (drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c, lines 3384-3391)…
- [Low] The commit message says only that the error path in init_one()
  'lacks some cleanup operations to release sources', which reads like a…

--

net: cxgb3: complete the cleanup operations on error paths

This patch adds offload unregistration, netdev unregistration and MSI
teardown to the out_close_led error path in init_one(). That path is
taken when sysfs_create_group() fails after the ports have been
registered.

> If sysfs_create_group() fails, the error path lacks some
> cleanup operations to release sources. Add corresponding
> cleanup functions under out_close_led label.

[Severity: Low]

Does this description undersell what the patch fixes? Before this change,
out_close_led fell straight through to out_free_dev. That calls
free_netdev() on ports still in NETREG_REGISTERED, which hits this check:

net/core/dev.c:free_netdev() {
    ...
	BUG_ON(dev->reg_state != NETREG_UNREGISTERED);
    ...
}

The adapter was also kfree()d while its t3cdev was still on the offload
device list via cxgb3_adapter_ofld()->register_tdev().

This failure path seems to have come from commit 7c099773b086 ("net: cxgb3:
add error handling for sysfs_create_group").

Should the commit message mention the BUG_ON and the use-after-free? Should
it also carry a Fixes: tag for that commit?

> diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
> index 3bee82bc06806..a6693f332d259 100644
> --- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
> +++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
> @@ -3381,6 +3381,15 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
>  	return 0;
>  
>  out_close_led:
> +	if (is_offload(adapter))
> +		cxgb3_adapter_unofld(adapter);
> +
> +	for_each_port(adapter, i)
> +		if (test_bit(i, &adapter->registered_device_map))
> +			unregister_netdev(adapter->port[i]);
> +
> +	cxgb_disable_msi(adapter);
> +
>  	t3_set_reg_field(adapter, A_T3DBG_GPIO_EN, F_GPIO0_OUT_VAL, 0);
>  
>  out_free_dev:

[Severity: High]

Is this teardown complete if a port was opened before sysfs_create_group()
failed?

Userspace can see the netdevs as soon as register_netdev() returns. So
udev, NetworkManager or "ip link set up" can open a port before
sysfs_create_group() runs. Opening a port goes through
cxgb_open()->cxgb_up(), which does:

cxgb_up()
    setup_sge_qsets(adap)
    request_irq() with dev_id == adapter
    t3_start_sge_timers(adap)
    adap->flags |= FULL_INIT_DONE

On an offload adapter, offload_open() also sets OFFLOAD_DEVMAP_BIT in
open_device_map and calls cxgb3_offload_activate(). That may register the
netevent notifier, and it adds the adapter to the global adapter_list.

remove_one() tears down the same state like this:

	t3_sge_stop(adapter);
	...
	if (is_offload(adapter)) {
		cxgb3_adapter_unofld(adapter);
		if (test_bit(OFFLOAD_DEVMAP_BIT,
			     &adapter->open_device_map))
			offload_close(&adapter->tdev);
	}
	... unregister_netdev() ...
	t3_stop_sge_timers(adapter);
	t3_free_sge_resources(adapter);
	cxgb_disable_msi(adapter);

The new error path is missing t3_sge_stop(), offload_close(),
t3_stop_sge_timers() and t3_free_sge_resources().

While OFFLOAD_DEVMAP_BIT is still set, open_device_map stays non-zero after
unregister_netdev()->__cxgb_close(). So cxgb_down() is skipped:

	if (!adapter->open_device_map)
		cxgb_down(adapter, on_wq);

That leaves the IRQs requested and interrupts enabled, and cxgb3_wq is not
flushed. cxgb_disable_msi() then disables MSI/MSI-X vectors that may still
have handlers attached. Even without offload, cxgb_down() does not stop the
SGE reclaim timers or free the qsets.

The code then falls through to iounmap(adapter->regs), free_netdev() and
kfree(adapter).

Can sge_timer_tx() and sge_timer_rx() still fire after that? They
dereference qs->netdev and pi->adapter, read registers through
adapter->regs, and rearm themselves with mod_timer().

There are other leftovers too:

- The IRQ handlers would still have a freed dev_id.
- adapter_list and the netevent notifier would still point at the freed
  adapter.
- The SGE DMA rings would leak with their hardware contexts still enabled,
  because only t3_free_qset() disables them.

The sysfs_create_group() failure can happen in practice. If
register_netdev() failed for port[0] but another port registered,
port[0]->dev.kobj has no sysfs directory. internal_create_group() then
returns -EINVAL.

Would it be better to follow the teardown order in remove_one()?
Alternatively, the failure point after register_netdev() could go away
entirely, for example by attaching cxgb3_attr_group through
port[0]->sysfs_groups[] before registration.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/BN8PR06MB6177F1B73B4D37AC2315B428A4462%40BN8PR06MB6177.namprd06.prod.outlook.com

  reply	other threads:[~2026-11-23 17:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 16:44 [PATCH] net: cxgb3: complete the cleanup operations on error paths b.lane130
2026-11-23 17:13 ` netdev-bot+sashiko [this message]
  -- strict thread matches above, loose matches on Subject: below --
2026-11-22 16:47 netdev-bot+sinfo

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=179545403948.3135.3451259084551088603@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=b.lane130@outlook.com \
    --cc=bharat@chelsio.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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