linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] brcm80211: Don't leak 'vbuffer' in brcmf_sdbrcm_write_vars()
@ 2012-01-08 22:41 Jesper Juhl
  2012-01-09 10:01 ` Arend van Spriel
  0 siblings, 1 reply; 2+ messages in thread
From: Jesper Juhl @ 2012-01-08 22:41 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Alwin Beukers, Pieter-Paul Giesberts,
	John W. Linville, Franky Lin, Arend van Spriel

If the memory allocation 'nvram_ularray = kmalloc(varsize,
GFP_ATOMIC);' fails we'll leak the memory allocated to 'vbuffer' when
we return -ENOMEM from the function.

This patch resolves the leak by kfree()'ing the allocated memory
before the return.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

  compile tested only.

diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
index 5a002a2..f7eeee1 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
@@ -3119,8 +3119,10 @@ static int brcmf_sdbrcm_write_vars(struct brcmf_sdio *bus)
 		/* Verify NVRAM bytes */
 		brcmf_dbg(INFO, "Compare NVRAM dl & ul; varsize=%d\n", varsize);
 		nvram_ularray = kmalloc(varsize, GFP_ATOMIC);
-		if (!nvram_ularray)
+		if (!nvram_ularray) {
+			kfree(vbuffer);
 			return -ENOMEM;
+		}
 
 		/* Upload image to verify downloaded contents. */
 		memset(nvram_ularray, 0xaa, varsize);
-- 
1.7.8.1



PS. Please CC me on replies.

-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.


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

* Re: [PATCH] brcm80211: Don't leak 'vbuffer' in brcmf_sdbrcm_write_vars()
  2012-01-08 22:41 [PATCH] brcm80211: Don't leak 'vbuffer' in brcmf_sdbrcm_write_vars() Jesper Juhl
@ 2012-01-09 10:01 ` Arend van Spriel
  0 siblings, 0 replies; 2+ messages in thread
From: Arend van Spriel @ 2012-01-09 10:01 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Alwin Beukers, Pieter-Paul Giesberts, John W. Linville,
	Franky (Zhenhui) Lin

On 01/08/2012 11:41 PM, Jesper Juhl wrote:
> If the memory allocation 'nvram_ularray = kmalloc(varsize,
> GFP_ATOMIC);' fails we'll leak the memory allocated to 'vbuffer' when
> we return -ENOMEM from the function.
> 
> This patch resolves the leak by kfree()'ing the allocated memory
> before the return.
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>

Nice catch. Thanks.

Acked-by: Arend van Spriel <arend@broadcom.com>

Gr. AvS


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

end of thread, other threads:[~2012-01-09 10:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-08 22:41 [PATCH] brcm80211: Don't leak 'vbuffer' in brcmf_sdbrcm_write_vars() Jesper Juhl
2012-01-09 10:01 ` Arend van Spriel

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).