mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 11:11:45 -04:00
watchdog: Add Locking support
This patch fixes some potential multithreading issues, despite only allowing one process to open the /dev/watchdog device, we can still get called multiple times at the same time, since a program could be using thread, or could share the fd after a fork. This causes 2 potential problems: 1) watchdog_start / open do an unlocked test_n_set / test_n_clear, if these 2 race, the watchdog could be stopped while the active bit indicates it is running or visa versa. 2) Most watchdog_dev drivers probably assume that only one watchdog-op will get called at a time, this is not necessary true atm. Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
This commit is contained in:
parent
7a87982420
commit
f4e9c82f64
4 changed files with 29 additions and 0 deletions
|
|
@ -79,6 +79,7 @@ int watchdog_register_device(struct watchdog_device *wdd)
|
|||
* corrupted in a later stage then we expect a kernel panic!
|
||||
*/
|
||||
|
||||
mutex_init(&wdd->lock);
|
||||
id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KERNEL);
|
||||
if (id < 0)
|
||||
return id;
|
||||
|
|
|
|||
|
|
@ -63,6 +63,8 @@ static int watchdog_ping(struct watchdog_device *wddev)
|
|||
{
|
||||
int err = 0;
|
||||
|
||||
mutex_lock(&wddev->lock);
|
||||
|
||||
if (!watchdog_active(wddev))
|
||||
goto out_ping;
|
||||
|
||||
|
|
@ -72,6 +74,7 @@ static int watchdog_ping(struct watchdog_device *wddev)
|
|||
err = wddev->ops->start(wddev); /* restart watchdog */
|
||||
|
||||
out_ping:
|
||||
mutex_unlock(&wddev->lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -88,6 +91,8 @@ static int watchdog_start(struct watchdog_device *wddev)
|
|||
{
|
||||
int err = 0;
|
||||
|
||||
mutex_lock(&wddev->lock);
|
||||
|
||||
if (watchdog_active(wddev))
|
||||
goto out_start;
|
||||
|
||||
|
|
@ -96,6 +101,7 @@ static int watchdog_start(struct watchdog_device *wddev)
|
|||
set_bit(WDOG_ACTIVE, &wddev->status);
|
||||
|
||||
out_start:
|
||||
mutex_unlock(&wddev->lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -113,6 +119,8 @@ static int watchdog_stop(struct watchdog_device *wddev)
|
|||
{
|
||||
int err = 0;
|
||||
|
||||
mutex_lock(&wddev->lock);
|
||||
|
||||
if (!watchdog_active(wddev))
|
||||
goto out_stop;
|
||||
|
||||
|
|
@ -127,6 +135,7 @@ static int watchdog_stop(struct watchdog_device *wddev)
|
|||
clear_bit(WDOG_ACTIVE, &wddev->status);
|
||||
|
||||
out_stop:
|
||||
mutex_unlock(&wddev->lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -147,8 +156,11 @@ static int watchdog_get_status(struct watchdog_device *wddev,
|
|||
if (!wddev->ops->status)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
mutex_lock(&wddev->lock);
|
||||
|
||||
*status = wddev->ops->status(wddev);
|
||||
|
||||
mutex_unlock(&wddev->lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -171,8 +183,11 @@ static int watchdog_set_timeout(struct watchdog_device *wddev,
|
|||
(timeout < wddev->min_timeout || timeout > wddev->max_timeout))
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&wddev->lock);
|
||||
|
||||
err = wddev->ops->set_timeout(wddev, timeout);
|
||||
|
||||
mutex_unlock(&wddev->lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -193,8 +208,11 @@ static int watchdog_get_timeleft(struct watchdog_device *wddev,
|
|||
if (!wddev->ops->get_timeleft)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
mutex_lock(&wddev->lock);
|
||||
|
||||
*timeleft = wddev->ops->get_timeleft(wddev);
|
||||
|
||||
mutex_unlock(&wddev->lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -213,8 +231,11 @@ static int watchdog_ioctl_op(struct watchdog_device *wddev, unsigned int cmd,
|
|||
if (!wddev->ops->ioctl)
|
||||
return -ENOIOCTLCMD;
|
||||
|
||||
mutex_lock(&wddev->lock);
|
||||
|
||||
err = wddev->ops->ioctl(wddev, cmd, arg);
|
||||
|
||||
mutex_unlock(&wddev->lock);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue