diff mbox series

[2/2] rtc-r7301: Fix a possible sleep-in-atomic bug in rtc7301_set_time

Message ID 1513173364-18424-1-git-send-email-baijiaju1990@gmail.com
State Accepted
Headers show
Series [1/2] rtc-r7301: Fix a possible sleep-in-atomic bug in rtc7301_read_time | expand

Commit Message

Jia-Ju Bai Dec. 13, 2017, 1:56 p.m. UTC
The driver may sleep under a spinlock.
The function call path is:
rtc7301_set_time (acquire the spinlock)
  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(-)

Comments

Alexandre Belloni Dec. 18, 2017, 10:24 p.m. UTC | #1
On 13/12/2017 at 21:56:04 +0800, Jia-Ju Bai wrote:
> The driver may sleep under a spinlock.
> The function call path is:
> rtc7301_set_time (acquire the spinlock)
>   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.
diff mbox series

Patch

diff --git a/drivers/rtc/rtc-r7301.c b/drivers/rtc/rtc-r7301.c
index 28d5408..a040536 100644
--- a/drivers/rtc/rtc-r7301.c
+++ b/drivers/rtc/rtc-r7301.c
@@ -235,7 +235,7 @@  static int rtc7301_set_time(struct device *dev, struct rtc_time *tm)
 	spin_lock_irqsave(&priv->lock, flags);
 
 	rtc7301_stop(priv);
-	usleep_range(200, 300);
+	udelay(300);
 	rtc7301_select_bank(priv, 0);
 	rtc7301_write_time(priv, tm, false);
 	rtc7301_start(priv);