Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by b.lane130
Sun, 22 Nov 2026 16:44
[PATCH] net: cxgb3: complete the cleanup operations on error paths
Author: b.lane130
Date: Sun, 22 Nov 2026 16:44
Date: Sun, 22 Nov 2026 16:44
34 lines
16964 bytes
16964 bytes
From: Bruce Lane <b.lane130@outlook.com> If sysfs_create_group() fails, the error path lacks some cleanup operations to release sources. Add corresponding cleanup functions under out_close_led label. Signed-off-by: Bruce Lane <b.lane130@outlook.com> --- drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c index 3bee82bc0680..a6693f332d25 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: -- 2.25.1
Re: [PATCH] net: cxgb3: complete the cleanup operations on error paths
Author: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 17:13
Date: Mon, 23 Nov 2026 17:13
148 lines
13312 bytes
13312 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads