* [PATCH] net: cxgb3: complete the cleanup operations on error paths
@ 2026-11-22 16:44 b.lane130
2026-11-23 17:13 ` netdev-bot+sashiko
0 siblings, 1 reply; 3+ messages in thread
From: b.lane130 @ 2026-11-22 16:44 UTC (permalink / raw)
To: bharat, andrew+netdev, davem, edumazet, kuba, pabeni; +Cc: netdev, Bruce Lane
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] net: cxgb3: complete the cleanup operations on error paths
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
0 siblings, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 17:13 UTC (permalink / raw)
To: b.lane130; +Cc: bharat, andrew+netdev, davem, edumazet, kuba, pabeni, netdev
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net: cxgb3: complete the cleanup operations on error paths
@ 2026-11-22 16:47 netdev-bot+sinfo
0 siblings, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-11-22 16:47 UTC (permalink / raw)
To: b.lane130; +Cc: bharat, andrew+netdev, davem, edumazet, kuba, pabeni, netdev
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.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
- What hardware the change was tested on. For driver fixes please
mention the device (and if relevant firmware version) used for
testing, or say that the change was not tested on real hardware.
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-23 17:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
-- strict thread matches above, loose matches on Subject: below --
2026-11-22 16:47 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