Skip to content

Commit 0f4f199

Browse files
Navidemlucacoelho
authored andcommitted
iwlwifi: pcie: fix memory leaks in iwl_pcie_ctxt_info_gen3_init
In iwl_pcie_ctxt_info_gen3_init there are cases that the allocated dma memory is leaked in case of error. DMA memories prph_scratch, prph_info, and ctxt_info_gen3 are allocated and initialized to be later assigned to trans_pcie. But in any error case before such assignment the allocated memories should be released. First of such error cases happens when iwl_pcie_init_fw_sec fails. Current implementation correctly releases prph_scratch. But in two sunsequent error cases where dma_alloc_coherent may fail, such releases are missing. This commit adds release for prph_scratch when allocation for prph_info fails, and adds releases for prph_scratch and prph_info when allocation for ctxt_info_gen3 fails. Fixes: 2ee8240 ("iwlwifi: pcie: support context information for 22560 devices") Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com> Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
1 parent b4b814f commit 0f4f199

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

Diff for: drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-gen3.c

+25-11
Original file line numberDiff line numberDiff line change
@@ -107,30 +107,30 @@ int iwl_pcie_ctxt_info_gen3_init(struct iwl_trans *trans,
107107

108108
/* allocate ucode sections in dram and set addresses */
109109
ret = iwl_pcie_init_fw_sec(trans, fw, &prph_scratch->dram);
110-
if (ret) {
111-
dma_free_coherent(trans->dev,
112-
sizeof(*prph_scratch),
113-
prph_scratch,
114-
trans_pcie->prph_scratch_dma_addr);
115-
return ret;
116-
}
110+
if (ret)
111+
goto err_free_prph_scratch;
112+
117113

118114
/* Allocate prph information
119115
* currently we don't assign to the prph info anything, but it would get
120116
* assigned later */
121117
prph_info = dma_alloc_coherent(trans->dev, sizeof(*prph_info),
122118
&trans_pcie->prph_info_dma_addr,
123119
GFP_KERNEL);
124-
if (!prph_info)
125-
return -ENOMEM;
120+
if (!prph_info) {
121+
ret = -ENOMEM;
122+
goto err_free_prph_scratch;
123+
}
126124

127125
/* Allocate context info */
128126
ctxt_info_gen3 = dma_alloc_coherent(trans->dev,
129127
sizeof(*ctxt_info_gen3),
130128
&trans_pcie->ctxt_info_dma_addr,
131129
GFP_KERNEL);
132-
if (!ctxt_info_gen3)
133-
return -ENOMEM;
130+
if (!ctxt_info_gen3) {
131+
ret = -ENOMEM;
132+
goto err_free_prph_info;
133+
}
134134

135135
ctxt_info_gen3->prph_info_base_addr =
136136
cpu_to_le64(trans_pcie->prph_info_dma_addr);
@@ -186,6 +186,20 @@ int iwl_pcie_ctxt_info_gen3_init(struct iwl_trans *trans,
186186
iwl_set_bit(trans, CSR_GP_CNTRL, CSR_AUTO_FUNC_INIT);
187187

188188
return 0;
189+
190+
err_free_prph_info:
191+
dma_free_coherent(trans->dev,
192+
sizeof(*prph_info),
193+
prph_info,
194+
trans_pcie->prph_info_dma_addr);
195+
196+
err_free_prph_scratch:
197+
dma_free_coherent(trans->dev,
198+
sizeof(*prph_scratch),
199+
prph_scratch,
200+
trans_pcie->prph_scratch_dma_addr);
201+
return ret;
202+
189203
}
190204

191205
void iwl_pcie_ctxt_info_gen3_free(struct iwl_trans *trans)

0 commit comments

Comments
 (0)