mmc: host: Fix mmc_alloc_host() error path
PATCH 1/1 mmc: host: Fix mmc_alloc_host() error path
From: Fabio Estevam <[email protected]>
If mmc_gpio_alloc() fails we miss to call 'kfree(host)', so rearrange the error path to fix it.
Signed-off-by Fabio Estevam <[email protected]>
--- drivers/mmc/core/host.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/mmc/core/host.c +10 -8
@@ -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);
Signature · 1 line
1.9.1
Quoted 4 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
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()?
Quoted 50 lines
Signed-off-by Fabio Estevam <[email protected]>--- drivers/mmc/core/host.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)drivers/mmc/core/host.c +10
-8@@ -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);
Quoted 7 lines · Adrian Hunter
Quoted 4 lines · Fabio Estevam
From: Fabio Estevam <[email protected]>
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()?
Yes, you are right. Sorry for the noise.
Thanks