* [PATCH 2/5] hwrng: exynos - Runtime suspend device after init
2016-03-11 7:49 [PATCH 1/5] hwrng: exynos - Hide PM functions with __maybe_unused Krzysztof Kozlowski
@ 2016-03-11 7:49 ` Krzysztof Kozlowski
2016-03-11 7:49 ` [PATCH 3/5] hwrng: exynos - Fix unbalanced PM runtime put on timeout error path Krzysztof Kozlowski
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2016-03-11 7:49 UTC (permalink / raw)
To: Matt Mackall, Herbert Xu, Kukjin Kim, linux-crypto,
linux-arm-kernel, linux-samsung-soc, linux-kernel
Cc: Krzysztof Kozlowski
The driver uses pm_runtime_put_noidle() after initialization so the
device might remain in active state if the core does not read from it
(the read callback contains regular runtime put). The put_noidle() was
chosen probably to avoid unneeded suspend and resume cycle after the
initialization.
However for this purpose autosuspend is enabled so it is safe to runtime
put just after the initialization.
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
drivers/char/hw_random/exynos-rng.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/char/hw_random/exynos-rng.c b/drivers/char/hw_random/exynos-rng.c
index ada081232528..d1fd21e99368 100644
--- a/drivers/char/hw_random/exynos-rng.c
+++ b/drivers/char/hw_random/exynos-rng.c
@@ -77,7 +77,8 @@ static int exynos_init(struct hwrng *rng)
pm_runtime_get_sync(exynos_rng->dev);
ret = exynos_rng_configure(exynos_rng);
- pm_runtime_put_noidle(exynos_rng->dev);
+ pm_runtime_mark_last_busy(exynos_rng->dev);
+ pm_runtime_put_autosuspend(exynos_rng->dev);
return ret;
}
--
2.5.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/5] hwrng: exynos - Fix unbalanced PM runtime put on timeout error path
2016-03-11 7:49 [PATCH 1/5] hwrng: exynos - Hide PM functions with __maybe_unused Krzysztof Kozlowski
2016-03-11 7:49 ` [PATCH 2/5] hwrng: exynos - Runtime suspend device after init Krzysztof Kozlowski
@ 2016-03-11 7:49 ` Krzysztof Kozlowski
2016-03-11 7:49 ` [PATCH 4/5] hwrng: exynos - Disable runtime PM on probe failure Krzysztof Kozlowski
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2016-03-11 7:49 UTC (permalink / raw)
To: Matt Mackall, Herbert Xu, Kukjin Kim, linux-crypto,
linux-arm-kernel, linux-samsung-soc, linux-kernel
Cc: Krzysztof Kozlowski, stable
In case of timeout during read operation, the exit path lacked PM
runtime put. This could lead to unbalanced runtime PM usage counter thus
leaving the device in an active state.
Fixes: d7fd6075a205 ("hwrng: exynos - Add timeout for waiting on init done")
Cc: <stable@vger.kernel.org> # v4.4+
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
drivers/char/hw_random/exynos-rng.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/char/hw_random/exynos-rng.c b/drivers/char/hw_random/exynos-rng.c
index d1fd21e99368..38b80f82ddd2 100644
--- a/drivers/char/hw_random/exynos-rng.c
+++ b/drivers/char/hw_random/exynos-rng.c
@@ -90,6 +90,7 @@ static int exynos_read(struct hwrng *rng, void *buf,
struct exynos_rng, rng);
u32 *data = buf;
int retry = 100;
+ int ret = 4;
pm_runtime_get_sync(exynos_rng->dev);
@@ -98,17 +99,20 @@ static int exynos_read(struct hwrng *rng, void *buf,
while (!(exynos_rng_readl(exynos_rng,
EXYNOS_PRNG_STATUS_OFFSET) & PRNG_DONE) && --retry)
cpu_relax();
- if (!retry)
- return -ETIMEDOUT;
+ if (!retry) {
+ ret = -ETIMEDOUT;
+ goto out;
+ }
exynos_rng_writel(exynos_rng, PRNG_DONE, EXYNOS_PRNG_STATUS_OFFSET);
*data = exynos_rng_readl(exynos_rng, EXYNOS_PRNG_OUT1_OFFSET);
+out:
pm_runtime_mark_last_busy(exynos_rng->dev);
pm_runtime_put_sync_autosuspend(exynos_rng->dev);
- return 4;
+ return ret;
}
static int exynos_rng_probe(struct platform_device *pdev)
--
2.5.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/5] hwrng: exynos - Disable runtime PM on probe failure
2016-03-11 7:49 [PATCH 1/5] hwrng: exynos - Hide PM functions with __maybe_unused Krzysztof Kozlowski
2016-03-11 7:49 ` [PATCH 2/5] hwrng: exynos - Runtime suspend device after init Krzysztof Kozlowski
2016-03-11 7:49 ` [PATCH 3/5] hwrng: exynos - Fix unbalanced PM runtime put on timeout error path Krzysztof Kozlowski
@ 2016-03-11 7:49 ` Krzysztof Kozlowski
2016-03-11 7:49 ` [PATCH 5/5] hwrng: exynos - Disable runtime PM on driver unbind Krzysztof Kozlowski
2016-03-12 4:55 ` [PATCH 1/5] hwrng: exynos - Hide PM functions with __maybe_unused Krzysztof Kozlowski
4 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2016-03-11 7:49 UTC (permalink / raw)
To: Matt Mackall, Herbert Xu, Kukjin Kim, linux-crypto,
linux-arm-kernel, linux-samsung-soc, linux-kernel
Cc: Krzysztof Kozlowski
Add proper error path (for disabling runtime PM) when registering of
hwrng fails.
Fixes: b329669ea0b5 ("hwrng: exynos - Add support for Exynos random number generator")
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
drivers/char/hw_random/exynos-rng.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/char/hw_random/exynos-rng.c b/drivers/char/hw_random/exynos-rng.c
index 38b80f82ddd2..68c349bf66a0 100644
--- a/drivers/char/hw_random/exynos-rng.c
+++ b/drivers/char/hw_random/exynos-rng.c
@@ -119,6 +119,7 @@ static int exynos_rng_probe(struct platform_device *pdev)
{
struct exynos_rng *exynos_rng;
struct resource *res;
+ int ret;
exynos_rng = devm_kzalloc(&pdev->dev, sizeof(struct exynos_rng),
GFP_KERNEL);
@@ -146,7 +147,11 @@ static int exynos_rng_probe(struct platform_device *pdev)
pm_runtime_use_autosuspend(&pdev->dev);
pm_runtime_enable(&pdev->dev);
- return devm_hwrng_register(&pdev->dev, &exynos_rng->rng);
+ ret = devm_hwrng_register(&pdev->dev, &exynos_rng->rng);
+ if (ret)
+ pm_runtime_disable(&pdev->dev);
+
+ return ret;
}
static int __maybe_unused exynos_rng_runtime_suspend(struct device *dev)
--
2.5.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/5] hwrng: exynos - Disable runtime PM on driver unbind
2016-03-11 7:49 [PATCH 1/5] hwrng: exynos - Hide PM functions with __maybe_unused Krzysztof Kozlowski
` (2 preceding siblings ...)
2016-03-11 7:49 ` [PATCH 4/5] hwrng: exynos - Disable runtime PM on probe failure Krzysztof Kozlowski
@ 2016-03-11 7:49 ` Krzysztof Kozlowski
2016-03-12 5:26 ` Krzysztof Kozlowski
2016-03-12 4:55 ` [PATCH 1/5] hwrng: exynos - Hide PM functions with __maybe_unused Krzysztof Kozlowski
4 siblings, 1 reply; 7+ messages in thread
From: Krzysztof Kozlowski @ 2016-03-11 7:49 UTC (permalink / raw)
To: Matt Mackall, Herbert Xu, Kukjin Kim, linux-crypto,
linux-arm-kernel, linux-samsung-soc, linux-kernel
Cc: Krzysztof Kozlowski
Driver enabled runtime PM but did not revert this on removal. Re-binding
of a device triggered warning:
exynos-rng 10830400.rng: Unbalanced pm_runtime_enable!
Fixes: b329669ea0b5 ("hwrng: exynos - Add support for Exynos random number generator")
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
drivers/char/hw_random/exynos-rng.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/char/hw_random/exynos-rng.c b/drivers/char/hw_random/exynos-rng.c
index 68c349bf66a0..cba1ff538c46 100644
--- a/drivers/char/hw_random/exynos-rng.c
+++ b/drivers/char/hw_random/exynos-rng.c
@@ -154,6 +154,13 @@ static int exynos_rng_probe(struct platform_device *pdev)
return ret;
}
+static int exynos_rng_remove(struct platform_device *pdev)
+{
+ pm_runtime_disable(&pdev->dev);
+
+ return 0;
+}
+
static int __maybe_unused exynos_rng_runtime_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
@@ -211,6 +218,7 @@ static struct platform_driver exynos_rng_driver = {
.of_match_table = exynos_rng_dt_match,
},
.probe = exynos_rng_probe,
+ .remove = exynos_rng_remove,
};
module_platform_driver(exynos_rng_driver);
--
2.5.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 5/5] hwrng: exynos - Disable runtime PM on driver unbind
2016-03-11 7:49 ` [PATCH 5/5] hwrng: exynos - Disable runtime PM on driver unbind Krzysztof Kozlowski
@ 2016-03-12 5:26 ` Krzysztof Kozlowski
0 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2016-03-12 5:26 UTC (permalink / raw)
To: Matt Mackall, Herbert Xu, Kukjin Kim, linux-crypto,
linux-arm-kernel, linux-samsung-soc, linux-kernel
Cc: k.kozlowski.k
W dniu 11.03.2016 o 16:49, Krzysztof Kozlowski pisze:
> Driver enabled runtime PM but did not revert this on removal. Re-binding
> of a device triggered warning:
> exynos-rng 10830400.rng: Unbalanced pm_runtime_enable!
>
> Fixes: b329669ea0b5 ("hwrng: exynos - Add support for Exynos random number generator")
> Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> ---
> drivers/char/hw_random/exynos-rng.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/char/hw_random/exynos-rng.c b/drivers/char/hw_random/exynos-rng.c
> index 68c349bf66a0..cba1ff538c46 100644
> --- a/drivers/char/hw_random/exynos-rng.c
> +++ b/drivers/char/hw_random/exynos-rng.c
> @@ -154,6 +154,13 @@ static int exynos_rng_probe(struct platform_device *pdev)
> return ret;
> }
>
> +static int exynos_rng_remove(struct platform_device *pdev)
> +{
> + pm_runtime_disable(&pdev->dev);
> +
This is not sufficient. pm_runtime_dont_use_autosuspend() is also
necessary here. I will send a v2.
BTW, no problem if it is too late for taking this for v4.6. If this
patchset misses merge window I'll resend it later.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/5] hwrng: exynos - Hide PM functions with __maybe_unused
2016-03-11 7:49 [PATCH 1/5] hwrng: exynos - Hide PM functions with __maybe_unused Krzysztof Kozlowski
` (3 preceding siblings ...)
2016-03-11 7:49 ` [PATCH 5/5] hwrng: exynos - Disable runtime PM on driver unbind Krzysztof Kozlowski
@ 2016-03-12 4:55 ` Krzysztof Kozlowski
4 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2016-03-12 4:55 UTC (permalink / raw)
To: Matt Mackall, Herbert Xu, Kukjin Kim, linux-crypto,
linux-arm-kernel, linux-samsung-soc, linux-kernel
Cc: Krzysztof Kozlowski
2016-03-11 16:49 GMT+09:00 Krzysztof Kozlowski <k.kozlowski@samsung.com>:
> Replace ifdef with __maybe_unused to silence compiler warning on when
> SUSPEND=n and PM=y:
>
> drivers/char/hw_random/exynos-rng.c:166:12: warning: ‘exynos_rng_suspend’ defined but not used [-Wunused-function]
> static int exynos_rng_suspend(struct device *dev)
> ^
> drivers/char/hw_random/exynos-rng.c:171:12: warning: ‘exynos_rng_resume’ defined but not used [-Wunused-function]
> static int exynos_rng_resume(struct device *dev)
>
> Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
> ---
> drivers/char/hw_random/exynos-rng.c | 10 ++++------
> 1 file changed, 4 insertions(+), 6 deletions(-)
>
Patch can be dropped, Arnd sent the same some days before.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 7+ messages in thread