Commit 9afdd612 authored by Johannes Thumshirn's avatar Johannes Thumshirn Committed by Kalle Valo

cw1200: Don't leak memory if krealloc failes

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: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Cc: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent 424342ff
...@@ -1807,16 +1807,18 @@ static int wsm_buf_reserve(struct wsm_buf *buf, size_t extra_size) ...@@ -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 pos = buf->data - buf->begin;
size_t size = pos + extra_size; size_t size = pos + extra_size;
u8 *tmp;
size = round_up(size, FWLOAD_BLOCK_SIZE); size = round_up(size, FWLOAD_BLOCK_SIZE);
buf->begin = krealloc(buf->begin, size, GFP_KERNEL | GFP_DMA); tmp = krealloc(buf->begin, size, GFP_KERNEL | GFP_DMA);
if (buf->begin) { if (!tmp) {
buf->data = &buf->begin[pos]; wsm_buf_deinit(buf);
buf->end = &buf->begin[size];
return 0;
} else {
buf->end = buf->data = buf->begin;
return -ENOMEM; return -ENOMEM;
} }
buf->begin = tmp;
buf->data = &buf->begin[pos];
buf->end = &buf->begin[size];
return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment