All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luca Coelho <luca@coelho.fi>
To: kvalo@kernel.org
Cc: luca@coelho.fi, linux-wireless@vger.kernel.org
Subject: [PATCH 07/10] iwlwifi: fix leaks/bad data after failed firmware load
Date: Fri, 10 Dec 2021 11:12:42 +0200	[thread overview]
Message-ID: <iwlwifi.20211210110539.1f742f0eb58a.I1315f22f6aa632d94ae2069f85e1bca5e734dce0@changeid> (raw)
In-Reply-To: <20211210091245.289008-1-luca@coelho.fi>

From: Johannes Berg <johannes.berg@intel.com>

If firmware load fails after having loaded some parts of the
firmware, e.g. the IML image, then this would leak. For the
host command list we'd end up running into a WARN on the next
attempt to load another firmware image.

Fix this by calling iwl_dealloc_ucode() on failures, and make
that also clear the data so we start fresh on the next round.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
---
 drivers/net/wireless/intel/iwlwifi/iwl-drv.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-drv.c b/drivers/net/wireless/intel/iwlwifi/iwl-drv.c
index 9652da2b8125..4dab1e88346d 100644
--- a/drivers/net/wireless/intel/iwlwifi/iwl-drv.c
+++ b/drivers/net/wireless/intel/iwlwifi/iwl-drv.c
@@ -130,6 +130,9 @@ static void iwl_dealloc_ucode(struct iwl_drv *drv)
 
 	for (i = 0; i < IWL_UCODE_TYPE_MAX; i++)
 		iwl_free_fw_img(drv, drv->fw.img + i);
+
+	/* clear the data for the aborted load case */
+	memset(&drv->fw, 0, sizeof(drv->fw));
 }
 
 static int iwl_alloc_fw_desc(struct iwl_drv *drv, struct fw_desc *desc,
@@ -1426,6 +1429,7 @@ static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
 	int i;
 	bool load_module = false;
 	bool usniffer_images = false;
+	bool failure = true;
 
 	fw->ucode_capa.max_probe_length = IWL_DEFAULT_MAX_PROBE_LENGTH;
 	fw->ucode_capa.standard_phy_calibration_size =
@@ -1695,6 +1699,7 @@ static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
 				op->name, err);
 #endif
 	}
+	failure = false;
 	goto free;
 
  try_again:
@@ -1710,6 +1715,9 @@ static void iwl_req_fw_callback(const struct firmware *ucode_raw, void *context)
 	complete(&drv->request_firmware_complete);
 	device_release_driver(drv->trans->dev);
  free:
+	if (failure)
+		iwl_dealloc_ucode(drv);
+
 	if (pieces) {
 		for (i = 0; i < ARRAY_SIZE(pieces->img); i++)
 			kfree(pieces->img[i].sec);
-- 
2.34.1


  parent reply	other threads:[~2021-12-10  9:13 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-10  9:12 [PATCH 00/10] iwlwifi: updates intended for v5.17 2021-12-10 part 2 Luca Coelho
2021-12-10  9:12 ` [PATCH 01/10] iwlwifi: parse error tables from debug TLVs Luca Coelho
2021-12-10  9:12 ` [PATCH 02/10] iwlwifi: dump CSR scratch from outer function Luca Coelho
2021-12-10  9:12 ` [PATCH 03/10] iwlwifi: dump both TCM error tables if present Luca Coelho
2021-12-10  9:12 ` [PATCH 04/10] iwlwifi: dump RCM error tables Luca Coelho
2021-12-10  9:12 ` [PATCH 05/10] iwlwifi: mvm: fix 32-bit build in FTM Luca Coelho
2021-12-13 10:49   ` Kalle Valo
2021-12-13 11:00     ` Luca Coelho
2021-12-14  5:55       ` Kalle Valo
2021-12-19  9:14   ` [PATCH v2 " Luca Coelho
2021-12-10  9:12 ` [PATCH 06/10] iwlwifi: fix debug TLV parsing Luca Coelho
2021-12-10  9:12 ` Luca Coelho [this message]
2021-12-10  9:12 ` [PATCH 08/10] iwlwifi: mvm: add support for OCE scan Luca Coelho
2021-12-10  9:12 ` [PATCH 09/10] iwlwifi: mvm: isolate offload assist (checksum) calculation Luca Coelho
2021-12-10  9:12 ` [PATCH 10/10] iwlwifi: remove module loading failure message Luca Coelho
2022-02-11 14:52 [PATCH 07/10] iwlwifi: fix leaks/bad data after failed firmware load Liu, Yongxin
2022-02-11 14:58 ` Johannes Berg
2022-02-11 15:15   ` Liu, Yongxin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=iwlwifi.20211210110539.1f742f0eb58a.I1315f22f6aa632d94ae2069f85e1bca5e734dce0@changeid \
    --to=luca@coelho.fi \
    --cc=kvalo@kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.