linux-rtc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] rtc-r7301: Fix a possible sleep-in-atomic bug in rtc7301_read_time
@ 2017-12-13 13:55 Jia-Ju Bai
  2017-12-18 22:24 ` Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2017-12-13 13:55 UTC (permalink / raw)
  To: akinobu.mita, a.zummo, alexandre.belloni
  Cc: linux-rtc, linux-kernel, Jia-Ju Bai

The driver may sleep under a spinlock.
The function call path is:
rtc7301_read_time (acquire the spinlock)
  rtc7301_wait_while_busy 
    usleep_range --> may sleep

To fix it, usleep_range is replaced with udelay.

This bug is found by my static analysis tool(DSAC) and checked by my code review.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/rtc/rtc-r7301.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-r7301.c b/drivers/rtc/rtc-r7301.c
index 28d5408..d846e97 100644
--- a/drivers/rtc/rtc-r7301.c
+++ b/drivers/rtc/rtc-r7301.c
@@ -95,7 +95,7 @@ static int rtc7301_wait_while_busy(struct rtc7301_priv *priv)
 		if (!(val & RTC7301_CONTROL_BUSY))
 			return 0;
 
-		usleep_range(200, 300);
+		udelay(300);
 	}
 
 	return -ETIMEDOUT;
-- 
1.7.9.5

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

* Re: [PATCH 1/2] rtc-r7301: Fix a possible sleep-in-atomic bug in rtc7301_read_time
  2017-12-13 13:55 [PATCH 1/2] rtc-r7301: Fix a possible sleep-in-atomic bug in rtc7301_read_time Jia-Ju Bai
@ 2017-12-18 22:24 ` Alexandre Belloni
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Belloni @ 2017-12-18 22:24 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: akinobu.mita, a.zummo, linux-rtc, linux-kernel

On 13/12/2017 at 21:55:50 +0800, Jia-Ju Bai wrote:
> The driver may sleep under a spinlock.
> The function call path is:
> rtc7301_read_time (acquire the spinlock)
>   rtc7301_wait_while_busy 
>     usleep_range --> may sleep
> 
> To fix it, usleep_range is replaced with udelay.
> 
> This bug is found by my static analysis tool(DSAC) and checked by my code review.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  drivers/rtc/rtc-r7301.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
Applied, thanks.

-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

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

end of thread, other threads:[~2017-12-18 22:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-13 13:55 [PATCH 1/2] rtc-r7301: Fix a possible sleep-in-atomic bug in rtc7301_read_time Jia-Ju Bai
2017-12-18 22:24 ` Alexandre Belloni

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