* [PATCH] wifi: ath11k: fix resource leak on error in ext IRQ setup @ 2026-06-22 2:56 ZhaoJinming 2026-07-13 5:33 ` Baochen Qiang 0 siblings, 1 reply; 4+ messages in thread From: ZhaoJinming @ 2026-06-22 2:56 UTC (permalink / raw) To: Jeff Johnson; +Cc: linux-wireless, ath11k, linux-kernel, ZhaoJinming 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@uniontech.com> --- drivers/net/wireless/ath/ath11k/ahb.c | 30 ++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/ahb.c b/drivers/net/wireless/ath/ath11k/ahb.c index f566d699d074..041c0fefe8c8 100644 --- a/drivers/net/wireless/ath/ath11k/ahb.c +++ b/drivers/net/wireless/ath/ath11k/ahb.c @@ -536,8 +536,10 @@ static int ath11k_ahb_config_ext_irq(struct ath11k_base *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) { + 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); @@ -600,11 +602,25 @@ 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; + goto err_request_irq; } } } return 0; + +err_request_irq: + for ( ; i >= 0; i--) { + irq_grp = &ab->ext_irq_grp[i]; + for (j = irq_grp->num_irq - 1; j >= 0; j--) + free_irq(ab->irq_num[irq_grp->irqs[j]], irq_grp); + if (irq_grp->napi_ndev) { + netif_napi_del(&irq_grp->napi); + free_netdev(irq_grp->napi_ndev); + } + } + return ret; } static int ath11k_ahb_config_irq(struct ath11k_base *ab) @@ -629,8 +645,16 @@ 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); + for (i--; i >= 0; i--) { + if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR) + continue; + free_irq(ab->irq_num[ATH11K_IRQ_CE0_OFFSET + i], + &ab->ce.ce_pipe[i]); + } return ret; + } ab->irq_num[irq_idx] = irq; } -- 2.20.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] wifi: ath11k: fix resource leak on error in ext IRQ setup 2026-06-22 2:56 [PATCH] wifi: ath11k: fix resource leak on error in ext IRQ setup ZhaoJinming @ 2026-07-13 5:33 ` Baochen Qiang 2026-07-13 10:59 ` [PATCH v2] " ZhaoJinming 0 siblings, 1 reply; 4+ messages in thread From: Baochen Qiang @ 2026-07-13 5:33 UTC (permalink / raw) To: ZhaoJinming, Jeff Johnson; +Cc: linux-wireless, ath11k, linux-kernel On 6/22/2026 10:56 AM, 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@uniontech.com> > --- > drivers/net/wireless/ath/ath11k/ahb.c | 30 ++++++++++++++++++++++++--- > 1 file changed, 27 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/wireless/ath/ath11k/ahb.c b/drivers/net/wireless/ath/ath11k/ahb.c > index f566d699d074..041c0fefe8c8 100644 > --- a/drivers/net/wireless/ath/ath11k/ahb.c > +++ b/drivers/net/wireless/ath/ath11k/ahb.c > @@ -536,8 +536,10 @@ static int ath11k_ahb_config_ext_irq(struct ath11k_base *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) { > + 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); > @@ -600,11 +602,25 @@ 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; > + goto err_request_irq; > } > } > } > > return 0; > + > +err_request_irq: > + for ( ; i >= 0; i--) { > + irq_grp = &ab->ext_irq_grp[i]; this does not compile since irq_grp is a local variable defined inside the for loop above. > + for (j = irq_grp->num_irq - 1; j >= 0; j--) > + free_irq(ab->irq_num[irq_grp->irqs[j]], irq_grp); > + if (irq_grp->napi_ndev) { > + netif_napi_del(&irq_grp->napi); > + free_netdev(irq_grp->napi_ndev); > + } > + } > + return ret; > } > > static int ath11k_ahb_config_irq(struct ath11k_base *ab) > @@ -629,8 +645,16 @@ 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); > + for (i--; i >= 0; i--) { > + if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR) > + continue; > + free_irq(ab->irq_num[ATH11K_IRQ_CE0_OFFSET + i], > + &ab->ce.ce_pipe[i]); > + } > return ret; > + } > > ab->irq_num[irq_idx] = irq; > } ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] wifi: ath11k: fix resource leak on error in ext IRQ setup 2026-07-13 5:33 ` Baochen Qiang @ 2026-07-13 10:59 ` ZhaoJinming 2026-07-15 3:15 ` Baochen Qiang 0 siblings, 1 reply; 4+ messages in thread From: ZhaoJinming @ 2026-07-13 10:59 UTC (permalink / raw) To: Baochen Qiang, Jeff Johnson Cc: linux-wireless, ath11k, linux-kernel, ZhaoJinming 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@uniontech.com> --- 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. drivers/net/wireless/ath/ath11k/ahb.c | 48 ++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/ahb.c b/drivers/net/wireless/ath/ath11k/ahb.c index f566d699d074..11bafbd94aff 100644 --- a/drivers/net/wireless/ath/ath11k/ahb.c +++ b/drivers/net/wireless/ath/ath11k/ahb.c @@ -524,20 +524,24 @@ 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]; + irq_grp = &ab->ext_irq_grp[i]; u32 num_irq = 0; 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); @@ -600,11 +604,25 @@ 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; + goto err_request_irq; } } } return 0; + +err_request_irq: + for ( ; i >= 0; i--) { + irq_grp = &ab->ext_irq_grp[i]; + for (j = irq_grp->num_irq - 1; j >= 0; j--) + free_irq(ab->irq_num[irq_grp->irqs[j]], irq_grp); + if (irq_grp->napi_ndev) { + netif_napi_del(&irq_grp->napi); + free_netdev(irq_grp->napi_ndev); + } + } + return ret; } static int ath11k_ahb_config_irq(struct ath11k_base *ab) @@ -629,15 +647,30 @@ 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) - return ret; + if (ret) { + ath11k_err(ab, "failed request_irq for %d\n", irq); + goto err_ce_irq; + } 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); + goto err_ce_irq; + } + + return 0; +err_ce_irq: + for (i--; i >= 0; i--) { + if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR) + continue; + free_irq(ab->irq_num[ATH11K_IRQ_CE0_OFFSET + i], + &ab->ce.ce_pipe[i]); + } return ret; } -- 2.20.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] wifi: ath11k: fix resource leak on error in ext IRQ setup 2026-07-13 10:59 ` [PATCH v2] " ZhaoJinming @ 2026-07-15 3:15 ` Baochen Qiang 0 siblings, 0 replies; 4+ messages in thread From: Baochen Qiang @ 2026-07-15 3:15 UTC (permalink / raw) To: ZhaoJinming, Jeff Johnson; +Cc: linux-wireless, ath11k, linux-kernel On 7/13/2026 6:59 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@uniontech.com> > --- > > 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. > > drivers/net/wireless/ath/ath11k/ahb.c | 48 ++++++++++++++++++++++++++-- > 1 file changed, 44 insertions(+), 4 deletions(-) > > diff --git a/drivers/net/wireless/ath/ath11k/ahb.c b/drivers/net/wireless/ath/ath11k/ahb.c > index f566d699d074..11bafbd94aff 100644 > --- a/drivers/net/wireless/ath/ath11k/ahb.c > +++ b/drivers/net/wireless/ath/ath11k/ahb.c > @@ -524,20 +524,24 @@ 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]; > + irq_grp = &ab->ext_irq_grp[i]; > u32 num_irq = 0; declaration after statement. better to have num_irq declaration at the beginning of the for loop. > > 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; the ath12k_base is allocated by kzalloc, so the ext_irq_grp array, as a member of ath12k_base, is already zero'ed, hence this re-initialization is redundant. But I am OK with it since it improves code readability. > + goto err_request_irq; > + } > > netif_napi_add(irq_grp->napi_ndev, &irq_grp->napi, > ath11k_ahb_ext_grp_napi_poll); > @@ -600,11 +604,25 @@ 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; with this forcing to the number of successful irq request ... > + goto err_request_irq; > } > } > } > > return 0; > + > +err_request_irq: > + for ( ; i >= 0; i--) { then with the index starting from the failed loop ... > + irq_grp = &ab->ext_irq_grp[i]; > + for (j = irq_grp->num_irq - 1; j >= 0; j--) > + free_irq(ab->irq_num[irq_grp->irqs[j]], irq_grp); > + if (irq_grp->napi_ndev) { and with the guard ... > + netif_napi_del(&irq_grp->napi); > + free_netdev(irq_grp->napi_ndev); > + } > + } at the cost of above three, the centralized err handling is working. Yeah this simplifies the code, but makes it hard to understand. what about: 1. refactor the existing ath11k_ahb_free_ext_irq(): ath11k_ahb_free_ext_irq_grp() { for (j = 0; j < irq_grp->num_irq; j++) free_irq(ab->irq_num[irq_grp->irqs[j]], irq_grp); netif_napi_del(&irq_grp->napi); free_netdev(irq_grp->napi_ndev); } then we can have ath11k_ahb_free_ext_irq() { for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) ath11k_ahb_free_ext_irq_grp(irq_grp) } and the complete err handling of ext irq can be ath11k_ahb_config_ext_irq() { for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) { irq_grp->napi_ndev = alloc_netdev_dummy(0); if (!irq_grp->napi_ndev) { ret = -ENOMEM; irq_grp->num_irq = 0; goto err_request_irq; } ... for (j = 0; j < num_irq; j++) { ret = request_irq(); if (ret) { irq_grp->num_irq = j; ath11k_ahb_free_ext_irq_grp(irq_grp); goto err_request_irq; } } irq_grp->num_irq = num_irq; } err_request_irq: for ( i--; i >= 0; i--) { irq_grp = &ab->ext_irq_grp[i]; ath11k_ahb_free_ext_irq_grp(irq_grp); } return ret; } > + return ret; > } > > static int ath11k_ahb_config_irq(struct ath11k_base *ab) > @@ -629,15 +647,30 @@ 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) > - return ret; > + if (ret) { > + ath11k_err(ab, "failed request_irq for %d\n", irq); > + goto err_ce_irq; > + } > > 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); > + goto err_ce_irq; > + } > + > + return 0; > > +err_ce_irq: > + for (i--; i >= 0; i--) { > + if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR) > + continue; > + free_irq(ab->irq_num[ATH11K_IRQ_CE0_OFFSET + i], > + &ab->ce.ce_pipe[i]); > + } this is also a duplication of the CE part of ath11k_ahb_free_irq(), consider refactoring the exsiting helper and reuse it. > return ret; > } > ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-15 3:16 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-06-22 2:56 [PATCH] wifi: ath11k: fix resource leak on error in ext IRQ setup ZhaoJinming 2026-07-13 5:33 ` Baochen Qiang 2026-07-13 10:59 ` [PATCH v2] " ZhaoJinming 2026-07-15 3:15 ` Baochen Qiang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox