linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw_random: omap3-rom-rng: convert timer to delayed work
@ 2015-11-05 22:15 Aaro Koskinen
  2015-11-06 19:20 ` Grygorii Strashko
  2015-11-17 13:36 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Aaro Koskinen @ 2015-11-05 22:15 UTC (permalink / raw)
  To: Matt Mackall, Herbert Xu, linux-crypto, Sebastian Reichel,
	Pali Rohár, linux-omap

We cannot put the HW RNG to idle using a timer because we cannot disable
clocks from atomic context. Use a delayed work instead.

Fixes a warning with CONFIG_DEBUG_MUTEXES on Nokia N900 during boot.

Reported-by: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
---
 drivers/char/hw_random/omap3-rom-rng.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
index a405cdc..58191c6 100644
--- a/drivers/char/hw_random/omap3-rom-rng.c
+++ b/drivers/char/hw_random/omap3-rom-rng.c
@@ -29,11 +29,11 @@
 /* param1: ptr, param2: count, param3: flag */
 static u32 (*omap3_rom_rng_call)(u32, u32, u32);
 
-static struct timer_list idle_timer;
+static struct delayed_work idle_work;
 static int rng_idle;
 static struct clk *rng_clk;
 
-static void omap3_rom_rng_idle(unsigned long data)
+static void omap3_rom_rng_idle(struct work_struct *work)
 {
 	int r;
 
@@ -51,7 +51,7 @@ static int omap3_rom_rng_get_random(void *buf, unsigned int count)
 	u32 r;
 	u32 ptr;
 
-	del_timer_sync(&idle_timer);
+	cancel_delayed_work_sync(&idle_work);
 	if (rng_idle) {
 		clk_prepare_enable(rng_clk);
 		r = omap3_rom_rng_call(0, 0, RNG_GEN_PRNG_HW_INIT);
@@ -65,7 +65,7 @@ static int omap3_rom_rng_get_random(void *buf, unsigned int count)
 
 	ptr = virt_to_phys(buf);
 	r = omap3_rom_rng_call(ptr, count, RNG_GEN_HW);
-	mod_timer(&idle_timer, jiffies + msecs_to_jiffies(500));
+	schedule_delayed_work(&idle_work, msecs_to_jiffies(500));
 	if (r != 0)
 		return -EINVAL;
 	return 0;
@@ -102,7 +102,7 @@ static int omap3_rom_rng_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	setup_timer(&idle_timer, omap3_rom_rng_idle, 0);
+	INIT_DELAYED_WORK(&idle_work, omap3_rom_rng_idle);
 	rng_clk = devm_clk_get(&pdev->dev, "ick");
 	if (IS_ERR(rng_clk)) {
 		pr_err("unable to get RNG clock\n");
@@ -118,6 +118,7 @@ static int omap3_rom_rng_probe(struct platform_device *pdev)
 
 static int omap3_rom_rng_remove(struct platform_device *pdev)
 {
+	cancel_delayed_work_sync(&idle_work);
 	hwrng_unregister(&omap3_rom_rng_ops);
 	clk_disable_unprepare(rng_clk);
 	return 0;
-- 
2.4.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] hw_random: omap3-rom-rng: convert timer to delayed work
  2015-11-05 22:15 [PATCH] hw_random: omap3-rom-rng: convert timer to delayed work Aaro Koskinen
@ 2015-11-06 19:20 ` Grygorii Strashko
  2015-11-17 13:36 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Grygorii Strashko @ 2015-11-06 19:20 UTC (permalink / raw)
  To: Aaro Koskinen, Matt Mackall, Herbert Xu, linux-crypto,
	Sebastian Reichel, Pali Rohár, linux-omap

