hwrng: exynos - Add timeout for waiting on init done
authorKrzysztof Kozlowski <k.kozlowski@samsung.com>
Mon, 19 Oct 2015 04:37:40 +0000 (13:37 +0900)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 20 Oct 2015 14:13:59 +0000 (22:13 +0800)
Driver may hang waiting indefinitely for PRNG to finish its
initialization stage. Instead of stalling return -ETIMEDOUT error.

Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/char/hw_random/exynos-rng.c

index 73318e2a34ddd2c4d320b3f26ccbb0ed3eea15fd..c117463642e34de73372e0e837c45f4289a8c90a 100644 (file)
@@ -81,14 +81,17 @@ static int exynos_read(struct hwrng *rng, void *buf,
        struct exynos_rng *exynos_rng = container_of(rng,
                                                struct exynos_rng, rng);
        u32 *data = buf;
+       int retry = 100;
 
        pm_runtime_get_sync(exynos_rng->dev);
 
        exynos_rng_writel(exynos_rng, PRNG_START, 0);
 
        while (!(exynos_rng_readl(exynos_rng,
-                       EXYNOS_PRNG_STATUS_OFFSET) & PRNG_DONE))
+                       EXYNOS_PRNG_STATUS_OFFSET) & PRNG_DONE) && --retry)
                cpu_relax();
+       if (!retry)
+               return -ETIMEDOUT;
 
        exynos_rng_writel(exynos_rng, PRNG_DONE, EXYNOS_PRNG_STATUS_OFFSET);