Commit 0254e953 authored by Guenter Roeck's avatar Guenter Roeck Committed by Wim Van Sebroeck

watchdog: Drop pointer to watchdog device from struct watchdog_device

The lifetime of the watchdog device pointer is different from the lifetime
of its character device. Remove it entirely to avoid race conditions.
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent 2c2f3080
...@@ -44,7 +44,6 @@ The watchdog device structure looks like this: ...@@ -44,7 +44,6 @@ The watchdog device structure looks like this:
struct watchdog_device { struct watchdog_device {
int id; int id;
struct device *dev;
struct device *parent; struct device *parent;
const struct attribute_group **groups; const struct attribute_group **groups;
const struct watchdog_info *info; const struct watchdog_info *info;
...@@ -66,7 +65,6 @@ It contains following fields: ...@@ -66,7 +65,6 @@ It contains following fields:
/dev/watchdog0 cdev (dynamic major, minor 0) as well as the old /dev/watchdog0 cdev (dynamic major, minor 0) as well as the old
/dev/watchdog miscdev. The id is set automatically when calling /dev/watchdog miscdev. The id is set automatically when calling
watchdog_register_device. watchdog_register_device.
* dev: device under the watchdog class (created by watchdog_register_device).
* parent: set this to the parent device (or NULL) before calling * parent: set this to the parent device (or NULL) before calling
watchdog_register_device. watchdog_register_device.
* groups: List of sysfs attribute groups to create when creating the watchdog * groups: List of sysfs attribute groups to create when creating the watchdog
......
...@@ -249,8 +249,8 @@ static int __watchdog_register_device(struct watchdog_device *wdd) ...@@ -249,8 +249,8 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
ret = register_reboot_notifier(&wdd->reboot_nb); ret = register_reboot_notifier(&wdd->reboot_nb);
if (ret) { if (ret) {
dev_err(wdd->dev, "Cannot register reboot notifier (%d)\n", pr_err("watchdog%d: Cannot register reboot notifier (%d)\n",
ret); wdd->id, ret);
watchdog_dev_unregister(wdd); watchdog_dev_unregister(wdd);
ida_simple_remove(&watchdog_ida, wdd->id); ida_simple_remove(&watchdog_ida, wdd->id);
return ret; return ret;
...@@ -262,8 +262,8 @@ static int __watchdog_register_device(struct watchdog_device *wdd) ...@@ -262,8 +262,8 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
ret = register_restart_handler(&wdd->restart_nb); ret = register_restart_handler(&wdd->restart_nb);
if (ret) if (ret)
dev_warn(wdd->dev, "Cannot register restart handler (%d)\n", pr_warn("watchog%d: Cannot register restart handler (%d)\n",
ret); wdd->id, ret);
} }
return 0; return 0;
......
...@@ -143,7 +143,8 @@ static int watchdog_stop(struct watchdog_device *wdd) ...@@ -143,7 +143,8 @@ static int watchdog_stop(struct watchdog_device *wdd)
return 0; return 0;
if (test_bit(WDOG_NO_WAY_OUT, &wdd->status)) { if (test_bit(WDOG_NO_WAY_OUT, &wdd->status)) {
dev_info(wdd->dev, "nowayout prevents watchdog being stopped!\n"); pr_info("watchdog%d: nowayout prevents watchdog being stopped!\n",
wdd->id);
return -EBUSY; return -EBUSY;
} }
...@@ -604,7 +605,7 @@ static int watchdog_release(struct inode *inode, struct file *file) ...@@ -604,7 +605,7 @@ static int watchdog_release(struct inode *inode, struct file *file)
/* If the watchdog was not stopped, send a keepalive ping */ /* If the watchdog was not stopped, send a keepalive ping */
if (err < 0) { if (err < 0) {
dev_crit(wdd->dev, "watchdog did not stop!\n"); pr_crit("watchdog%d: watchdog did not stop!\n", wdd->id);
watchdog_ping(wdd); watchdog_ping(wdd);
} }
...@@ -751,7 +752,6 @@ int watchdog_dev_register(struct watchdog_device *wdd) ...@@ -751,7 +752,6 @@ int watchdog_dev_register(struct watchdog_device *wdd)
watchdog_cdev_unregister(wdd); watchdog_cdev_unregister(wdd);
return PTR_ERR(dev); return PTR_ERR(dev);
} }
wdd->dev = dev;
return ret; return ret;
} }
...@@ -766,8 +766,7 @@ int watchdog_dev_register(struct watchdog_device *wdd) ...@@ -766,8 +766,7 @@ int watchdog_dev_register(struct watchdog_device *wdd)
void watchdog_dev_unregister(struct watchdog_device *wdd) void watchdog_dev_unregister(struct watchdog_device *wdd)
{ {
device_destroy(&watchdog_class, wdd->dev->devt); device_destroy(&watchdog_class, wdd->wd_data->cdev.dev);
wdd->dev = NULL;
watchdog_cdev_unregister(wdd); watchdog_cdev_unregister(wdd);
} }
......
...@@ -53,7 +53,6 @@ struct watchdog_ops { ...@@ -53,7 +53,6 @@ struct watchdog_ops {
/** struct watchdog_device - The structure that defines a watchdog device /** struct watchdog_device - The structure that defines a watchdog device
* *
* @id: The watchdog's ID. (Allocated by watchdog_register_device) * @id: The watchdog's ID. (Allocated by watchdog_register_device)
* @dev: The device for our watchdog
* @parent: The parent bus device * @parent: The parent bus device
* @groups: List of sysfs attribute groups to create when creating the * @groups: List of sysfs attribute groups to create when creating the
* watchdog device. * watchdog device.
...@@ -82,7 +81,6 @@ struct watchdog_ops { ...@@ -82,7 +81,6 @@ struct watchdog_ops {
*/ */
struct watchdog_device { struct watchdog_device {
int id; int id;
struct device *dev;
struct device *parent; struct device *parent;
const struct attribute_group **groups; const struct attribute_group **groups;
const struct watchdog_info *info; const struct watchdog_info *info;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment