]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
cw1200: Don't leak memory if krealloc failes
authorJohannes Thumshirn <jthumshirn@suse.de>
Fri, 30 Sep 2016 12:39:17 +0000 (14:39 +0200)
committerKalle Valo <kvalo@codeaurora.org>
Wed, 9 Nov 2016 01:36:44 +0000 (03:36 +0200)
The call to krealloc() in wsm_buf_reserve() directly assigns the newly
returned memory to buf->begin. This is all fine except when krealloc()
failes we loose the ability to free the old memory pointed to by
buf->begin. If we just create a temporary variable to assign memory to
and assign the memory to it we can mitigate the memory leak.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/st/cw1200/wsm.c

index 680d60eabc75de4b50a44a7bb6395fb020fa4b83..ffb245e941bbed6a5552ccc5855eaf86e7ed86c4 100644 (file)
@@ -1807,16 +1807,18 @@ static int wsm_buf_reserve(struct wsm_buf *buf, size_t extra_size)
 {
        size_t pos = buf->data - buf->begin;
        size_t size = pos + extra_size;
+       u8 *tmp;
 
        size = round_up(size, FWLOAD_BLOCK_SIZE);
 
-       buf->begin = krealloc(buf->begin, size, GFP_KERNEL | GFP_DMA);
-       if (buf->begin) {
-               buf->data = &buf->begin[pos];
-               buf->end = &buf->begin[size];
-               return 0;
-       } else {
-               buf->end = buf->data = buf->begin;
+       tmp = krealloc(buf->begin, size, GFP_KERNEL | GFP_DMA);
+       if (!tmp) {
+               wsm_buf_deinit(buf);
                return -ENOMEM;
        }
+
+       buf->begin = tmp;
+       buf->data = &buf->begin[pos];
+       buf->end = &buf->begin[size];
+       return 0;
 }