iwlwifi: pcie: free IML DMA memory allocation
authorJohannes Berg <johannes.berg@intel.com>
Fri, 18 Jun 2021 08:01:16 +0000 (11:01 +0300)
committerLuca Coelho <luciano.coelho@intel.com>
Tue, 22 Jun 2021 13:57:56 +0000 (16:57 +0300)
In the case of gen3 devices with image loader (IML) support,
we were leaking the IML DMA allocation and never freeing it.
Fix that.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
Link: https://lore.kernel.org/r/iwlwifi.20210618105614.07e117dbedb7.I7bb9ebbe0617656986c2a598ea5e827b533bd3b9@changeid
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
drivers/net/wireless/intel/iwlwifi/pcie/ctxt-info-gen3.c
drivers/net/wireless/intel/iwlwifi/pcie/internal.h

index 49560e5..c7b9ca2 100644 (file)
@@ -79,7 +79,6 @@ int iwl_pcie_ctxt_info_gen3_init(struct iwl_trans *trans,
        struct iwl_prph_scratch *prph_scratch;
        struct iwl_prph_scratch_ctrl_cfg *prph_sc_ctrl;
        struct iwl_prph_info *prph_info;
-       void *iml_img;
        u32 control_flags = 0;
        int ret;
        int cmdq_size = max_t(u32, IWL_CMD_QUEUE_SIZE,
@@ -190,14 +189,15 @@ int iwl_pcie_ctxt_info_gen3_init(struct iwl_trans *trans,
        trans_pcie->prph_scratch = prph_scratch;
 
        /* Allocate IML */
-       iml_img = dma_alloc_coherent(trans->dev, trans->iml_len,
-                                    &trans_pcie->iml_dma_addr, GFP_KERNEL);
-       if (!iml_img) {
+       trans_pcie->iml = dma_alloc_coherent(trans->dev, trans->iml_len,
+                                            &trans_pcie->iml_dma_addr,
+                                            GFP_KERNEL);
+       if (!trans_pcie->iml) {
                ret = -ENOMEM;
                goto err_free_ctxt_info;
        }
 
-       memcpy(iml_img, trans->iml, trans->iml_len);
+       memcpy(trans_pcie->iml, trans->iml, trans->iml_len);
 
        iwl_enable_fw_load_int_ctx_info(trans);
 
@@ -244,6 +244,11 @@ void iwl_pcie_ctxt_info_gen3_free(struct iwl_trans *trans)
        trans_pcie->ctxt_info_dma_addr = 0;
        trans_pcie->ctxt_info_gen3 = NULL;
 
+       dma_free_coherent(trans->dev, trans->iml_len, trans_pcie->iml,
+                         trans_pcie->iml_dma_addr);
+       trans_pcie->iml_dma_addr = 0;
+       trans_pcie->iml = NULL;
+
        iwl_pcie_ctxt_info_free_fw_img(trans);
 
        dma_free_coherent(trans->dev, sizeof(*trans_pcie->prph_scratch),
index 292b972..69289e9 100644 (file)
@@ -271,6 +271,8 @@ struct cont_rec {
  *     Context information addresses will be taken from here.
  *     This is driver's local copy for keeping track of size and
  *     count for allocating and freeing the memory.
+ * @iml: image loader image virtual address
+ * @iml_dma_addr: image loader image DMA address
  * @trans: pointer to the generic transport area
  * @scd_base_addr: scheduler sram base address in SRAM
  * @kw: keep warm address
@@ -322,6 +324,7 @@ struct iwl_trans_pcie {
        };
        struct iwl_prph_info *prph_info;
        struct iwl_prph_scratch *prph_scratch;
+       void *iml;
        dma_addr_t ctxt_info_dma_addr;
        dma_addr_t prph_info_dma_addr;
        dma_addr_t prph_scratch_dma_addr;