All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Fabio Estevam <festevam@gmail.com>, ulf.hansson@linaro.org
Cc: linux-mmc@vger.kernel.org, Fabio Estevam <fabio.estevam@freescale.com>
Subject: Re: [PATCH] mmc: host: Fix mmc_alloc_host() error path
Date: Fri, 12 Jun 2015 10:22:47 +0300	[thread overview]
Message-ID: <557A88C7.3020306@intel.com> (raw)
In-Reply-To: <1434083961-32540-1-git-send-email-festevam@gmail.com>

On 12/06/15 07:39, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@freescale.com>
> 
> If mmc_gpio_alloc() fails we miss to call 'kfree(host)', so rearrange
> the error path to fix it. 

Are you sure it doesn't get freed through put_device()?

> 
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
> ---
>  drivers/mmc/core/host.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
> index 99a9c90..01fa1ed 100644
> --- a/drivers/mmc/core/host.c
> +++ b/drivers/mmc/core/host.c
> @@ -566,10 +566,8 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
>  		host->index = err;
>  	spin_unlock(&mmc_host_lock);
>  	idr_preload_end();
> -	if (err < 0) {
> -		kfree(host);
> -		return NULL;
> -	}
> +	if (err < 0)
> +		goto err_kfree;
>  
>  	dev_set_name(&host->class_dev, "mmc%d", host->index);
>  
> @@ -578,10 +576,8 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
>  	host->class_dev.class = &mmc_host_class;
>  	device_initialize(&host->class_dev);
>  
> -	if (mmc_gpio_alloc(host)) {
> -		put_device(&host->class_dev);
> -		return NULL;
> -	}
> +	if (mmc_gpio_alloc(host))
> +		goto err_put_device;
>  
>  	mmc_host_clk_init(host);
>  
> @@ -605,6 +601,12 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
>  	host->max_blk_count = PAGE_CACHE_SIZE / 512;
>  
>  	return host;
> +
> +err_put_device:
> +	put_device(&host->class_dev);
> +err_kfree:
> +	kfree(host);
> +	return NULL;
>  }
>  
>  EXPORT_SYMBOL(mmc_alloc_host);
> 


  reply	other threads:[~2015-06-12  7:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12  4:39 [PATCH] mmc: host: Fix mmc_alloc_host() error path Fabio Estevam
2015-06-12  7:22 ` Adrian Hunter [this message]
2015-06-15 13:03   ` Fabio Estevam

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=557A88C7.3020306@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=fabio.estevam@freescale.com \
    --cc=festevam@gmail.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.