aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/watchdog/softdog.c
diff options
context:
space:
mode:
authorChuck Ebbert <76306.1226@compuserve.com>2005-08-19 08:14:07 -0400
committerWim Van Sebroeck <wim@iguana.be>2005-09-03 07:59:46 -0400
commit1cc77248106aafc12ba529953f652d6f8db2c84d (patch)
tree6e5f8ee1053e7add2ec1890b594dc4086ae39f09 /drivers/char/watchdog/softdog.c
parent93642ecd463df30d032da8ac37c2676cee4ad876 (diff)
[WATCHDOG] softdog-timer-running-oops.patch
The softdog watchdog timer has a bug that can create an oops: 1. Load the module without the nowayout option. 2. Open the driver and close it without writing 'V' before close. 3. Unload the module. The timer will continue to run... 4. Oops happens when timer fires. Reported Sun, 10 Oct 2004, by Michael Schierl <schierlm@gmx.de> Fix is easy: always take a reference on the module on open. Release it only when the device is closed and no timer is running. Tested on 2.6.13-rc6 using the soft_noboot option. While the timer is running and the device is closed, the module use count stays at 1. After the timer fires, it drops to 0. Repeatedly opening and closing the driver caused no problems. Please apply. Signed-off-by: Chuck Ebbert <76306.1226@compuserve.com> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers/char/watchdog/softdog.c')
-rw-r--r--drivers/char/watchdog/softdog.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/char/watchdog/softdog.c b/drivers/char/watchdog/softdog.c
index 4d7ed931f5c6..20e5eb8667f2 100644
--- a/drivers/char/watchdog/softdog.c
+++ b/drivers/char/watchdog/softdog.c
@@ -77,7 +77,7 @@ static void watchdog_fire(unsigned long);
77 77
78static struct timer_list watchdog_ticktock = 78static struct timer_list watchdog_ticktock =
79 TIMER_INITIALIZER(watchdog_fire, 0, 0); 79 TIMER_INITIALIZER(watchdog_fire, 0, 0);
80static unsigned long timer_alive; 80static unsigned long driver_open, orphan_timer;
81static char expect_close; 81static char expect_close;
82 82
83 83
@@ -87,6 +87,9 @@ static char expect_close;
87 87
88static void watchdog_fire(unsigned long data) 88static void watchdog_fire(unsigned long data)
89{ 89{
90 if (test_and_clear_bit(0, &orphan_timer))
91 module_put(THIS_MODULE);
92
90 if (soft_noboot) 93 if (soft_noboot)
91 printk(KERN_CRIT PFX "Triggered - Reboot ignored.\n"); 94 printk(KERN_CRIT PFX "Triggered - Reboot ignored.\n");
92 else 95 else
@@ -128,9 +131,9 @@ static int softdog_set_heartbeat(int t)
128 131
129static int softdog_open(struct inode *inode, struct file *file) 132static int softdog_open(struct inode *inode, struct file *file)
130{ 133{
131 if(test_and_set_bit(0, &timer_alive)) 134 if (test_and_set_bit(0, &driver_open))
132 return -EBUSY; 135 return -EBUSY;
133 if (nowayout) 136 if (!test_and_clear_bit(0, &orphan_timer))
134 __module_get(THIS_MODULE); 137 __module_get(THIS_MODULE);
135 /* 138 /*
136 * Activate timer 139 * Activate timer
@@ -147,11 +150,13 @@ static int softdog_release(struct inode *inode, struct file *file)
147 */ 150 */
148 if (expect_close == 42) { 151 if (expect_close == 42) {
149 softdog_stop(); 152 softdog_stop();
153 module_put(THIS_MODULE);
150 } else { 154 } else {
151 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); 155 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
156 set_bit(0, &orphan_timer);
152 softdog_keepalive(); 157 softdog_keepalive();
153 } 158 }
154 clear_bit(0, &timer_alive); 159 clear_bit(0, &driver_open);
155 expect_close = 0; 160 expect_close = 0;
156 return 0; 161 return 0;
157} 162}