Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee3298a2 authored by Russell King - ARM Linux's avatar Russell King - ARM Linux Committed by Chris Ball
Browse files

mmc: fix sdhci-dove probe/removal



1. Never ever publish a device in the system before it has been setup
   to a usable state.
2. Unregister the device _BEFORE_ taking away any resources it may be
   using.
3. Don't check clks against NULL.

Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
Tested-by: default avatarSebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Signed-off-by: default avatarChris Ball <cjb@laptop.org>
parent a0d28ba0
Loading
Loading
Loading
Loading
+20 −18
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 */


#include <linux/err.h>
#include <linux/io.h>
#include <linux/io.h>
#include <linux/clk.h>
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/err.h>
@@ -84,30 +85,32 @@ static int __devinit sdhci_dove_probe(struct platform_device *pdev)
	struct sdhci_dove_priv *priv;
	struct sdhci_dove_priv *priv;
	int ret;
	int ret;


	ret = sdhci_pltfm_register(pdev, &sdhci_dove_pdata);
	if (ret)
		goto sdhci_dove_register_fail;

	priv = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_dove_priv),
	priv = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_dove_priv),
			    GFP_KERNEL);
			    GFP_KERNEL);
	if (!priv) {
	if (!priv) {
		dev_err(&pdev->dev, "unable to allocate private data");
		dev_err(&pdev->dev, "unable to allocate private data");
		ret = -ENOMEM;
		return -ENOMEM;
		goto sdhci_dove_allocate_fail;
	}
	}


	priv->clk = clk_get(&pdev->dev, NULL);
	if (!IS_ERR(priv->clk))
		clk_prepare_enable(priv->clk);

	ret = sdhci_pltfm_register(pdev, &sdhci_dove_pdata);
	if (ret)
		goto sdhci_dove_register_fail;

	host = platform_get_drvdata(pdev);
	host = platform_get_drvdata(pdev);
	pltfm_host = sdhci_priv(host);
	pltfm_host = sdhci_priv(host);
	pltfm_host->priv = priv;
	pltfm_host->priv = priv;


	priv->clk = clk_get(&pdev->dev, NULL);
	if (!IS_ERR(priv->clk))
		clk_prepare_enable(priv->clk);
	return 0;
	return 0;


sdhci_dove_allocate_fail:
	sdhci_pltfm_unregister(pdev);
sdhci_dove_register_fail:
sdhci_dove_register_fail:
	if (!IS_ERR(priv->clk)) {
		clk_disable_unprepare(priv->clk);
		clk_put(priv->clk);
	}
	return ret;
	return ret;
}
}


@@ -117,14 +120,13 @@ static int __devexit sdhci_dove_remove(struct platform_device *pdev)
	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
	struct sdhci_dove_priv *priv = pltfm_host->priv;
	struct sdhci_dove_priv *priv = pltfm_host->priv;


	if (priv->clk) {
	sdhci_pltfm_unregister(pdev);

	if (!IS_ERR(priv->clk)) {
	if (!IS_ERR(priv->clk)) {
		clk_disable_unprepare(priv->clk);
		clk_disable_unprepare(priv->clk);
		clk_put(priv->clk);
		clk_put(priv->clk);
	}
	}
		devm_kfree(&pdev->dev, priv->clk);
	return 0;
	}
	return sdhci_pltfm_unregister(pdev);
}
}


static const struct of_device_id sdhci_dove_of_match_table[] __devinitdata = {
static const struct of_device_id sdhci_dove_of_match_table[] __devinitdata = {