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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 24 Mar 2018 10:00:24 +0000 (11:00 +0100)
commit6ad31f858328e0c4257c3b0367271d7e99d16af2
treeb4016a55e00f180a2a2b2da525810fdd870a1cfc
parent32dc29cf72e866fafca3a12ea821954632a0edca
watchdog: Fix potential kref imbalance when opening watchdog

[ Upstream commit 4bcd615fad6adddc68b058d498b30a9e0e0db77a ]

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>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/watchdog/watchdog_dev.c