[PATCH] watchdog: Make API functions const correct

Kari Argillander posted 1 patch 1 month, 2 weeks ago
Documentation/watchdog/watchdog-kernel-api.rst |  2 +-
drivers/watchdog/watchdog_core.c               |  3 ++-
include/linux/watchdog.h                       | 12 +++++++-----
3 files changed, 10 insertions(+), 7 deletions(-)
[PATCH] watchdog: Make API functions const correct
Posted by Kari Argillander 1 month, 2 weeks ago
Many watchdog API functions do not modify the watchdog_device nor
device. Mark their arguments as const to reflect this and improve
const-correctness of the API.

No functional change intended.

Signed-off-by: Kari Argillander <kari.argillander@gmail.com>
---
 Documentation/watchdog/watchdog-kernel-api.rst |  2 +-
 drivers/watchdog/watchdog_core.c               |  3 ++-
 include/linux/watchdog.h                       | 12 +++++++-----
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/Documentation/watchdog/watchdog-kernel-api.rst b/Documentation/watchdog/watchdog-kernel-api.rst
index 243231fe4c0a..5649c54cf6fb 100644
--- a/Documentation/watchdog/watchdog-kernel-api.rst
+++ b/Documentation/watchdog/watchdog-kernel-api.rst
@@ -293,7 +293,7 @@ To initialize the timeout field, the following function can be used::
 
   extern int watchdog_init_timeout(struct watchdog_device *wdd,
                                    unsigned int timeout_parm,
-                                   struct device *dev);
+                                   const struct device *dev);
 
 The watchdog_init_timeout function allows you to initialize the timeout field
 using the module timeout parameter or by retrieving the timeout-sec property from
diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
index 6152dba4b52c..8300520688d0 100644
--- a/drivers/watchdog/watchdog_core.c
+++ b/drivers/watchdog/watchdog_core.c
@@ -117,7 +117,8 @@ static void watchdog_check_min_max_timeout(struct watchdog_device *wdd)
  * bounds.
  */
 int watchdog_init_timeout(struct watchdog_device *wdd,
-				unsigned int timeout_parm, struct device *dev)
+			  unsigned int timeout_parm,
+			  const struct device *dev)
 {
 	const char *dev_str = wdd->parent ? dev_name(wdd->parent) :
 			      (const char *)wdd->info->identity;
diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h
index 8c60687a3e55..62cdd26fd025 100644
--- a/include/linux/watchdog.h
+++ b/include/linux/watchdog.h
@@ -129,7 +129,7 @@ struct watchdog_device {
 #define WATCHDOG_NOWAYOUT_INIT_STATUS	(WATCHDOG_NOWAYOUT << WDOG_NO_WAY_OUT)
 
 /* Use the following function to check whether or not the watchdog is active */
-static inline bool watchdog_active(struct watchdog_device *wdd)
+static inline bool watchdog_active(const struct watchdog_device *wdd)
 {
 	return test_bit(WDOG_ACTIVE, &wdd->status);
 }
@@ -138,7 +138,7 @@ static inline bool watchdog_active(struct watchdog_device *wdd)
  * Use the following function to check whether or not the hardware watchdog
  * is running
  */
-static inline bool watchdog_hw_running(struct watchdog_device *wdd)
+static inline bool watchdog_hw_running(const struct watchdog_device *wdd)
 {
 	return test_bit(WDOG_HW_RUNNING, &wdd->status);
 }
@@ -169,7 +169,8 @@ static inline void watchdog_stop_ping_on_suspend(struct watchdog_device *wdd)
 }
 
 /* Use the following function to check if a timeout value is invalid */
-static inline bool watchdog_timeout_invalid(struct watchdog_device *wdd, unsigned int t)
+static inline bool watchdog_timeout_invalid(const struct watchdog_device *wdd,
+					    unsigned int t)
 {
 	/*
 	 * The timeout is invalid if
@@ -188,7 +189,7 @@ static inline bool watchdog_timeout_invalid(struct watchdog_device *wdd, unsigne
 }
 
 /* Use the following function to check if a pretimeout value is invalid */
-static inline bool watchdog_pretimeout_invalid(struct watchdog_device *wdd,
+static inline bool watchdog_pretimeout_invalid(const struct watchdog_device *wdd,
 					       unsigned int t)
 {
 	return t && wdd->timeout && t >= wdd->timeout;
@@ -218,7 +219,8 @@ static inline void watchdog_notify_pretimeout(struct watchdog_device *wdd)
 /* drivers/watchdog/watchdog_core.c */
 void watchdog_set_restart_priority(struct watchdog_device *wdd, int priority);
 extern int watchdog_init_timeout(struct watchdog_device *wdd,
-				  unsigned int timeout_parm, struct device *dev);
+				 unsigned int timeout_parm,
+				 const struct device *dev);
 extern int watchdog_register_device(struct watchdog_device *);
 extern void watchdog_unregister_device(struct watchdog_device *);
 int watchdog_dev_suspend(struct watchdog_device *wdd);

---
base-commit: cc3aa43b44bdb43dfbac0fcb51c56594a11338a8
change-id: 20251219-watchdog-improvements-a26143b9c81e

Best regards,
-- 
Kari Argillander <kari.argillander@gmail.com>
Re: [PATCH] watchdog: Make API functions const correct
Posted by Guenter Roeck 1 month, 2 weeks ago
On 12/19/25 12:42, Kari Argillander wrote:
> Many watchdog API functions do not modify the watchdog_device nor
> device. Mark their arguments as const to reflect this and improve
> const-correctness of the API.
> 
> No functional change intended.
> 
> Signed-off-by: Kari Argillander <kari.argillander@gmail.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>