009-7-watchdog-Drop-pointer-to-watchdog-device-from-struct-watchdog_device.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. From 0254e953537c92df3e7d0176f401a211e944fd61 Mon Sep 17 00:00:00 2001
  2. From: Guenter Roeck <linux@roeck-us.net>
  3. Date: Sun, 3 Jan 2016 15:11:58 -0800
  4. Subject: watchdog: Drop pointer to watchdog device from struct watchdog_device
  5. The lifetime of the watchdog device pointer is different from the lifetime
  6. of its character device. Remove it entirely to avoid race conditions.
  7. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  8. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  9. Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
  10. ---
  11. Documentation/watchdog/watchdog-kernel-api.txt | 2 --
  12. drivers/watchdog/watchdog_core.c | 8 ++++----
  13. drivers/watchdog/watchdog_dev.c | 9 ++++-----
  14. include/linux/watchdog.h | 2 --
  15. 4 files changed, 8 insertions(+), 13 deletions(-)
  16. --- a/Documentation/watchdog/watchdog-kernel-api.txt
  17. +++ b/Documentation/watchdog/watchdog-kernel-api.txt
  18. @@ -44,7 +44,6 @@ The watchdog device structure looks like
  19. struct watchdog_device {
  20. int id;
  21. - struct device *dev;
  22. struct device *parent;
  23. const struct watchdog_info *info;
  24. const struct watchdog_ops *ops;
  25. @@ -65,7 +64,6 @@ It contains following fields:
  26. /dev/watchdog0 cdev (dynamic major, minor 0) as well as the old
  27. /dev/watchdog miscdev. The id is set automatically when calling
  28. watchdog_register_device.
  29. -* dev: device under the watchdog class (created by watchdog_register_device).
  30. * parent: set this to the parent device (or NULL) before calling
  31. watchdog_register_device.
  32. * info: a pointer to a watchdog_info structure. This structure gives some
  33. --- a/drivers/watchdog/watchdog_core.c
  34. +++ b/drivers/watchdog/watchdog_core.c
  35. @@ -249,8 +249,8 @@ static int __watchdog_register_device(st
  36. ret = register_reboot_notifier(&wdd->reboot_nb);
  37. if (ret) {
  38. - dev_err(wdd->dev, "Cannot register reboot notifier (%d)\n",
  39. - ret);
  40. + pr_err("watchdog%d: Cannot register reboot notifier (%d)\n",
  41. + wdd->id, ret);
  42. watchdog_dev_unregister(wdd);
  43. ida_simple_remove(&watchdog_ida, wdd->id);
  44. return ret;
  45. @@ -262,8 +262,8 @@ static int __watchdog_register_device(st
  46. ret = register_restart_handler(&wdd->restart_nb);
  47. if (ret)
  48. - dev_warn(wdd->dev, "Cannot register restart handler (%d)\n",
  49. - ret);
  50. + pr_warn("watchog%d: Cannot register restart handler (%d)\n",
  51. + wdd->id, ret);
  52. }
  53. return 0;
  54. --- a/drivers/watchdog/watchdog_dev.c
  55. +++ b/drivers/watchdog/watchdog_dev.c
  56. @@ -143,7 +143,8 @@ static int watchdog_stop(struct watchdog
  57. return 0;
  58. if (test_bit(WDOG_NO_WAY_OUT, &wdd->status)) {
  59. - dev_info(wdd->dev, "nowayout prevents watchdog being stopped!\n");
  60. + pr_info("watchdog%d: nowayout prevents watchdog being stopped!\n",
  61. + wdd->id);
  62. return -EBUSY;
  63. }
  64. @@ -604,7 +605,7 @@ static int watchdog_release(struct inode
  65. /* If the watchdog was not stopped, send a keepalive ping */
  66. if (err < 0) {
  67. - dev_crit(wdd->dev, "watchdog did not stop!\n");
  68. + pr_crit("watchdog%d: watchdog did not stop!\n", wdd->id);
  69. watchdog_ping(wdd);
  70. }
  71. @@ -750,7 +751,6 @@ int watchdog_dev_register(struct watchdo
  72. watchdog_cdev_unregister(wdd);
  73. return PTR_ERR(dev);
  74. }
  75. - wdd->dev = dev;
  76. return ret;
  77. }
  78. @@ -765,8 +765,7 @@ int watchdog_dev_register(struct watchdo
  79. void watchdog_dev_unregister(struct watchdog_device *wdd)
  80. {
  81. - device_destroy(&watchdog_class, wdd->dev->devt);
  82. - wdd->dev = NULL;
  83. + device_destroy(&watchdog_class, wdd->wd_data->cdev.dev);
  84. watchdog_cdev_unregister(wdd);
  85. }
  86. --- a/include/linux/watchdog.h
  87. +++ b/include/linux/watchdog.h
  88. @@ -55,7 +55,6 @@ struct watchdog_ops {
  89. /** struct watchdog_device - The structure that defines a watchdog device
  90. *
  91. * @id: The watchdog's ID. (Allocated by watchdog_register_device)
  92. - * @dev: The device for our watchdog
  93. * @parent: The parent bus device
  94. * @info: Pointer to a watchdog_info structure.
  95. * @ops: Pointer to the list of watchdog operations.
  96. @@ -82,7 +81,6 @@ struct watchdog_ops {
  97. */
  98. struct watchdog_device {
  99. int id;
  100. - struct device *dev;
  101. struct device *parent;
  102. const struct watchdog_info *info;
  103. const struct watchdog_ops *ops;