[PATCH] iwlwifi: pcie: Fix potential firmware allocation leaks on failure
From: Guangshuo Li
Date: Sun Dec 06 2026 - 03:41:51 EST
A failed firmware-section allocation leaves the descriptor arrays and
previous DMA allocations behind. The context-info pointer is not yet
published, so context-info cleanup cannot release the firmware image.
Unwind both section lists locally, using their successful allocation
counts and resetting them through the existing cleanup helpers.
This issue was found by our static analysis tool under development.
Fixes: eda50cde58de ("iwlwifi: pcie: add context information support")
Signed-off-by: Guangshuo Li <liguangshuo@xxxxxxxxxxxxxxx>
---
.../net/wireless/intel/iwlwifi/pcie/ctxt-info.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info.c b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info.c
index 7f886200d693..567c8061c0ac 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info.c
@@ -108,8 +108,10 @@ int iwl_pcie_init_fw_sec(struct iwl_trans *trans,
if (!dram->fw)
return -ENOMEM;
dram->paging = kzalloc_objs(*dram->paging, paging_cnt);
- if (!dram->paging)
- return -ENOMEM;
+ if (!dram->paging) {
+ ret = -ENOMEM;
+ goto err;
+ }
/* initialize lmac sections */
for (i = 0; i < lmac_cnt; i++) {
@@ -117,7 +119,7 @@ int iwl_pcie_init_fw_sec(struct iwl_trans *trans,
fw->sec[i].len,
&dram->fw[dram->fw_cnt]);
if (ret)
- return ret;
+ goto err;
ctxt_dram->lmac_img[i] =
cpu_to_le64(dram->fw[dram->fw_cnt].physical);
dram->fw_cnt++;
@@ -131,7 +133,7 @@ int iwl_pcie_init_fw_sec(struct iwl_trans *trans,
fw->sec[dram->fw_cnt + 1].len,
&dram->fw[dram->fw_cnt]);
if (ret)
- return ret;
+ goto err;
ctxt_dram->umac_img[i] =
cpu_to_le64(dram->fw[dram->fw_cnt].physical);
dram->fw_cnt++;
@@ -155,7 +157,7 @@ int iwl_pcie_init_fw_sec(struct iwl_trans *trans,
fw->sec[fw_idx].len,
&dram->paging[i]);
if (ret)
- return ret;
+ goto err;
ctxt_dram->virtual_img[i] =
cpu_to_le64(dram->paging[i].physical);
@@ -163,6 +165,11 @@ int iwl_pcie_init_fw_sec(struct iwl_trans *trans,
}
return 0;
+
+err:
+ iwl_pcie_ctxt_info_free_paging(trans);
+ iwl_pcie_ctxt_info_free_fw_img(trans);
+ return ret;
}
int iwl_pcie_ctxt_info_init(struct iwl_trans *trans,
base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907