From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
To: Johannes Thumshirn <jthumshirn@suse.de>,
Solomon Peachy <pizza@shaftnet.org>,
Kalle Valo <kvalo@codeaurora.org>
Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] cw1200: Don't leak memory if krealloc failes
Date: Fri, 30 Sep 2016 15:56:45 +0300 [thread overview]
Message-ID: <25a38254-f0e3-1f4e-de46-688d9fd1b736@cogentembedded.com> (raw)
In-Reply-To: <1475237495-15030-1-git-send-email-jthumshirn@suse.de>
Hello.
On 9/30/2016 3:11 PM, Johannes Thumshirn wrote:
> 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
Fails.
> 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>
> ---
> drivers/net/wireless/st/cw1200/wsm.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/net/wireless/st/cw1200/wsm.c b/drivers/net/wireless/st/cw1200/wsm.c
> index 680d60e..12fad99 100644
> --- a/drivers/net/wireless/st/cw1200/wsm.c
> +++ b/drivers/net/wireless/st/cw1200/wsm.c
> @@ -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) {
!tmp, you mean?
> + wsm_buf_deinit(buf);
> return -ENOMEM;
> }
> +
> + buf->begin = tmp;
> + buf->data = &buf->begin[pos];
> + buf->end = &buf->begin[size];
> + return 0;
> }
MBR, Sergei
next prev parent reply other threads:[~2016-09-30 12:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-30 12:11 Johannes Thumshirn
2016-09-30 12:29 ` Johannes Berg
2016-09-30 12:33 ` Johannes Thumshirn
2016-09-30 12:56 ` Sergei Shtylyov [this message]
2016-09-30 13:00 ` Johannes Thumshirn
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=25a38254-f0e3-1f4e-de46-688d9fd1b736@cogentembedded.com \
--to=sergei.shtylyov@cogentembedded.com \
--cc=jthumshirn@suse.de \
--cc=kvalo@codeaurora.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pizza@shaftnet.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®