Skip to content

Commit

Permalink
hwmon: Add helper to tell if a char is invalid in a name
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Andrew Lunn authored and David S. Miller committed Jul 18, 2018
1 parent aa7f29b commit dcb5d0f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions include/linux/hwmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit dcb5d0f

Please sign in to comment.