mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 09:19:51 +00:00
watchdog: watchdog_dev: Use single variable name for struct watchdog_device
The current code uses 'wdd', wddev', and 'watchdog' as variable names for struct watchdog_device. This is confusing and makes it difficult to enhance the code. Replace it all with 'wdd'. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Cc: Timo Kokkonen <timo.kokkonen@offcode.fi> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
This commit is contained in:
parent
1e93594911
commit
bc794ac3b5
1 changed files with 75 additions and 76 deletions
|
@ -51,7 +51,7 @@ static struct watchdog_device *old_wdd;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* watchdog_ping: ping the watchdog.
|
* watchdog_ping: ping the watchdog.
|
||||||
* @wddev: the watchdog device to ping
|
* @wdd: the watchdog device to ping
|
||||||
*
|
*
|
||||||
* If the watchdog has no own ping operation then it needs to be
|
* If the watchdog has no own ping operation then it needs to be
|
||||||
* restarted via the start operation. This wrapper function does
|
* restarted via the start operation. This wrapper function does
|
||||||
|
@ -59,65 +59,65 @@ static struct watchdog_device *old_wdd;
|
||||||
* We only ping when the watchdog device is running.
|
* We only ping when the watchdog device is running.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int watchdog_ping(struct watchdog_device *wddev)
|
static int watchdog_ping(struct watchdog_device *wdd)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
mutex_lock(&wddev->lock);
|
mutex_lock(&wdd->lock);
|
||||||
|
|
||||||
if (test_bit(WDOG_UNREGISTERED, &wddev->status)) {
|
if (test_bit(WDOG_UNREGISTERED, &wdd->status)) {
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
goto out_ping;
|
goto out_ping;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!watchdog_active(wddev))
|
if (!watchdog_active(wdd))
|
||||||
goto out_ping;
|
goto out_ping;
|
||||||
|
|
||||||
if (wddev->ops->ping)
|
if (wdd->ops->ping)
|
||||||
err = wddev->ops->ping(wddev); /* ping the watchdog */
|
err = wdd->ops->ping(wdd); /* ping the watchdog */
|
||||||
else
|
else
|
||||||
err = wddev->ops->start(wddev); /* restart watchdog */
|
err = wdd->ops->start(wdd); /* restart watchdog */
|
||||||
|
|
||||||
out_ping:
|
out_ping:
|
||||||
mutex_unlock(&wddev->lock);
|
mutex_unlock(&wdd->lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* watchdog_start: wrapper to start the watchdog.
|
* watchdog_start: wrapper to start the watchdog.
|
||||||
* @wddev: the watchdog device to start
|
* @wdd: the watchdog device to start
|
||||||
*
|
*
|
||||||
* Start the watchdog if it is not active and mark it active.
|
* Start the watchdog if it is not active and mark it active.
|
||||||
* This function returns zero on success or a negative errno code for
|
* This function returns zero on success or a negative errno code for
|
||||||
* failure.
|
* failure.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int watchdog_start(struct watchdog_device *wddev)
|
static int watchdog_start(struct watchdog_device *wdd)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
mutex_lock(&wddev->lock);
|
mutex_lock(&wdd->lock);
|
||||||
|
|
||||||
if (test_bit(WDOG_UNREGISTERED, &wddev->status)) {
|
if (test_bit(WDOG_UNREGISTERED, &wdd->status)) {
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
goto out_start;
|
goto out_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (watchdog_active(wddev))
|
if (watchdog_active(wdd))
|
||||||
goto out_start;
|
goto out_start;
|
||||||
|
|
||||||
err = wddev->ops->start(wddev);
|
err = wdd->ops->start(wdd);
|
||||||
if (err == 0)
|
if (err == 0)
|
||||||
set_bit(WDOG_ACTIVE, &wddev->status);
|
set_bit(WDOG_ACTIVE, &wdd->status);
|
||||||
|
|
||||||
out_start:
|
out_start:
|
||||||
mutex_unlock(&wddev->lock);
|
mutex_unlock(&wdd->lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* watchdog_stop: wrapper to stop the watchdog.
|
* watchdog_stop: wrapper to stop the watchdog.
|
||||||
* @wddev: the watchdog device to stop
|
* @wdd: the watchdog device to stop
|
||||||
*
|
*
|
||||||
* Stop the watchdog if it is still active and unmark it active.
|
* Stop the watchdog if it is still active and unmark it active.
|
||||||
* This function returns zero on success or a negative errno code for
|
* This function returns zero on success or a negative errno code for
|
||||||
|
@ -125,155 +125,154 @@ static int watchdog_start(struct watchdog_device *wddev)
|
||||||
* If the 'nowayout' feature was set, the watchdog cannot be stopped.
|
* If the 'nowayout' feature was set, the watchdog cannot be stopped.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int watchdog_stop(struct watchdog_device *wddev)
|
static int watchdog_stop(struct watchdog_device *wdd)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
mutex_lock(&wddev->lock);
|
mutex_lock(&wdd->lock);
|
||||||
|
|
||||||
if (test_bit(WDOG_UNREGISTERED, &wddev->status)) {
|
if (test_bit(WDOG_UNREGISTERED, &wdd->status)) {
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
goto out_stop;
|
goto out_stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!watchdog_active(wddev))
|
if (!watchdog_active(wdd))
|
||||||
goto out_stop;
|
goto out_stop;
|
||||||
|
|
||||||
if (test_bit(WDOG_NO_WAY_OUT, &wddev->status)) {
|
if (test_bit(WDOG_NO_WAY_OUT, &wdd->status)) {
|
||||||
dev_info(wddev->dev, "nowayout prevents watchdog being stopped!\n");
|
dev_info(wdd->dev, "nowayout prevents watchdog being stopped!\n");
|
||||||
err = -EBUSY;
|
err = -EBUSY;
|
||||||
goto out_stop;
|
goto out_stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = wddev->ops->stop(wddev);
|
err = wdd->ops->stop(wdd);
|
||||||
if (err == 0)
|
if (err == 0)
|
||||||
clear_bit(WDOG_ACTIVE, &wddev->status);
|
clear_bit(WDOG_ACTIVE, &wdd->status);
|
||||||
|
|
||||||
out_stop:
|
out_stop:
|
||||||
mutex_unlock(&wddev->lock);
|
mutex_unlock(&wdd->lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* watchdog_get_status: wrapper to get the watchdog status
|
* watchdog_get_status: wrapper to get the watchdog status
|
||||||
* @wddev: the watchdog device to get the status from
|
* @wdd: the watchdog device to get the status from
|
||||||
* @status: the status of the watchdog device
|
* @status: the status of the watchdog device
|
||||||
*
|
*
|
||||||
* Get the watchdog's status flags.
|
* Get the watchdog's status flags.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int watchdog_get_status(struct watchdog_device *wddev,
|
static int watchdog_get_status(struct watchdog_device *wdd,
|
||||||
unsigned int *status)
|
unsigned int *status)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
*status = 0;
|
*status = 0;
|
||||||
if (!wddev->ops->status)
|
if (!wdd->ops->status)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
mutex_lock(&wddev->lock);
|
mutex_lock(&wdd->lock);
|
||||||
|
|
||||||
if (test_bit(WDOG_UNREGISTERED, &wddev->status)) {
|
if (test_bit(WDOG_UNREGISTERED, &wdd->status)) {
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
goto out_status;
|
goto out_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
*status = wddev->ops->status(wddev);
|
*status = wdd->ops->status(wdd);
|
||||||
|
|
||||||
out_status:
|
out_status:
|
||||||
mutex_unlock(&wddev->lock);
|
mutex_unlock(&wdd->lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* watchdog_set_timeout: set the watchdog timer timeout
|
* watchdog_set_timeout: set the watchdog timer timeout
|
||||||
* @wddev: the watchdog device to set the timeout for
|
* @wdd: the watchdog device to set the timeout for
|
||||||
* @timeout: timeout to set in seconds
|
* @timeout: timeout to set in seconds
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int watchdog_set_timeout(struct watchdog_device *wddev,
|
static int watchdog_set_timeout(struct watchdog_device *wdd,
|
||||||
unsigned int timeout)
|
unsigned int timeout)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if ((wddev->ops->set_timeout == NULL) ||
|
if (!wdd->ops->set_timeout || !(wdd->info->options & WDIOF_SETTIMEOUT))
|
||||||
!(wddev->info->options & WDIOF_SETTIMEOUT))
|
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
if (watchdog_timeout_invalid(wddev, timeout))
|
if (watchdog_timeout_invalid(wdd, timeout))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
mutex_lock(&wddev->lock);
|
mutex_lock(&wdd->lock);
|
||||||
|
|
||||||
if (test_bit(WDOG_UNREGISTERED, &wddev->status)) {
|
if (test_bit(WDOG_UNREGISTERED, &wdd->status)) {
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
goto out_timeout;
|
goto out_timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = wddev->ops->set_timeout(wddev, timeout);
|
err = wdd->ops->set_timeout(wdd, timeout);
|
||||||
|
|
||||||
out_timeout:
|
out_timeout:
|
||||||
mutex_unlock(&wddev->lock);
|
mutex_unlock(&wdd->lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* watchdog_get_timeleft: wrapper to get the time left before a reboot
|
* watchdog_get_timeleft: wrapper to get the time left before a reboot
|
||||||
* @wddev: the watchdog device to get the remaining time from
|
* @wdd: the watchdog device to get the remaining time from
|
||||||
* @timeleft: the time that's left
|
* @timeleft: the time that's left
|
||||||
*
|
*
|
||||||
* Get the time before a watchdog will reboot (if not pinged).
|
* Get the time before a watchdog will reboot (if not pinged).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int watchdog_get_timeleft(struct watchdog_device *wddev,
|
static int watchdog_get_timeleft(struct watchdog_device *wdd,
|
||||||
unsigned int *timeleft)
|
unsigned int *timeleft)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
*timeleft = 0;
|
*timeleft = 0;
|
||||||
if (!wddev->ops->get_timeleft)
|
if (!wdd->ops->get_timeleft)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
mutex_lock(&wddev->lock);
|
mutex_lock(&wdd->lock);
|
||||||
|
|
||||||
if (test_bit(WDOG_UNREGISTERED, &wddev->status)) {
|
if (test_bit(WDOG_UNREGISTERED, &wdd->status)) {
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
goto out_timeleft;
|
goto out_timeleft;
|
||||||
}
|
}
|
||||||
|
|
||||||
*timeleft = wddev->ops->get_timeleft(wddev);
|
*timeleft = wdd->ops->get_timeleft(wdd);
|
||||||
|
|
||||||
out_timeleft:
|
out_timeleft:
|
||||||
mutex_unlock(&wddev->lock);
|
mutex_unlock(&wdd->lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* watchdog_ioctl_op: call the watchdog drivers ioctl op if defined
|
* watchdog_ioctl_op: call the watchdog drivers ioctl op if defined
|
||||||
* @wddev: the watchdog device to do the ioctl on
|
* @wdd: the watchdog device to do the ioctl on
|
||||||
* @cmd: watchdog command
|
* @cmd: watchdog command
|
||||||
* @arg: argument pointer
|
* @arg: argument pointer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int watchdog_ioctl_op(struct watchdog_device *wddev, unsigned int cmd,
|
static int watchdog_ioctl_op(struct watchdog_device *wdd, unsigned int cmd,
|
||||||
unsigned long arg)
|
unsigned long arg)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!wddev->ops->ioctl)
|
if (!wdd->ops->ioctl)
|
||||||
return -ENOIOCTLCMD;
|
return -ENOIOCTLCMD;
|
||||||
|
|
||||||
mutex_lock(&wddev->lock);
|
mutex_lock(&wdd->lock);
|
||||||
|
|
||||||
if (test_bit(WDOG_UNREGISTERED, &wddev->status)) {
|
if (test_bit(WDOG_UNREGISTERED, &wdd->status)) {
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
goto out_ioctl;
|
goto out_ioctl;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = wddev->ops->ioctl(wddev, cmd, arg);
|
err = wdd->ops->ioctl(wdd, cmd, arg);
|
||||||
|
|
||||||
out_ioctl:
|
out_ioctl:
|
||||||
mutex_unlock(&wddev->lock);
|
mutex_unlock(&wdd->lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,43 +512,43 @@ static struct miscdevice watchdog_miscdev = {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* watchdog_dev_register: register a watchdog device
|
* watchdog_dev_register: register a watchdog device
|
||||||
* @watchdog: watchdog device
|
* @wdd: watchdog device
|
||||||
*
|
*
|
||||||
* Register a watchdog device including handling the legacy
|
* Register a watchdog device including handling the legacy
|
||||||
* /dev/watchdog node. /dev/watchdog is actually a miscdevice and
|
* /dev/watchdog node. /dev/watchdog is actually a miscdevice and
|
||||||
* thus we set it up like that.
|
* thus we set it up like that.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int watchdog_dev_register(struct watchdog_device *watchdog)
|
int watchdog_dev_register(struct watchdog_device *wdd)
|
||||||
{
|
{
|
||||||
int err, devno;
|
int err, devno;
|
||||||
|
|
||||||
if (watchdog->id == 0) {
|
if (wdd->id == 0) {
|
||||||
old_wdd = watchdog;
|
old_wdd = wdd;
|
||||||
watchdog_miscdev.parent = watchdog->parent;
|
watchdog_miscdev.parent = wdd->parent;
|
||||||
err = misc_register(&watchdog_miscdev);
|
err = misc_register(&watchdog_miscdev);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
pr_err("%s: cannot register miscdev on minor=%d (err=%d).\n",
|
pr_err("%s: cannot register miscdev on minor=%d (err=%d).\n",
|
||||||
watchdog->info->identity, WATCHDOG_MINOR, err);
|
wdd->info->identity, WATCHDOG_MINOR, err);
|
||||||
if (err == -EBUSY)
|
if (err == -EBUSY)
|
||||||
pr_err("%s: a legacy watchdog module is probably present.\n",
|
pr_err("%s: a legacy watchdog module is probably present.\n",
|
||||||
watchdog->info->identity);
|
wdd->info->identity);
|
||||||
old_wdd = NULL;
|
old_wdd = NULL;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fill in the data structures */
|
/* Fill in the data structures */
|
||||||
devno = MKDEV(MAJOR(watchdog_devt), watchdog->id);
|
devno = MKDEV(MAJOR(watchdog_devt), wdd->id);
|
||||||
cdev_init(&watchdog->cdev, &watchdog_fops);
|
cdev_init(&wdd->cdev, &watchdog_fops);
|
||||||
watchdog->cdev.owner = watchdog->ops->owner;
|
wdd->cdev.owner = wdd->ops->owner;
|
||||||
|
|
||||||
/* Add the device */
|
/* Add the device */
|
||||||
err = cdev_add(&watchdog->cdev, devno, 1);
|
err = cdev_add(&wdd->cdev, devno, 1);
|
||||||
if (err) {
|
if (err) {
|
||||||
pr_err("watchdog%d unable to add device %d:%d\n",
|
pr_err("watchdog%d unable to add device %d:%d\n",
|
||||||
watchdog->id, MAJOR(watchdog_devt), watchdog->id);
|
wdd->id, MAJOR(watchdog_devt), wdd->id);
|
||||||
if (watchdog->id == 0) {
|
if (wdd->id == 0) {
|
||||||
misc_deregister(&watchdog_miscdev);
|
misc_deregister(&watchdog_miscdev);
|
||||||
old_wdd = NULL;
|
old_wdd = NULL;
|
||||||
}
|
}
|
||||||
|
@ -564,14 +563,14 @@ int watchdog_dev_register(struct watchdog_device *watchdog)
|
||||||
* Unregister the watchdog and if needed the legacy /dev/watchdog device.
|
* Unregister the watchdog and if needed the legacy /dev/watchdog device.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int watchdog_dev_unregister(struct watchdog_device *watchdog)
|
int watchdog_dev_unregister(struct watchdog_device *wdd)
|
||||||
{
|
{
|
||||||
mutex_lock(&watchdog->lock);
|
mutex_lock(&wdd->lock);
|
||||||
set_bit(WDOG_UNREGISTERED, &watchdog->status);
|
set_bit(WDOG_UNREGISTERED, &wdd->status);
|
||||||
mutex_unlock(&watchdog->lock);
|
mutex_unlock(&wdd->lock);
|
||||||
|
|
||||||
cdev_del(&watchdog->cdev);
|
cdev_del(&wdd->cdev);
|
||||||
if (watchdog->id == 0) {
|
if (wdd->id == 0) {
|
||||||
misc_deregister(&watchdog_miscdev);
|
misc_deregister(&watchdog_miscdev);
|
||||||
old_wdd = NULL;
|
old_wdd = NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue