Skip to contentSkip to conversation

wifi: ath11k: fix resource leak on error in ext IRQ setup

PATCH Superseded ZhaoJinming 4 participants 11 messages Jun 22 – Aug 5 Qualcomm Atheros ATH11K wireless driver

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: ath11k: fix resource leak on error in ext IRQ setup

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.

---
 drivers/net/wireless/ath/ath11k/ahb.c | 30 ++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
drivers/net/wireless/ath/ath11k/ahb.c +27 -3
index f566d699d074..041c0fefe8c8 100644
@@ -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;
 	}
Signature · 1 line
2.20.1
#1 lore raw
Quoted 50 lines · 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.

---
 drivers/net/wireless/ath/ath11k/ahb.c | 30 ++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
drivers/net/wireless/ath/ath11k/ahb.c +5 -2
index f566d699d074..041c0fefe8c8 100644
@@ -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;

drivers/net/wireless/ath/ath11k/ahb.c static int ath11k_ahb_config_ext_irq(struct ath11k_base *ab) · line 615

Quoted 10 lines
drivers/net/wireless/ath/ath11k/ahb.c +5 -0
+				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.

Quoted 29 lines
drivers/net/wireless/ath/ath11k/ahb.c +17 -1
+		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 lore raw

PATCH v2 1/1 wifi: ath11k: fix resource leak on error in ext IRQ setup

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.

---

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(-)
drivers/net/wireless/ath/ath11k/ahb.c +38 -5
index f566d699d074..11bafbd94aff 100644
@@ -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;
 }
 
Signature · 1 line
2.20.1
#3 lore raw
Quoted 44 lines · 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.

---

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(-)
drivers/net/wireless/ath/ath11k/ahb.c +0 -0
index f566d699d074..11bafbd94aff 100644
@@ -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)
 {

drivers/net/wireless/ath/ath11k/ahb.c static irqreturn_t ath11k_ahb_ext_interrupt_handler(int irq, void *arg) · line 534

Quoted 10 lines
drivers/net/wireless/ath/ath11k/ahb.c +2 -1
 	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.

drivers/net/wireless/ath/ath11k/ahb.c static irqreturn_t ath11k_ahb_ext_interrupt_handler(int irq, void *arg) · line 542

Quoted 10 lines
drivers/net/wireless/ath/ath11k/ahb.c +3 -2
 		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.

drivers/net/wireless/ath/ath11k/ahb.c static int ath11k_ahb_config_ext_irq(struct ath11k_base *ab) · line 607

Quoted 10 lines
drivers/net/wireless/ath/ath11k/ahb.c +3 -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;

with this forcing to the number of successful irq request ...

drivers/net/wireless/ath/ath11k/ahb.c static int ath11k_ahb_config_ext_irq(struct ath11k_base *ab) · line 616

Quoted 9 lines
drivers/net/wireless/ath/ath11k/ahb.c +4 -0
+				goto err_request_irq;
 			}
 		}
 	}
 
 	return 0;
+
+err_request_irq:
+	for ( ; i >= 0; i--) {

then with the index starting from the failed loop ...

drivers/net/wireless/ath/ath11k/ahb.c static int ath11k_ahb_config_ext_irq(struct ath11k_base *ab) · line 620

Quoted 4 lines
drivers/net/wireless/ath/ath11k/ahb.c +4 -0
+		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 ...

drivers/net/wireless/ath/ath11k/ahb.c static int ath11k_ahb_config_ext_irq(struct ath11k_base *ab) · line 624

Quoted 4 lines
drivers/net/wireless/ath/ath11k/ahb.c +4 -0
+			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;
}
Quoted 24 lines
drivers/net/wireless/ath/ath11k/ahb.c +9 -2
+	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;
+	}

drivers/net/wireless/ath/ath11k/ahb.c static int ath11k_ahb_config_irq(struct ath11k_base *ab) · line 673

Quoted 10 lines
drivers/net/wireless/ath/ath11k/ahb.c +9 -0
+
+	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.

Quoted 3 lines
drivers/net/wireless/ath/ath11k/ahb.c +0 -0
 	return ret;
 }
 
#4 lore raw

PATCH v3 1/1 wifi: ath11k: fix resource leak on error in ext IRQ setup

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.

---

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.

drivers/net/wireless/ath/ath11k/ahb.c +56 -22
index f566d699d074..1a9408138d81 100644
@@ -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;
 
-		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,
Reviewed-by on v3 1/1
#5 lore raw
Quoted 62 lines · 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.

---

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.

drivers/net/wireless/ath/ath11k/ahb.c +3 -2
index f566d699d074..1a9408138d81 100644
@@ -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;

drivers/net/wireless/ath/ath11k/ahb.c static void ath11k_ahb_init_qmi_ce_config(struct ath11k_base *ab) · line 443

Quoted 10 lines
drivers/net/wireless/ath/ath11k/ahb.c +4 -4
 
-	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.

Quoted 123 lines
drivers/net/wireless/ath/ath11k/ahb.c +44 -15
-		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) {

drivers/net/wireless/ath/ath11k/ahb.c static int ath11k_ahb_config_irq(struct ath11k_base *ab) · line 678

Quoted 10 lines
drivers/net/wireless/ath/ath11k/ahb.c +5 -1
+		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:

#6 lore raw

PATCH v4 1/1 wifi: ath11k: fix resource leak on error in ext IRQ setup

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.

---

Changes in v4:
- Drop the napi_ndev NULL guard in ath11k_ahb_free_ext_irq_grp() as it is unreachable in all existing call paths. A silent guard against an impossible condition hides bugs instead of exposing them.

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.
- 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.

drivers/net/wireless/ath/ath11k/ahb.c +54 -23
index f566d699d074..bdf53aa7ddf1 100644
@@ -431,36 +431,44 @@ 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;
-
-	for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
-		struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
+	int j;
 
-		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);
 
-		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 +532,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 +598,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 +611,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 +652,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,
Reviewed-by on v4 1/1
#7 lore raw
Quoted 16 lines · 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.

Quoted 8 lines

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.

#10 lore raw
In reply to ZhaoJinming
kernel test robot noticed the following build errors:

Hi ZhaoJinming,

kernel test robot noticed the following build errors:

[auto build test ERROR on wireless/main]
[also build test ERROR on wireless-next/main linus/master v7.2-rc6] [cannot apply to ath/ath-next next-20260805]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/ZhaoJinming/wifi-ath11k-fix-resource-leak-on-error-in-ext-IRQ-setup/20260805-214821
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless.git main
patch link:    https://lore.kernel.org/r/20260622025659.1235658-1-zhaojinming%40uniontech.com
patch subject: [PATCH] wifi: ath11k: fix resource leak on error in ext IRQ setup
config: alpha-allmodconfig (https://download.01.org/0day-ci/archive/20260806/[email protected]/config)
compiler: alpha-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260806/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/net/wireless/ath/ath11k/ahb.c: In function 'ath11k_ahb_config_ext_irq':

>> drivers/net/wireless/ath/ath11k/ahb.c:615:17: error: 'irq_grp' undeclared (first use in this function)
     615 |                 irq_grp = &ab->ext_irq_grp[i];
         |                 ^~~~~~~

drivers/net/wireless/ath/ath11k/ahb.c:615:17: note: each undeclared identifier is reported only once for each function it appears in

vim +/irq_grp +615 drivers/net/wireless/ath/ath11k/ahb.c

523
524 static int ath11k_ahb_config_ext_irq(struct ath11k_base *ab)
525 {
526 struct ath11k_hw_params *hw = &ab->hw_params;
527 int i, j;
528 int irq;
529 int ret;
530
531 for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
532 struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
533 u32 num_irq = 0;
534
535 irq_grp->ab = ab;
536 irq_grp->grp_id = i;
537
538 irq_grp->napi_ndev = alloc_netdev_dummy(0);
539 if (!irq_grp->napi_ndev) {
540 irq_grp->num_irq = 0;
541 goto err_request_irq;
542 }
543
544 netif_napi_add(irq_grp->napi_ndev, &irq_grp->napi,
545 ath11k_ahb_ext_grp_napi_poll);
546
547 for (j = 0; j < ATH11K_EXT_IRQ_NUM_MAX; j++) {
548 if (ab->hw_params.ring_mask->tx[i] & BIT(j)) {
549 irq_grp->irqs[num_irq++] =
550 wbm2host_tx_completions_ring1 - j;
551 }
552
553 if (ab->hw_params.ring_mask->rx[i] & BIT(j)) {
554 irq_grp->irqs[num_irq++] =
555 reo2host_destination_ring1 - j;
556 }
557
558 if (ab->hw_params.ring_mask->rx_err[i] & BIT(j))
559 irq_grp->irqs[num_irq++] = reo2host_exception;
560
561 if (ab->hw_params.ring_mask->rx_wbm_rel[i] & BIT(j))
562 irq_grp->irqs[num_irq++] = wbm2host_rx_release;
563
564 if (ab->hw_params.ring_mask->reo_status[i] & BIT(j))
565 irq_grp->irqs[num_irq++] = reo2host_status;
566
567 if (j < ab->hw_params.max_radios) {
568 if (ab->hw_params.ring_mask->rxdma2host[i] & BIT(j)) {
569 irq_grp->irqs[num_irq++] =
570 rxdma2host_destination_ring_mac1 -
571 ath11k_hw_get_mac_from_pdev_id(hw, j);
572 }
573
574 if (ab->hw_params.ring_mask->host2rxdma[i] & BIT(j)) {
575 irq_grp->irqs[num_irq++] =
576 host2rxdma_host_buf_ring_mac1 -
577 ath11k_hw_get_mac_from_pdev_id(hw, j);
578 }
579
580 if (ab->hw_params.ring_mask->rx_mon_status[i] & BIT(j)) {
581 irq_grp->irqs[num_irq++] =
582 ppdu_end_interrupts_mac1 -
583 ath11k_hw_get_mac_from_pdev_id(hw, j);
584 irq_grp->irqs[num_irq++] =
585 rxdma2host_monitor_status_ring_mac1 -
586 ath11k_hw_get_mac_from_pdev_id(hw, j);
587 }
588 }
589 }
590 irq_grp->num_irq = num_irq;
591
592 for (j = 0; j < irq_grp->num_irq; j++) {
593 int irq_idx = irq_grp->irqs[j];
594
595 irq = platform_get_irq_byname(ab->pdev,
596 irq_name[irq_idx]);
597 ab->irq_num[irq_idx] = irq;
598 irq_set_status_flags(irq, IRQ_NOAUTOEN | IRQ_DISABLE_UNLAZY);
599 ret = request_irq(irq, ath11k_ahb_ext_interrupt_handler,
600 IRQF_TRIGGER_RISING,
601 irq_name[irq_idx], irq_grp);
602 if (ret) {
603 ath11k_err(ab, "failed request_irq for %d\n",
604 irq);
605 irq_grp->num_irq = j;
606 goto err_request_irq;
607 }
608 }
609 }
610
611 return 0;
612
613 err_request_irq:
614 for ( ; i >= 0; i--) {

 > 615			irq_grp = &ab->ext_irq_grp[i];

616 for (j = irq_grp->num_irq - 1; j >= 0; j--)
617 free_irq(ab->irq_num[irq_grp->irqs[j]], irq_grp);
618 if (irq_grp->napi_ndev) {
619 netif_napi_del(&irq_grp->napi);
620 free_netdev(irq_grp->napi_ndev);
621 }
622 }
623 return ret;
624 }
625

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki