linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arend van Spriel <arend@broadcom.com>
To: "Raphaël Beamonte" <raphael.beamonte@gmail.com>,
	"Johnny Kim" <johnny.kim@atmel.com>
Cc: Rachel Kim <rachel.kim@atmel.com>, Dean Lee <dean.lee@atmel.com>,
	"Chris Park" <chris.park@atmel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	<linux-wireless@vger.kernel.org>, <devel@driverdev.osuosl.org>,
	<linux-kernel@vger.kernel.org>,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [PATCHv2 5/5] staging: wilc1000: replace MALLOC_WILC_BUFFER() macro to avoid possible memory leak
Date: Mon, 17 Aug 2015 21:41:08 +0200	[thread overview]
Message-ID: <55D238D4.20800@broadcom.com> (raw)
In-Reply-To: <339fc87526f51233b262315b2297f68e3b00c7b6.1439838526.git.raphael.beamonte@gmail.com>

On 08/17/2015 09:28 PM, Raphaël Beamonte wrote:
> The MACRO_WILC_BUFFER() macro was using a return statement, and didn't

Probable MACRO_WILC_BUFFER should be MALLOC_WILC_BUFFER here.

> take care of possible memory leaks and subsequent bugs when it was failing
> after succeeding some allocations. This patch corrects this behavior.
>
> Signed-off-by: Raphaël Beamonte <raphael.beamonte@gmail.com>
> ---
>   drivers/staging/wilc1000/wilc_exported_buf.c | 37 ++++++++++++++++++++--------
>   1 file changed, 27 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/staging/wilc1000/wilc_exported_buf.c b/drivers/staging/wilc1000/wilc_exported_buf.c
> index c9a5943..0f3bdad 100644
> --- a/drivers/staging/wilc1000/wilc_exported_buf.c
> +++ b/drivers/staging/wilc1000/wilc_exported_buf.c
> @@ -8,13 +8,6 @@
>   #define LINUX_TX_SIZE	(64 * 1024)
>   #define WILC1000_FW_SIZE (4 * 1024)
>
> -#define MALLOC_WILC_BUFFER(name, size)	\
> -	exported_ ## name = kmalloc(size, GFP_KERNEL);	  \
> -	if (!exported_ ## name) {   \
> -		printk("fail to alloc: %s memory\n", exported_ ## name);  \
> -		return -ENOBUFS;	\
> -	}
> -
>   /*
>    * Add necessary buffer pointers
>    */
> @@ -45,11 +38,35 @@ static int __init wilc_module_init(void)
>   	/*
>   	 * alloc necessary memory
>   	 */
> -	MALLOC_WILC_BUFFER(g_tx_buf, LINUX_TX_SIZE)
> -	MALLOC_WILC_BUFFER(g_rx_buf, LINUX_RX_SIZE)
> -	MALLOC_WILC_BUFFER(g_fw_buf, WILC1000_FW_SIZE)
> +	exported_g_tx_buf = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
> +	if (!exported_g_tx_buf) {
> +		pr_err("fail to alloc tx buf");

There is really no need to print an error message here. kmalloc will 
blurb enough info when it fails.

So these buffers are globals? So does this driver support multiple 
devices, ie. how are these used when two wilc1000 supported devices are 
present.

Regards,
Arend

> +		return -ENOMEM;
> +	}
> +
> +	exported_g_rx_buf = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
> +	if (!exported_g_rx_buf) {
> +		pr_err("fail to alloc rx buf");
> +		goto free_g_tx_buf;
> +	}
> +
> +	exported_g_fw_buf = kmalloc(WILC1000_FW_SIZE, GFP_KERNEL);
> +	if (!exported_g_fw_buf) {
> +		pr_err("fail to alloc fw buf");
> +		goto free_g_rx_buf;
> +	}
>
>   	return 0;
> +
> +free_g_rx_buf:
> +	kfree(exported_g_rx_buf);
> +	exported_g_rx_buf = NULL;
> +
> +free_g_tx_buf:
> +	kfree(exported_g_tx_buf);
> +	exported_g_tx_buf = NULL;
> +
> +	return -ENOMEM;
>   }
>
>   static void __exit wilc_module_deinit(void)
>


  reply	other threads:[~2015-08-17 19:41 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-16  5:30 [PATCH 0/3] staging: wilc1000: code style patches Raphaël Beamonte
2015-08-16  5:30 ` [PATCH 1/3] staging: wilc1000: code style: fix macro with multiple statements Raphaël Beamonte
2015-08-17  9:08   ` Dan Carpenter
2015-08-17 14:39     ` Raphaël Beamonte
2015-08-17 16:08       ` [PATCH 0/5] staging: wilc1000: code improvements Raphaël Beamonte
2015-08-17 16:08         ` [PATCH 1/5] staging: wilc1000: remove DECLARE_WILC_BUFFER() Raphaël Beamonte
2015-08-17 16:08         ` [PATCH 2/5] staging: wilc1000: remove FREE_WILC_BUFFER() Raphaël Beamonte
2015-08-17 17:42           ` Dan Carpenter
2015-08-17 16:08         ` [PATCH 3/5] staging: wilc1000: replace MALLOC_WILC_BUFFER() macro to avoid possible memory leak Raphaël Beamonte
2015-08-17 17:31           ` Dan Carpenter
2015-08-17 16:08         ` [PATCH 4/5] staging: wilc1000: use pr_* instead of printk Raphaël Beamonte
2015-08-17 17:47           ` Dan Carpenter
2015-08-17 17:59             ` Raphaël Beamonte
2015-08-17 18:06               ` Dan Carpenter
2015-08-17 16:08         ` [PATCH 5/5] staging: wilc1000: remove void function return statements that are not useful Raphaël Beamonte
2015-08-17 19:28         ` [PATCHv2 0/5] staging: wilc1000: code improvements Raphaël Beamonte
2015-08-17 19:28           ` [PATCHv2 1/5] staging: wilc1000: remove void function return statements that are not useful Raphaël Beamonte
2015-08-17 19:28           ` [PATCHv2 2/5] staging: wilc1000: use pr_* instead of printk Raphaël Beamonte
2015-08-17 19:55             ` Greg Kroah-Hartman
2015-08-17 23:06               ` [PATCHv3] staging: wilc1000: use netdev_* " Raphaël Beamonte
2015-08-18  4:24                 ` Sudip Mukherjee
2015-08-18  5:27                   ` Raphaël Beamonte
2015-08-18  6:10                     ` Sudip Mukherjee
2015-08-19  2:58                 ` Greg Kroah-Hartman
2015-08-17 19:28           ` [PATCHv2 3/5] staging: wilc1000: remove DECLARE_WILC_BUFFER() Raphaël Beamonte
2015-08-17 19:28           ` [PATCHv2 4/5] staging: wilc1000: remove FREE_WILC_BUFFER() Raphaël Beamonte
2015-08-17 20:01             ` Greg Kroah-Hartman
2015-08-17 19:28           ` [PATCHv2 5/5] staging: wilc1000: replace MALLOC_WILC_BUFFER() macro to avoid possible memory leak Raphaël Beamonte
2015-08-17 19:41             ` Arend van Spriel [this message]
2015-08-17 23:12               ` [PATCHv3] " Raphaël Beamonte
2015-08-17 23:46                 ` Dan Carpenter
2015-08-18  9:15                   ` Dan Carpenter
2015-08-18 17:06                     ` Raphaël Beamonte
2015-08-19  2:59                       ` Greg Kroah-Hartman
2015-08-19  3:14                         ` [PATCHv4 0/2] staging: wilc1000: code improvements Raphaël Beamonte
2015-08-19  3:14                           ` [PATCHv4 1/2] staging: wilc1000: remove FREE_WILC_BUFFER() Raphaël Beamonte
2015-09-03  1:19                             ` Greg Kroah-Hartman
2015-09-05 16:25                               ` Raphaël Beamonte
2015-09-05 16:29                                 ` Raphaël Beamonte
2015-08-19  3:14                           ` [PATCHv4 2/2] staging: wilc1000: replace MALLOC_WILC_BUFFER() macro to avoid possible memory leak Raphaël Beamonte
2015-08-17 23:15               ` [PATCHv2 5/5] " Raphaël Beamonte
2015-08-16  5:30 ` [PATCH 2/3] staging: wilc1000: code style: fix globals initialized to false Raphaël Beamonte
2015-08-16  5:30 ` [PATCH 3/3] staging: wilc1000: code style: fix open brace { on wrong line Raphaël Beamonte

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=55D238D4.20800@broadcom.com \
    --to=arend@broadcom.com \
    --cc=chris.park@atmel.com \
    --cc=dan.carpenter@oracle.com \
    --cc=dean.lee@atmel.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johnny.kim@atmel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=rachel.kim@atmel.com \
    --cc=raphael.beamonte@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).