diff options
author | Andrew Lunn <andrew@lunn.ch> | 2018-07-17 21:48:12 +0200 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-07-18 10:01:46 +0900 |
commit | dcb5d0fcaa1ddd0af9c18ef51e6b05e38a6cec71 (patch) | |
tree | 6df2dadc6a18ce56330c1b0ac18fd3495d9ae23a /include/linux/hwmon.h | |
parent | aa7f29b07c8702127124d0522e3cd46850cdbc41 (diff) |
hwmon: Add helper to tell if a char is invalid in a name
HWMON device names are not allowed to contain "-* \t\n". Add a helper
which will return true if passed an invalid character. It can be used
to massage a string into a hwmon compatible name by replacing invalid
characters with '_'.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/hwmon.h')
-rw-r--r-- | include/linux/hwmon.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h index b217101ca76e..9493d4a388db 100644 --- a/include/linux/hwmon.h +++ b/include/linux/hwmon.h @@ -398,4 +398,27 @@ devm_hwmon_device_register_with_info(struct device *dev, void hwmon_device_unregister(struct device *dev); void devm_hwmon_device_unregister(struct device *dev); +/** + * hwmon_is_bad_char - Is the char invalid in a hwmon name + * @ch: the char to be considered + * + * hwmon_is_bad_char() can be used to determine if the given character + * may not be used in a hwmon name. + * + * Returns true if the char is invalid, false otherwise. + */ +static inline bool hwmon_is_bad_char(const char ch) +{ + switch (ch) { + case '-': + case '*': + case ' ': + case '\t': + case '\n': + return true; + default: + return false; + } +} + #endif |