* [PATCH v2 0/3] mmc: cavium: bug fixes for 4.12
@ 2017-05-22 11:09 Jan Glauber
2017-05-22 11:09 ` [PATCH v2 1/3] mmc: cavium: Prevent crash with incomplete DT Jan Glauber
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Jan Glauber @ 2017-05-22 11:09 UTC (permalink / raw)
To: Ulf Hansson
Cc: David Daney, Rob Herring, Frank Rowand, Steven J . Hill,
linux-mmc, linux-kernel, Jan Glauber
Changes to v1:
- Fixed platform device leak, apply fix also to Octeon driver
- Use mmc_regulator_get_supply
Jan Glauber (3):
mmc: cavium: Prevent crash with incomplete DT
of/platform: Make of_platform_device_destroy globally visible
mmc: cavium: Fix probing race with regulator
drivers/mmc/host/cavium-octeon.c | 11 ++++++++++-
drivers/mmc/host/cavium-thunderx.c | 6 ++++++
drivers/mmc/host/cavium.c | 25 ++++++++++---------------
drivers/of/platform.c | 3 ++-
include/linux/of_platform.h | 1 +
5 files changed, 29 insertions(+), 17 deletions(-)
--
2.9.0.rc0.21.g7777322
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/3] mmc: cavium: Prevent crash with incomplete DT
2017-05-22 11:09 [PATCH v2 0/3] mmc: cavium: bug fixes for 4.12 Jan Glauber
@ 2017-05-22 11:09 ` Jan Glauber
2017-05-22 11:09 ` [PATCH v2 2/3] of/platform: Make of_platform_device_destroy globally visible Jan Glauber
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Jan Glauber @ 2017-05-22 11:09 UTC (permalink / raw)
To: Ulf Hansson
Cc: David Daney, Rob Herring, Frank Rowand, Steven J . Hill,
linux-mmc, linux-kernel, Jan Glauber
In case the DT specifies neither a regulator nor a gpio
for the shared power the driver will crash accessing the regulator.
Prevent the crash by checking the regulator before use.
Use mmc_regulator_get_supply() instead of open coding the same
logic.
Signed-off-by: Jan Glauber <jglauber@cavium.com>
---
drivers/mmc/host/cavium.c | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/drivers/mmc/host/cavium.c b/drivers/mmc/host/cavium.c
index 58b51ba..b8aaf0f 100644
--- a/drivers/mmc/host/cavium.c
+++ b/drivers/mmc/host/cavium.c
@@ -839,14 +839,14 @@ static void cvm_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
cvm_mmc_reset_bus(slot);
if (host->global_pwr_gpiod)
host->set_shared_power(host, 0);
- else
+ else if (!IS_ERR(mmc->supply.vmmc))
mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
break;
case MMC_POWER_UP:
if (host->global_pwr_gpiod)
host->set_shared_power(host, 1);
- else
+ else if (!IS_ERR(mmc->supply.vmmc))
mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd);
break;
}
@@ -968,20 +968,15 @@ static int cvm_mmc_of_parse(struct device *dev, struct cvm_mmc_slot *slot)
return -EINVAL;
}
- mmc->supply.vmmc = devm_regulator_get_optional(dev, "vmmc");
- if (IS_ERR(mmc->supply.vmmc)) {
- if (PTR_ERR(mmc->supply.vmmc) == -EPROBE_DEFER)
- return -EPROBE_DEFER;
- /*
- * Legacy Octeon firmware has no regulator entry, fall-back to
- * a hard-coded voltage to get a sane OCR.
- */
+ ret = mmc_regulator_get_supply(mmc);
+ if (ret == -EPROBE_DEFER)
+ return ret;
+ /*
+ * Legacy Octeon firmware has no regulator entry, fall-back to
+ * a hard-coded voltage to get a sane OCR.
+ */
+ if (IS_ERR(mmc->supply.vmmc))
mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
- } else {
- ret = mmc_regulator_get_ocrmask(mmc->supply.vmmc);
- if (ret > 0)
- mmc->ocr_avail = ret;
- }
/* Common MMC bindings */
ret = mmc_of_parse(mmc);
--
2.9.0.rc0.21.g7777322
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] of/platform: Make of_platform_device_destroy globally visible
2017-05-22 11:09 [PATCH v2 0/3] mmc: cavium: bug fixes for 4.12 Jan Glauber
2017-05-22 11:09 ` [PATCH v2 1/3] mmc: cavium: Prevent crash with incomplete DT Jan Glauber
@ 2017-05-22 11:09 ` Jan Glauber
2017-05-22 13:30 ` Rob Herring
2017-05-22 11:09 ` [PATCH v2 3/3] mmc: cavium: Fix probing race with regulator Jan Glauber
2017-05-22 16:04 ` [PATCH v2 0/3] mmc: cavium: bug fixes for 4.12 Ulf Hansson
3 siblings, 1 reply; 6+ messages in thread
From: Jan Glauber @ 2017-05-22 11:09 UTC (permalink / raw)
To: Ulf Hansson
Cc: David Daney, Rob Herring, Frank Rowand, Steven J . Hill,
linux-mmc, linux-kernel, Jan Glauber
of_platform_device_destroy is the counterpart to
of_platform_device_create which is a non-static function.
After creating a platform device it might be neccessary
to destroy it to deal with -EPROBE_DEFER where a
repeated of_platform_device_create call would fail otherwise.
Therefore also make of_platform_device_destroy globally visible.
Signed-off-by: Jan Glauber <jglauber@cavium.com>
---
drivers/of/platform.c | 3 ++-
include/linux/of_platform.h | 1 +
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 71fecc2..703a421 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -523,7 +523,7 @@ static int __init of_platform_default_populate_init(void)
arch_initcall_sync(of_platform_default_populate_init);
#endif
-static int of_platform_device_destroy(struct device *dev, void *data)
+int of_platform_device_destroy(struct device *dev, void *data)
{
/* Do not touch devices not populated from the device tree */
if (!dev->of_node || !of_node_check_flag(dev->of_node, OF_POPULATED))
@@ -544,6 +544,7 @@ static int of_platform_device_destroy(struct device *dev, void *data)
of_node_clear_flag(dev->of_node, OF_POPULATED_BUS);
return 0;
}
+EXPORT_SYMBOL_GPL(of_platform_device_destroy);
/**
* of_platform_depopulate() - Remove devices populated from device tree
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index dc8224a..e0d1946 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -64,6 +64,7 @@ extern struct platform_device *of_platform_device_create(struct device_node *np,
const char *bus_id,
struct device *parent);
+extern int of_platform_device_destroy(struct device *dev, void *data);
extern int of_platform_bus_probe(struct device_node *root,
const struct of_device_id *matches,
struct device *parent);
--
2.9.0.rc0.21.g7777322
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] mmc: cavium: Fix probing race with regulator
2017-05-22 11:09 [PATCH v2 0/3] mmc: cavium: bug fixes for 4.12 Jan Glauber
2017-05-22 11:09 ` [PATCH v2 1/3] mmc: cavium: Prevent crash with incomplete DT Jan Glauber
2017-05-22 11:09 ` [PATCH v2 2/3] of/platform: Make of_platform_device_destroy globally visible Jan Glauber
@ 2017-05-22 11:09 ` Jan Glauber
2017-05-22 16:04 ` [PATCH v2 0/3] mmc: cavium: bug fixes for 4.12 Ulf Hansson
3 siblings, 0 replies; 6+ messages in thread
From: Jan Glauber @ 2017-05-22 11:09 UTC (permalink / raw)
To: Ulf Hansson
Cc: David Daney, Rob Herring, Frank Rowand, Steven J . Hill,
linux-mmc, linux-kernel, Jan Glauber
If the regulator probing is not yet finished this driver
might catch a -EPROBE_DEFER. Returning after this condition
did not remove the created platform device. On a repeated
call to the probe function the of_platform_device_create
fails.
Calling of_platform_device_destroy after EPROBE_DEFER resolves
this bug.
Signed-off-by: Jan Glauber <jglauber@cavium.com>
---
drivers/mmc/host/cavium-octeon.c | 11 ++++++++++-
drivers/mmc/host/cavium-thunderx.c | 6 ++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/host/cavium-octeon.c b/drivers/mmc/host/cavium-octeon.c
index cbb5663..951d2cd 100644
--- a/drivers/mmc/host/cavium-octeon.c
+++ b/drivers/mmc/host/cavium-octeon.c
@@ -288,11 +288,20 @@ static int octeon_mmc_probe(struct platform_device *pdev)
if (ret) {
dev_err(&pdev->dev, "Error populating slots\n");
octeon_mmc_set_shared_power(host, 0);
- return ret;
+ goto error;
}
i++;
}
return 0;
+
+error:
+ for (i = 0; i < CAVIUM_MAX_MMC; i++) {
+ if (host->slot[i])
+ cvm_mmc_of_slot_remove(host->slot[i]);
+ if (host->slot_pdev[i])
+ of_platform_device_destroy(&host->slot_pdev[i]->dev, NULL);
+ }
+ return ret;
}
static int octeon_mmc_remove(struct platform_device *pdev)
diff --git a/drivers/mmc/host/cavium-thunderx.c b/drivers/mmc/host/cavium-thunderx.c
index fe3d772..b9cc959 100644
--- a/drivers/mmc/host/cavium-thunderx.c
+++ b/drivers/mmc/host/cavium-thunderx.c
@@ -146,6 +146,12 @@ static int thunder_mmc_probe(struct pci_dev *pdev,
return 0;
error:
+ for (i = 0; i < CAVIUM_MAX_MMC; i++) {
+ if (host->slot[i])
+ cvm_mmc_of_slot_remove(host->slot[i]);
+ if (host->slot_pdev[i])
+ of_platform_device_destroy(&host->slot_pdev[i]->dev, NULL);
+ }
clk_disable_unprepare(host->clk);
return ret;
}
--
2.9.0.rc0.21.g7777322
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/3] of/platform: Make of_platform_device_destroy globally visible
2017-05-22 11:09 ` [PATCH v2 2/3] of/platform: Make of_platform_device_destroy globally visible Jan Glauber
@ 2017-05-22 13:30 ` Rob Herring
0 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2017-05-22 13:30 UTC (permalink / raw)
To: Jan Glauber
Cc: Ulf Hansson, David Daney, Frank Rowand, Steven J . Hill,
linux-mmc, linux-kernel
On Mon, May 22, 2017 at 6:09 AM, Jan Glauber <jglauber@cavium.com> wrote:
> of_platform_device_destroy is the counterpart to
> of_platform_device_create which is a non-static function.
>
> After creating a platform device it might be neccessary
> to destroy it to deal with -EPROBE_DEFER where a
> repeated of_platform_device_create call would fail otherwise.
>
> Therefore also make of_platform_device_destroy globally visible.
>
> Signed-off-by: Jan Glauber <jglauber@cavium.com>
> ---
> drivers/of/platform.c | 3 ++-
> include/linux/of_platform.h | 1 +
> 2 files changed, 3 insertions(+), 1 deletion(-)
Acked-by: Rob Herring <robh@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] mmc: cavium: bug fixes for 4.12
2017-05-22 11:09 [PATCH v2 0/3] mmc: cavium: bug fixes for 4.12 Jan Glauber
` (2 preceding siblings ...)
2017-05-22 11:09 ` [PATCH v2 3/3] mmc: cavium: Fix probing race with regulator Jan Glauber
@ 2017-05-22 16:04 ` Ulf Hansson
3 siblings, 0 replies; 6+ messages in thread
From: Ulf Hansson @ 2017-05-22 16:04 UTC (permalink / raw)
To: Jan Glauber
Cc: David Daney, Rob Herring, Frank Rowand, Steven J . Hill,
linux-mmc, linux-kernel
On 22 May 2017 at 13:09, Jan Glauber <jglauber@cavium.com> wrote:
> Changes to v1:
> - Fixed platform device leak, apply fix also to Octeon driver
> - Use mmc_regulator_get_supply
>
> Jan Glauber (3):
> mmc: cavium: Prevent crash with incomplete DT
> of/platform: Make of_platform_device_destroy globally visible
> mmc: cavium: Fix probing race with regulator
>
> drivers/mmc/host/cavium-octeon.c | 11 ++++++++++-
> drivers/mmc/host/cavium-thunderx.c | 6 ++++++
> drivers/mmc/host/cavium.c | 25 ++++++++++---------------
> drivers/of/platform.c | 3 ++-
> include/linux/of_platform.h | 1 +
> 5 files changed, 29 insertions(+), 17 deletions(-)
>
> --
> 2.9.0.rc0.21.g7777322
>
Thanks, applied for fixes!
Kind regards
Uffe
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-05-22 16:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-22 11:09 [PATCH v2 0/3] mmc: cavium: bug fixes for 4.12 Jan Glauber
2017-05-22 11:09 ` [PATCH v2 1/3] mmc: cavium: Prevent crash with incomplete DT Jan Glauber
2017-05-22 11:09 ` [PATCH v2 2/3] of/platform: Make of_platform_device_destroy globally visible Jan Glauber
2017-05-22 13:30 ` Rob Herring
2017-05-22 11:09 ` [PATCH v2 3/3] mmc: cavium: Fix probing race with regulator Jan Glauber
2017-05-22 16:04 ` [PATCH v2 0/3] mmc: cavium: bug fixes for 4.12 Ulf Hansson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).