Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

watchdog: pretimeout: add pretimeout_available_governors attribute

The change adds an option to a user with CONFIG_WATCHDOG_SYSFS and
CONFIG_WATCHDOG_PRETIMEOUT_GOV enabled to get information about all
registered watchdog pretimeout governors by reading watchdog device
attribute named "pretimeout_available_governors".

Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>

authored by

Vladimir Zapolskiy and committed by
Wim Van Sebroeck
89873a71 53f96cee

+31 -1
+10 -1
drivers/watchdog/watchdog_dev.c
··· 489 489 } 490 490 static DEVICE_ATTR_RO(state); 491 491 492 + static ssize_t pretimeout_available_governors_show(struct device *dev, 493 + struct device_attribute *attr, char *buf) 494 + { 495 + return watchdog_pretimeout_available_governors_get(buf); 496 + } 497 + static DEVICE_ATTR_RO(pretimeout_available_governors); 498 + 492 499 static ssize_t pretimeout_governor_show(struct device *dev, 493 500 struct device_attribute *attr, 494 501 char *buf) ··· 531 524 else if (attr == &dev_attr_pretimeout.attr && 532 525 !(wdd->info->options & WDIOF_PRETIMEOUT)) 533 526 mode = 0; 534 - else if (attr == &dev_attr_pretimeout_governor.attr && 527 + else if ((attr == &dev_attr_pretimeout_governor.attr || 528 + attr == &dev_attr_pretimeout_available_governors.attr) && 535 529 (!(wdd->info->options & WDIOF_PRETIMEOUT) || 536 530 !IS_ENABLED(CONFIG_WATCHDOG_PRETIMEOUT_GOV))) 537 531 mode = 0; ··· 549 541 &dev_attr_status.attr, 550 542 &dev_attr_nowayout.attr, 551 543 &dev_attr_pretimeout_governor.attr, 544 + &dev_attr_pretimeout_available_governors.attr, 552 545 NULL, 553 546 }; 554 547
+15
drivers/watchdog/watchdog_pretimeout.c
··· 52 52 return NULL; 53 53 } 54 54 55 + int watchdog_pretimeout_available_governors_get(char *buf) 56 + { 57 + struct governor_priv *priv; 58 + int count = 0; 59 + 60 + mutex_lock(&governor_lock); 61 + 62 + list_for_each_entry(priv, &governor_list, entry) 63 + count += sprintf(buf + count, "%s\n", priv->gov->name); 64 + 65 + mutex_unlock(&governor_lock); 66 + 67 + return count; 68 + } 69 + 55 70 int watchdog_pretimeout_governor_get(struct watchdog_device *wdd, char *buf) 56 71 { 57 72 int count = 0;
+6
drivers/watchdog/watchdog_pretimeout.h
··· 18 18 /* Interfaces to watchdog_dev.c */ 19 19 int watchdog_register_pretimeout(struct watchdog_device *wdd); 20 20 void watchdog_unregister_pretimeout(struct watchdog_device *wdd); 21 + int watchdog_pretimeout_available_governors_get(char *buf); 21 22 int watchdog_pretimeout_governor_get(struct watchdog_device *wdd, char *buf); 22 23 int watchdog_pretimeout_governor_set(struct watchdog_device *wdd, 23 24 const char *buf); ··· 37 36 38 37 static inline void watchdog_unregister_pretimeout(struct watchdog_device *wdd) 39 38 { 39 + } 40 + 41 + static inline int watchdog_pretimeout_available_governors_get(char *buf) 42 + { 43 + return -EINVAL; 40 44 } 41 45 42 46 static inline int watchdog_pretimeout_governor_get(struct watchdog_device *wdd,