Re: [PATCH v3] wifi: ath11k: fix resource leak on error in ext IRQ setup

From: Baochen Qiang

Date: Thu Jul 16 2026 - 23:48:09 EST




On 7/16/2026 7:46 PM, ZhaoJinming wrote:
> In ath11k_ahb_config_irq(), when a CE request_irq() fails, the function
> returns the error immediately without freeing the CE IRQs that were
> successfully registered in previous loop iterations. The probe error
> path does not call ath11k_ahb_free_irq() either, so the previously
> registered CE IRQ handlers remain attached to the interrupt lines and
> are never released.
>
> In ath11k_ahb_config_ext_irq(), when an external request_irq() fails,
> the error is only logged and the loop continues. The function then
> returns 0 indicating success, leaving the device in a partially
> configured state where some external IRQs are not registered. This
> causes enable_irq()/disable_irq()/free_irq() to be called on
> unregistered IRQs during runtime and remove/shutdown, triggering
> WARN_ON(!desc->action), and missing interrupt handlers lead to data
> loss.
>
> Additionally, if alloc_netdev_dummy() fails for a later IRQ group, the
> function returns -ENOMEM without freeing the ext IRQs and napi_ndev
> that were successfully set up for earlier groups.
>
> Fix all three issues: propagate the error up to the caller and unwind
> all successfully registered IRQs and allocated resources on failure.
>
> Signed-off-by: ZhaoJinming <zhaojinming@xxxxxxxxxxxxx>
> ---
>
> Changes in v3:
> - Extract ath11k_ahb_free_ext_irq_grp() to handle per-group ext IRQ
> cleanup and refactor ath11k_ahb_free_ext_irq() to use it. Add a NULL
> check for napi_ndev to avoid potential NULL pointer dereference since
> free_netdev() does not guard against NULL input.
> - On request_irq() failure in ath11k_ahb_config_ext_irq(), immediately
> clean up the current group via ath11k_ahb_free_ext_irq_grp() before
> jumping to the error label to unwind earlier groups.
> - Move u32 num_irq declaration before the irq_grp assignment to follow
> declaration-before-statement ordering.
> - Extract ath11k_ahb_free_ce_irqs() to handle partial/full CE IRQ cleanup
> and refactor ath11k_ahb_free_irq() to use it, replacing the duplicated
> err_ce_irq cleanup loop in ath11k_ahb_config_irq().
>
> Changes in v2:
> - Move `irq_grp` declaration from for-loop body to function scope to fix
> compile error in err_request_irq error path.
> - Set ret = -ENOMEM before goto err_request_irq on alloc_netdev_dummy()
> failure to avoid returning uninitialized value.
> - When ath11k_ahb_config_ext_irq() fails, unwind the already-registered
> CE IRQs via a shared err_ce_irq cleanup path to avoid leaking them.
>
> diff --git a/drivers/net/wireless/ath/ath11k/ahb.c b/drivers/net/wireless/ath/ath11k/ahb.c
> index f566d699d074..1a9408138d81 100644
> --- a/drivers/net/wireless/ath/ath11k/ahb.c
> +++ b/drivers/net/wireless/ath/ath11k/ahb.c
> @@ -431,36 +431,47 @@ static void ath11k_ahb_init_qmi_ce_config(struct ath11k_base *ab)
> ab->qmi.service_ins_id = ab->hw_params.qmi_service_ins_id;
> }
>
> -static void ath11k_ahb_free_ext_irq(struct ath11k_base *ab)
> +static void ath11k_ahb_free_ext_irq_grp(struct ath11k_base *ab,
> + struct ath11k_ext_irq_grp *irq_grp)
> {
> - int i, j;
> + int j;
>
> - for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
> - struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
> + for (j = 0; j < irq_grp->num_irq; j++)
> + free_irq(ab->irq_num[irq_grp->irqs[j]], irq_grp);
>
> - for (j = 0; j < irq_grp->num_irq; j++)
> - free_irq(ab->irq_num[irq_grp->irqs[j]], irq_grp);
> + if (!irq_grp->napi_ndev)
> + return;


irq_grp->napi_ndev can not be NULL in exsiting code, hence this is not reachable. A silent
guard against a state that cannot happen has real downsides, regardless of what it's guarding:

- It documents a code path that doesn't exist. The next person to touch this will assume
the guarded condition is reachable and may build further logic on that false premise,
spreading a phantom case through the code.
- It discourages proving the invariant. The check silently substitutes for the reasoning
"can this actually occur here?" — the exact analysis a reader should do — which invites
less rigorous code over time.
- It hides bugs and delays them. If the invariant is ever broken by a future change, the
silent early return swallows it instead of failing where the root cause is. What should be
an immediate, on-the-spot failure becomes a displaced, delayed symptom that looks
unrelated to its cause and is far harder to debug. If a "can't happen" condition is
genuinely worth asserting, the right tool is a loud warning — never a quiet return that
masks it.

So I'd drop the guard.

>
> - netif_napi_del(&irq_grp->napi);
> - free_netdev(irq_grp->napi_ndev);
> - }
> + netif_napi_del(&irq_grp->napi);
> + free_netdev(irq_grp->napi_ndev);
> }
>
> -static void ath11k_ahb_free_irq(struct ath11k_base *ab)
> +static void ath11k_ahb_free_ext_irq(struct ath11k_base *ab)
> {
> - int irq_idx;
> int i;
>
> - if (ab->hw_params.hybrid_bus_type)
> - return ath11k_pcic_free_irq(ab);
> + for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++)
> + ath11k_ahb_free_ext_irq_grp(ab, &ab->ext_irq_grp[i]);
> +}
>
> - for (i = 0; i < ab->hw_params.ce_count; i++) {
> +static void ath11k_ahb_free_ce_irqs(struct ath11k_base *ab, int max_idx)
> +{
> + int irq_idx, i;
> +
> + for (i = 0; i < max_idx; i++) {
> if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
> continue;
> irq_idx = ATH11K_IRQ_CE0_OFFSET + i;
> free_irq(ab->irq_num[irq_idx], &ab->ce.ce_pipe[i]);
> }
> +}
> +
> +static void ath11k_ahb_free_irq(struct ath11k_base *ab)
> +{
> + if (ab->hw_params.hybrid_bus_type)
> + return ath11k_pcic_free_irq(ab);
>
> + ath11k_ahb_free_ce_irqs(ab, ab->hw_params.ce_count);
> ath11k_ahb_free_ext_irq(ab);
> }
>
> @@ -524,20 +535,25 @@ static irqreturn_t ath11k_ahb_ext_interrupt_handler(int irq, void *arg)
> static int ath11k_ahb_config_ext_irq(struct ath11k_base *ab)
> {
> struct ath11k_hw_params *hw = &ab->hw_params;
> + struct ath11k_ext_irq_grp *irq_grp;
> int i, j;
> int irq;
> int ret;
>
> for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
> - struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
> u32 num_irq = 0;
>
> + irq_grp = &ab->ext_irq_grp[i];
> +
> irq_grp->ab = ab;
> irq_grp->grp_id = i;
>
> irq_grp->napi_ndev = alloc_netdev_dummy(0);
> - if (!irq_grp->napi_ndev)
> - return -ENOMEM;
> + if (!irq_grp->napi_ndev) {
> + ret = -ENOMEM;
> + irq_grp->num_irq = 0;
> + goto err_request_irq;
> + }
>
> netif_napi_add(irq_grp->napi_ndev, &irq_grp->napi,
> ath11k_ahb_ext_grp_napi_poll);
> @@ -585,9 +601,7 @@ static int ath11k_ahb_config_ext_irq(struct ath11k_base *ab)
> }
> }
> }
> - irq_grp->num_irq = num_irq;
> -
> - for (j = 0; j < irq_grp->num_irq; j++) {
> + for (j = 0; j < num_irq; j++) {
> int irq_idx = irq_grp->irqs[j];
>
> irq = platform_get_irq_byname(ab->pdev,
> @@ -600,11 +614,23 @@ static int ath11k_ahb_config_ext_irq(struct ath11k_base *ab)
> if (ret) {
> ath11k_err(ab, "failed request_irq for %d\n",
> irq);
> + irq_grp->num_irq = j;
> + ath11k_ahb_free_ext_irq_grp(ab, irq_grp);
> + goto err_request_irq;
> }
> }
> +
> + irq_grp->num_irq = num_irq;
> }
>
> return 0;
> +
> +err_request_irq:
> + for (i--; i >= 0; i--) {
> + irq_grp = &ab->ext_irq_grp[i];
> + ath11k_ahb_free_ext_irq_grp(ab, irq_grp);
> + }
> + return ret;
> }
>
> static int ath11k_ahb_config_irq(struct ath11k_base *ab)
> @@ -629,16 +655,24 @@ static int ath11k_ahb_config_irq(struct ath11k_base *ab)
> ret = request_irq(irq, ath11k_ahb_ce_interrupt_handler,
> IRQF_TRIGGER_RISING, irq_name[irq_idx],
> ce_pipe);
> - if (ret)
> + if (ret) {
> + ath11k_err(ab, "failed request_irq for %d\n", irq);
> + ath11k_ahb_free_ce_irqs(ab, i);
> return ret;
> + }
>
> ab->irq_num[irq_idx] = irq;
> }
>
> /* Configure external interrupts */
> ret = ath11k_ahb_config_ext_irq(ab);
> + if (ret) {
> + ath11k_err(ab, "failed to configure ext irq: %d\n", ret);
> + ath11k_ahb_free_ce_irqs(ab, ab->hw_params.ce_count);
> + return ret;
> + }
>
> - return ret;
> + return 0;
> }
>
> static int ath11k_ahb_map_service_to_pipe(struct ath11k_base *ab, u16 service_id,

others look good to me. Hence with the sanity guard removed:

Reviewed-by: Baochen Qiang <baochen.qiang@xxxxxxxxxxxxxxxx>