* [PATCH 0/2] mmc: add and use devm_mmc_alloc_host
@ 2023-02-03 23:50 Heiner Kallweit
2023-02-03 23:53 ` [PATCH 1/2] mmc: core: add devm_mmc_alloc_host Heiner Kallweit
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Heiner Kallweit @ 2023-02-03 23:50 UTC (permalink / raw)
To: Ulf Hansson, Neil Armstrong, Kevin Hilman, Jerome Brunet,
Martin Blumenstingl
Cc: linux-mmc@vger.kernel.org, open list:ARM/Amlogic Meson...,
linux-arm-kernel@lists.infradead.org
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(-)
--
2.39.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] mmc: core: add devm_mmc_alloc_host
2023-02-03 23:50 [PATCH 0/2] mmc: add and use devm_mmc_alloc_host Heiner Kallweit
@ 2023-02-03 23:53 ` Heiner Kallweit
2023-02-03 23:54 ` [PATCH 2/2] mmc: meson-gx: use devm_mmc_alloc_host Heiner Kallweit
2023-02-13 23:47 ` [PATCH 0/2] mmc: add and " Ulf Hansson
2 siblings, 0 replies; 4+ messages in thread
From: Heiner Kallweit @ 2023-02-03 23:53 UTC (permalink / raw)
To: Ulf Hansson, Neil Armstrong, Kevin Hilman, Jerome Brunet,
Martin Blumenstingl
Cc: linux-mmc@vger.kernel.org, open list:ARM/Amlogic Meson...,
linux-arm-kernel@lists.infradead.org
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 <hkallweit1@gmail.com>
---
drivers/mmc/core/host.c | 26 ++++++++++++++++++++++++++
include/linux/mmc/host.h | 1 +
2 files changed, 27 insertions(+)
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index d17eda753..6a7475ad7 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -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;
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 8fdd3cf97..812e6b583 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -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 *);
--
2.39.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] mmc: meson-gx: use devm_mmc_alloc_host
2023-02-03 23:50 [PATCH 0/2] mmc: add and use devm_mmc_alloc_host Heiner Kallweit
2023-02-03 23:53 ` [PATCH 1/2] mmc: core: add devm_mmc_alloc_host Heiner Kallweit
@ 2023-02-03 23:54 ` Heiner Kallweit
2023-02-13 23:47 ` [PATCH 0/2] mmc: add and " Ulf Hansson
2 siblings, 0 replies; 4+ messages in thread
From: Heiner Kallweit @ 2023-02-03 23:54 UTC (permalink / raw)
To: Ulf Hansson, Neil Armstrong, Kevin Hilman, Jerome Brunet,
Martin Blumenstingl
Cc: linux-mmc@vger.kernel.org, open list:ARM/Amlogic Meson...,
linux-arm-kernel@lists.infradead.org
Use new function devm_mmc_alloc_host() to simplify the code.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/mmc/host/meson-gx-mmc.c | 52 +++++++++++----------------------
1 file changed, 17 insertions(+), 35 deletions(-)
diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c
index be1a972c2..a2fc25467 100644
--- a/drivers/mmc/host/meson-gx-mmc.c
+++ b/drivers/mmc/host/meson-gx-mmc.c
@@ -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;
}
--
2.39.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] mmc: add and use devm_mmc_alloc_host
2023-02-03 23:50 [PATCH 0/2] mmc: add and use devm_mmc_alloc_host Heiner Kallweit
2023-02-03 23:53 ` [PATCH 1/2] mmc: core: add devm_mmc_alloc_host Heiner Kallweit
2023-02-03 23:54 ` [PATCH 2/2] mmc: meson-gx: use devm_mmc_alloc_host Heiner Kallweit
@ 2023-02-13 23:47 ` Ulf Hansson
2 siblings, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2023-02-13 23:47 UTC (permalink / raw)
To: Heiner Kallweit
Cc: Neil Armstrong, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
linux-mmc@vger.kernel.org, open list:ARM/Amlogic Meson...,
linux-arm-kernel@lists.infradead.org
On Sat, 4 Feb 2023 at 00:50, Heiner Kallweit <hkallweit1@gmail.com> wrote:
>
> 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(-)
>
Applied for next, thanks!
Kind regards
Uffe
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-02-13 23:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-03 23:50 [PATCH 0/2] mmc: add and use devm_mmc_alloc_host Heiner Kallweit
2023-02-03 23:53 ` [PATCH 1/2] mmc: core: add devm_mmc_alloc_host Heiner Kallweit
2023-02-03 23:54 ` [PATCH 2/2] mmc: meson-gx: use devm_mmc_alloc_host Heiner Kallweit
2023-02-13 23:47 ` [PATCH 0/2] mmc: add and " Ulf Hansson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox