mmc: add and use devm_mmc_alloc_host
Subsystems (2)
cover mmc: add and use devm_mmc_alloc_host
Add and use a device-managed version of mmc_alloc_host.
Heiner Kallweit (2):
mmc: core: add devm_mmc_alloc_host
mmc: meson-gx: use devm_mmc_alloc_host
drivers/mmc/core/host.c | 26 +++++++++++++++++ drivers/mmc/host/meson-gx-mmc.c | 52 +++++++++++---------------------- include/linux/mmc/host.h | 1 + 3 files changed, 44 insertions(+), 35 deletions(-)
Signature · 1 line
2.39.1
PATCH 1/2 mmc: core: add devm_mmc_alloc_host
Add a device-managed version of mmc_alloc_host().
The argument order is reversed compared to mmc_alloc_host() because device-managed functions typically have the device argument first.
Signed-off-by Heiner Kallweit <[email protected]>
--- drivers/mmc/core/host.c | 26 ++++++++++++++++++++++++++ include/linux/mmc/host.h | 1 + 2 files changed, 27 insertions(+)
drivers/mmc/core/host.c +26 -0
@@ -588,6 +588,32 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)EXPORT_SYMBOL (mmc_alloc_host); +static void devm_mmc_host_release (struct device *dev,void *res) +{ +mmc_free_host (*(struct mmc_host **)res); +} + +struct mmc_host *devm_mmc_alloc_host (struct device *dev,int extra) +{ +struct mmc_host **dr, *host; + + dr =devres_alloc (devm_mmc_host_release,sizeof (*dr),GFP_KERNEL ); +if (!dr) +return ERR_PTR (-ENOMEM ); + + host =mmc_alloc_host (extra, dev); +if (IS_ERR (host)) { +devres_free (dr); +return host; + } + + *dr = host; +devres_add (dev, dr); + +return host; +} +EXPORT_SYMBOL (devm_mmc_alloc_host); +static int mmc_validate_host_caps (struct mmc_host *host) {struct device *dev = host->parent;
include/linux/mmc/host.h +1 -0
@@ -527,6 +527,7 @@ struct mmc_host {struct device_node ;struct mmc_host *mmc_alloc_host (int extra,struct device *); +struct mmc_host *devm_mmc_alloc_host (struct device *dev,int extra);int mmc_add_host (struct mmc_host *);void mmc_remove_host (struct mmc_host *);void mmc_free_host (struct mmc_host *);
Signature · 1 line
2.39.1
PATCH 2/2 mmc: meson-gx: use devm_mmc_alloc_host
In reply to Heiner KallweitUse new function devm_mmc_alloc_host() to simplify the code.
Signed-off-by Heiner Kallweit <[email protected]>
--- drivers/mmc/host/meson-gx-mmc.c | 52 +++++++++++---------------------- 1 file changed, 17 insertions(+), 35 deletions(-)
drivers/mmc/host/meson-gx-mmc.c +17 -35
@@ -1185,7 +1185,7 @@ static int meson_mmc_probe(struct platform_device *pdev)struct mmc_host *mmc;int ret; - mmc =mmc_alloc_host (sizeof (struct meson_host ), &pdev->dev); + mmc =devm_mmc_alloc_host (&pdev->dev,sizeof (struct meson_host ));if (!mmc)return -ENOMEM ; host =mmc_priv (mmc);
@@ -1201,46 +1201,33 @@ static int meson_mmc_probe(struct platform_device *pdev) host->vqmmc_enabled = false; ret =mmc_regulator_get_supply (mmc);if (ret) - goto free_host; +return ret; ret =mmc_of_parse (mmc); -if (ret) { -if (ret != -EPROBE_DEFER ) -dev_warn (&pdev->dev,"error parsing DT: %d\n" , ret); - goto free_host; - } +if (ret) +return dev_err_probe (&pdev->dev, ret,"error parsing DT\n" ); host->data = (struct meson_mmc_data *)of_device_get_match_data (&pdev->dev); -if (!host->data) { - ret = -EINVAL ; - goto free_host; - } +if (!host->data) +return -EINVAL ; ret =device_reset_optional (&pdev->dev); -if (ret) { -dev_err_probe (&pdev->dev, ret,"device reset failed\n" ); - goto free_host; - } +if (ret) +return dev_err_probe (&pdev->dev, ret,"device reset failed\n" ); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); host->regs =devm_ioremap_resource (&pdev->dev, res); -if (IS_ERR (host->regs)) { - ret =PTR_ERR (host->regs); - goto free_host; - } +if (IS_ERR (host->regs)) +return PTR_ERR (host->regs); host->irq =platform_get_irq (pdev,0 ); -if (host->irq <=0 ) { - ret = -EINVAL ; - goto free_host; - } +if (host->irq <=0 ) +return -EINVAL ; host->pinctrl =devm_pinctrl_get (&pdev->dev); -if (IS_ERR (host->pinctrl)) { - ret =PTR_ERR (host->pinctrl); - goto free_host; - } +if (IS_ERR (host->pinctrl)) +return PTR_ERR (host->pinctrl); host->pins_clk_gate =pinctrl_lookup_state (host->pinctrl,"clk-gate" );
@@ -1251,14 +1238,12 @@ static int meson_mmc_probe(struct platform_device *pdev) } host->core_clk =devm_clk_get (&pdev->dev,"core" ); -if (IS_ERR (host->core_clk)) { - ret =PTR_ERR (host->core_clk); - goto free_host; - } +if (IS_ERR (host->core_clk)) +return PTR_ERR (host->core_clk); ret =clk_prepare_enable (host->core_clk);if (ret) - goto free_host; +return ret; ret =meson_mmc_clk_init (host);if (ret)
@@ -1353,8 +1338,6 @@ static int meson_mmc_probe(struct platform_device *pdev)clk_disable_unprepare (host->mmc_clk); err_core_clk:clk_disable_unprepare (host->core_clk); -free_host: -mmc_free_host (mmc);return ret; }
@@ -1371,7 +1354,6 @@ static int meson_mmc_remove(struct platform_device *pdev)clk_disable_unprepare (host->mmc_clk);clk_disable_unprepare (host->core_clk); -mmc_free_host (host->mmc);return 0 ; }
Signature · 1 line
2.39.1
Quoted 12 lines · Heiner Kallweit
Add and use a device-managed version of
mmc_alloc_host.Heiner Kallweit (2):
mmc: core: adddevm_mmc_alloc_host
mmc: meson-gx: usedevm_mmc_alloc_hostdrivers/mmc/core/host.c | 26 +++++++++++++++++ drivers/mmc/host/meson-gx-mmc.c | 52 +++++++++++---------------------- include/linux/mmc/host.h | 1 + 3 files changed, 44 insertions(+), 35 deletions(-)
Applied for next, thanks!
Kind regards
Uffe