Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

watchdog: diag288: Stop re-using watchdog core internal flags

A watchdog driver should not use watchdog subsystem internal flags.
Use a driver variable and flag instead to maintain the watchdog state
and to determine if a suspend operation is possible or not.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>

authored by

Guenter Roeck and committed by
Wim Van Sebroeck
e7d162fa 32ecc639

+16 -10
+16 -10
drivers/watchdog/diag288_wdt.c
··· 106 106 return __diag288(func, timeout, action, 0); 107 107 } 108 108 109 + static unsigned long wdt_status; 110 + 111 + #define DIAG_WDOG_BUSY 0 112 + 109 113 static int wdt_start(struct watchdog_device *dev) 110 114 { 111 115 char *ebc_cmd; ··· 117 113 int ret; 118 114 unsigned int func; 119 115 116 + if (test_and_set_bit(DIAG_WDOG_BUSY, &wdt_status)) 117 + return -EBUSY; 118 + 120 119 ret = -ENODEV; 121 120 122 121 if (MACHINE_IS_VM) { 123 122 ebc_cmd = kmalloc(MAX_CMDLEN, GFP_KERNEL); 124 - if (!ebc_cmd) 123 + if (!ebc_cmd) { 124 + clear_bit(DIAG_WDOG_BUSY, &wdt_status); 125 125 return -ENOMEM; 126 + } 126 127 len = strlcpy(ebc_cmd, wdt_cmd, MAX_CMDLEN); 127 128 ASCEBC(ebc_cmd, MAX_CMDLEN); 128 129 EBC_TOUPPER(ebc_cmd, MAX_CMDLEN); ··· 144 135 145 136 if (ret) { 146 137 pr_err("The watchdog cannot be activated\n"); 138 + clear_bit(DIAG_WDOG_BUSY, &wdt_status); 147 139 return ret; 148 140 } 149 141 return 0; ··· 156 146 157 147 diag_stat_inc(DIAG_STAT_X288); 158 148 ret = __diag288(WDT_FUNC_CANCEL, 0, 0, 0); 149 + 150 + clear_bit(DIAG_WDOG_BUSY, &wdt_status); 151 + 159 152 return ret; 160 153 } 161 154 ··· 233 220 * It makes no sense to go into suspend while the watchdog is running. 234 221 * Depending on the memory size, the watchdog might trigger, while we 235 222 * are still saving the memory. 236 - * We reuse the open flag to ensure that suspend and watchdog open are 237 - * exclusive operations 238 223 */ 239 224 static int wdt_suspend(void) 240 225 { 241 - if (test_and_set_bit(WDOG_DEV_OPEN, &wdt_dev.status)) { 242 - pr_err("Linux cannot be suspended while the watchdog is in use\n"); 243 - return notifier_from_errno(-EBUSY); 244 - } 245 - if (test_bit(WDOG_ACTIVE, &wdt_dev.status)) { 246 - clear_bit(WDOG_DEV_OPEN, &wdt_dev.status); 226 + if (test_and_set_bit(DIAG_WDOG_BUSY, &wdt_status)) { 247 227 pr_err("Linux cannot be suspended while the watchdog is in use\n"); 248 228 return notifier_from_errno(-EBUSY); 249 229 } ··· 245 239 246 240 static int wdt_resume(void) 247 241 { 248 - clear_bit(WDOG_DEV_OPEN, &wdt_dev.status); 242 + clear_bit(DIAG_WDOG_BUSY, &wdt_status); 249 243 return NOTIFY_DONE; 250 244 } 251 245