watchdog: Fix potential kref imbalance when opening watchdog
authorGuenter Roeck <linux@roeck-us.net>
Mon, 25 Sep 2017 16:17:01 +0000 (09:17 -0700)
committerWim Van Sebroeck <wim@iguana.be>
Sun, 17 Dec 2017 10:01:47 +0000 (11:01 +0100)
commit4bcd615fad6adddc68b058d498b30a9e0e0db77a
tree2147795c91515080182841b24959a0416bcae594
parentf3b5ad89de16f5d42e8ad36fbdf85f705c1ae051
watchdog: Fix potential kref imbalance when opening watchdog

If a watchdog driver's open function sets WDOG_HW_RUNNING with the
expectation that the watchdog can not be stopped, but then stops the
watchdog anyway in its stop function, kref_get() wil not be called in
watchdog_open(). If the watchdog then stops on close, WDOG_HW_RUNNING
will be cleared and kref_put() will be called, causing a kref imbalance.
As result the character device data structure will be released, which in
turn will cause the system to crash on the next call to watchdog_open().

Fixes: ee142889e32f5 ("watchdog: Introduce WDOG_HW_RUNNING flag")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
drivers/watchdog/watchdog_dev.c