public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: wangyuhang <wangyuhang2014@gmail.com>
Cc: artem.bityutskiy@linux.intel.com, linux-mtd@lists.infradead.org
Subject: Re: [PATCH] m25p80: fix the malloc space without being freed when probe failed
Date: Tue, 16 Jul 2013 08:25:48 +0200	[thread overview]
Message-ID: <201307160825.48782.marex@denx.de> (raw)
In-Reply-To: <1373955657-10363-1-git-send-email-wangyuhang2014@gmail.com>

Dear wangyuhang,

> space allocated can not be freed when probe failed, So we use
> devm_kzalloc() to instead of kzalloc().
> flash->fast_read is used without being initialized, here
> move it to the certain position.
> 
> Signed-off-by: wangyuhang <wangyuhang2014@gmail.com>

The commit message is a little unclear, but otherwise I agree with the patch. 
The rest is I believe up to Artem.

> ---
>  drivers/mtd/devices/m25p80.c |   13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
> index 5b6b072..70f3c54 100644
> --- a/drivers/mtd/devices/m25p80.c
> +++ b/drivers/mtd/devices/m25p80.c
> @@ -955,15 +955,9 @@ static int m25p_probe(struct spi_device *spi)
>  		}
>  	}
> 
> -	flash = kzalloc(sizeof *flash, GFP_KERNEL);
> +	flash = devm_kzalloc(&spi->dev, sizeof *flash, GFP_KERNEL);
>  	if (!flash)
>  		return -ENOMEM;
> -	flash->command = kmalloc(MAX_CMD_SIZE + (flash->fast_read ? 1 : 0),
> -					GFP_KERNEL);
> -	if (!flash->command) {
> -		kfree(flash);
> -		return -ENOMEM;
> -	}
> 
>  	flash->spi = spi;
>  	mutex_init(&flash->lock);
> @@ -1032,6 +1026,11 @@ static int m25p_probe(struct spi_device *spi)
>  	flash->fast_read = true;
>  #endif
> 
> +	flash->command = devm_kzalloc(&spi->dev,
> +		MAX_CMD_SIZE + (flash->fast_read ? 1 : 0), GFP_KERNEL);
> +	if (!flash->command)
> +		return -ENOMEM;
> +
>  	if (info->addr_width)
>  		flash->addr_width = info->addr_width;
>  	else {

Best regards,
Marek Vasut

      reply	other threads:[~2013-07-16  6:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-16  6:20 [PATCH] m25p80: fix the malloc space without being freed when probe failed wangyuhang
2013-07-16  6:25 ` Marek Vasut [this message]

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=201307160825.48782.marex@denx.de \
    --to=marex@denx.de \
    --cc=artem.bityutskiy@linux.intel.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=wangyuhang2014@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