On 11/06/2015 12:15 AM, Aaro Koskinen wrote:
> We cannot put the HW RNG to idle using a timer because we cannot disable
> clocks from atomic context. Use a delayed work instead.
>
> Fixes a warning with CONFIG_DEBUG_MUTEXES on Nokia N900 during boot.
>
> Reported-by: Sebastian Reichel <sre@kernel.org>
> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
> ---
>   drivers/char/hw_random/omap3-rom-rng.c | 11 ++++++-----
>   1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/char/hw_random/omap3-rom-rng.c b/drivers/char/hw_random/omap3-rom-rng.c
> index a405cdc..58191c6 100644
> --- a/drivers/char/hw_random/omap3-rom-rng.c
> +++ b/drivers/char/hw_random/omap3-rom-rng.c
> @@ -29,11 +29,11 @@
>   /* param1: ptr, param2: count, param3: flag */
>   static u32 (*omap3_rom_rng_call)(u32, u32, u32);
>
> -static struct timer_list idle_timer;
> +static struct delayed_work idle_work;
>   static int rng_idle;
>   static struct clk *rng_clk;
>
> -static void omap3_rom_rng_idle(unsigned long data)
> +static void omap3_rom_rng_idle(struct work_struct *work)
>   {
>   	int r;
>
> @@ -51,7 +51,7 @@ static int omap3_rom_rng_get_random(void *buf, unsigned int count)
>   	u32 r;
>   	u32 ptr;
>
> -	del_timer_sync(&idle_timer);
> +	cancel_delayed_work_sync(&idle_work);
>   	if (rng_idle) {
>   		clk_prepare_enable(rng_clk);
>   		r = omap3_rom_rng_call(0, 0, RNG_GEN_PRNG_HW_INIT);
> @@ -65,7 +65,7 @@ static int omap3_rom_rng_get_random(void *buf, unsigned int count)
>
>   	ptr = virt_to_phys(buf);
>   	r = omap3_rom_rng_call(ptr, count, RNG_GEN_HW);
> -	mod_timer(&idle_timer, jiffies + msecs_to_jiffies(500));
> +	schedule_delayed_work(&idle_work, msecs_to_jiffies(500));
>   	if (r != 0)
>   		return -EINVAL;
>   	return 0;
> @@ -102,7 +102,7 @@ static int omap3_rom_rng_probe(struct platform_device *pdev)
>   		return -EINVAL;
>   	}
>
> -	setup_timer(&idle_timer, omap3_rom_rng_idle, 0);
> +	INIT_DELAYED_WORK(&idle_work, omap3_rom_rng_idle);
>   	rng_clk = devm_clk_get(&pdev->dev, "ick");
>   	if (IS_ERR(rng_clk)) {
>   		pr_err("unable to get RNG clock\n");
> @@ -118,6 +118,7 @@ static int omap3_rom_rng_probe(struct platform_device *pdev)
>
>   static int omap3_rom_rng_remove(struct platform_device *pdev)
>   {
> +	cancel_delayed_work_sync(&idle_work);
>   	hwrng_unregister(&omap3_rom_rng_ops);
>   	clk_disable_unprepare(rng_clk);
>   	return 0;
>

Sry, It looks like PM runtime autosuspend might work well here.
What do you think?

-- 
regards,
-grygorii

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hw_random: omap3-rom-rng: convert timer to delayed work
  2015-11-05 22:15 [PATCH] hw_random: omap3-rom-rng: convert timer to delayed work Aaro Koskinen
  2015-11-06 19:20 ` Grygorii Strashko
@ 2015-11-17 13:36 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2015-11-17 13:36 UTC (permalink / raw)
  To: Aaro Koskinen
  Cc: Matt Mackall, linux-crypto, Sebastian Reichel, Pali Rohár,
	linux-omap

On Fri, Nov 06, 2015 at 12:15:24AM +0200, Aaro Koskinen wrote:
> We cannot put the HW RNG to idle using a timer because we cannot disable
> clocks from atomic context. Use a delayed work instead.
> 
> Fixes a warning with CONFIG_DEBUG_MUTEXES on Nokia N900 during boot.
> 
> Reported-by: Sebastian Reichel <sre@kernel.org>
> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>

Thanks for the patch.  Can you please remove timer.h and include
workqueue.h instead?

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-17 13:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-05 22:15 [PATCH] hw_random: omap3-rom-rng: convert timer to delayed work Aaro Koskinen
2015-11-06 19:20 ` Grygorii Strashko
2015-11-17 13:36 ` Herbert Xu

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).