[PATCH 5/5] watchdog: dw_wdt: unqueue timer synchronously on unexpected close

From: Ian Abbott
Date: Fri Jun 26 2015 - 09:22:18 EST


The driver normally calls the timer function `dw_wdt_ping()` every half
a second to pat the dog while it is not in use, and while waiting for
the next heartbeat from the user that opened the device. If the
watchdog device's "release" file operation determines that the watchdog
device is being closed unexpectedly, it calls `del_timer()` to remove
the timer from the queue and thus stop patting the dog. However, since
the timer function re-queues the timer, there is a race condition on SMP
systems which could leave the timer re-queueing itself when it
shouldn't. To prevent that, call `del_timer_sync()` instead of
`del_timer()`.

Signed-off-by: Ian Abbott <abbotti@xxxxxxxxx>
---
drivers/watchdog/dw_wdt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index daab90b..bf617e3 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -281,7 +281,7 @@ static int dw_wdt_release(struct inode *inode, struct file *filp)
clear_bit(DW_WDT_IN_USE, &dw_wdt.state);

if (!dw_wdt.expect_close) {
- del_timer(&dw_wdt.timer);
+ del_timer_sync(&dw_wdt.timer);

if (!nowayout)
pr_crit("unexpected close, system will reboot soon\n");
--
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/