linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iwlwifi: pnvm: Fix a memory leak in 'iwl_pnvm_get_from_fs()'
@ 2021-09-02 20:38 Christophe JAILLET
  2021-09-03  8:19 ` Dan Carpenter
  2021-09-05  6:11 ` Kalle Valo
  0 siblings, 2 replies; 4+ messages in thread
From: Christophe JAILLET @ 2021-09-02 20:38 UTC (permalink / raw)
  To: luciano.coelho, kvalo, davem, kuba, johannes.berg,
	pierre-louis.bossart, drorx.moshe
  Cc: linux-wireless, netdev, linux-kernel, kernel-janitors,
	Christophe JAILLET

A firmware is requested but never released in this function. This leads to
a memory leak in the normal execution path.

Add the missing 'release_firmware()' call.
Also introduce a temp variable (new_len) in order to keep the value of
'pnvm->size' after the firmware has been released.

Fixes: cdda18fbbefa ("iwlwifi: pnvm: move file loading code to a separate function")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/net/wireless/intel/iwlwifi/fw/pnvm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c
index 314ed90c23dd..dde22bdc8703 100644
--- a/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c
+++ b/drivers/net/wireless/intel/iwlwifi/fw/pnvm.c
@@ -231,6 +231,7 @@ static int iwl_pnvm_get_from_fs(struct iwl_trans *trans, u8 **data, size_t *len)
 {
 	const struct firmware *pnvm;
 	char pnvm_name[MAX_PNVM_NAME];
+	size_t new_len;
 	int ret;
 
 	iwl_pnvm_get_fs_name(trans, pnvm_name, sizeof(pnvm_name));
@@ -242,11 +243,14 @@ static int iwl_pnvm_get_from_fs(struct iwl_trans *trans, u8 **data, size_t *len)
 		return ret;
 	}
 
+	new_len = pnvm->size;
 	*data = kmemdup(pnvm->data, pnvm->size, GFP_KERNEL);
+	release_firmware(pnvm);
+
 	if (!*data)
 		return -ENOMEM;
 
-	*len = pnvm->size;
+	*len = new_len;
 
 	return 0;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iwlwifi: pnvm: Fix a memory leak in 'iwl_pnvm_get_from_fs()'
  2021-09-02 20:38 [PATCH] iwlwifi: pnvm: Fix a memory leak in 'iwl_pnvm_get_from_fs()' Christophe JAILLET
@ 2021-09-03  8:19 ` Dan Carpenter
  2021-09-03  8:55   ` Coelho, Luciano
  2021-09-05  6:11 ` Kalle Valo
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2021-09-03  8:19 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: luciano.coelho, kvalo, davem, kuba, johannes.berg,
	pierre-louis.bossart, drorx.moshe, linux-wireless, netdev,
	linux-kernel, kernel-janitors

On Thu, Sep 02, 2021 at 10:38:11PM +0200, Christophe JAILLET wrote:
> A firmware is requested but never released in this function. This leads to
> a memory leak in the normal execution path.
> 
> Add the missing 'release_firmware()' call.
> Also introduce a temp variable (new_len) in order to keep the value of
> 'pnvm->size' after the firmware has been released.
> 
> Fixes: cdda18fbbefa ("iwlwifi: pnvm: move file loading code to a separate function")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

regards,
dan carpenter



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iwlwifi: pnvm: Fix a memory leak in 'iwl_pnvm_get_from_fs()'
  2021-09-03  8:19 ` Dan Carpenter
@ 2021-09-03  8:55   ` Coelho, Luciano
  0 siblings, 0 replies; 4+ messages in thread
From: Coelho, Luciano @ 2021-09-03  8:55 UTC (permalink / raw)
  To: dan.carpenter, christophe.jaillet
  Cc: kernel-janitors, kvalo, Berg, Johannes, davem, linux-kernel,
	linux-wireless, netdev, pierre-louis.bossart, drorx.moshe, kuba

On Fri, 2021-09-03 at 11:19 +0300, Dan Carpenter wrote:
> On Thu, Sep 02, 2021 at 10:38:11PM +0200, Christophe JAILLET wrote:
> > A firmware is requested but never released in this function. This leads to
> > a memory leak in the normal execution path.
> > 
> > Add the missing 'release_firmware()' call.
> > Also introduce a temp variable (new_len) in order to keep the value of
> > 'pnvm->size' after the firmware has been released.
> > 
> > Fixes: cdda18fbbefa ("iwlwifi: pnvm: move file loading code to a separate function")
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> 
> Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

Acked-by: Luca Coelho <luca@coelho.fi>

Kalle, can you please queue this for v5.15? I'll assign it to you. 
Thanks! 

--
Cheers,
Luca.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iwlwifi: pnvm: Fix a memory leak in 'iwl_pnvm_get_from_fs()'
  2021-09-02 20:38 [PATCH] iwlwifi: pnvm: Fix a memory leak in 'iwl_pnvm_get_from_fs()' Christophe JAILLET
  2021-09-03  8:19 ` Dan Carpenter
@ 2021-09-05  6:11 ` Kalle Valo
  1 sibling, 0 replies; 4+ messages in thread
From: Kalle Valo @ 2021-09-05  6:11 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: luciano.coelho, davem, kuba, johannes.berg, pierre-louis.bossart,
	drorx.moshe, linux-wireless, netdev, linux-kernel,
	kernel-janitors, Christophe JAILLET

Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:

> A firmware is requested but never released in this function. This leads to
> a memory leak in the normal execution path.
> 
> Add the missing 'release_firmware()' call.
> Also introduce a temp variable (new_len) in order to keep the value of
> 'pnvm->size' after the firmware has been released.
> 
> Fixes: cdda18fbbefa ("iwlwifi: pnvm: move file loading code to a separate function")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
> Acked-by: Luca Coelho <luca@coelho.fi>

Patch applied to wireless-drivers.git, thanks.

45010c080e6e iwlwifi: pnvm: Fix a memory leak in 'iwl_pnvm_get_from_fs()'

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/1b5d80f54c1dbf85710fd285243932943b498fe7.1630614969.git.christophe.jaillet@wanadoo.fr/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-05  6:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-02 20:38 [PATCH] iwlwifi: pnvm: Fix a memory leak in 'iwl_pnvm_get_from_fs()' Christophe JAILLET
2021-09-03  8:19 ` Dan Carpenter
2021-09-03  8:55   ` Coelho, Luciano
2021-09-05  6:11 ` Kalle Valo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).