Skip to content

Commit dcb5d0f

Browse files
lunndavem330
authored andcommitted
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 <[email protected]> Acked-by: Guenter Roeck <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent aa7f29b commit dcb5d0f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

include/linux/hwmon.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,4 +398,27 @@ devm_hwmon_device_register_with_info(struct device *dev,
398398
void hwmon_device_unregister(struct device *dev);
399399
void devm_hwmon_device_unregister(struct device *dev);
400400

401+
/**
402+
* hwmon_is_bad_char - Is the char invalid in a hwmon name
403+
* @ch: the char to be considered
404+
*
405+
* hwmon_is_bad_char() can be used to determine if the given character
406+
* may not be used in a hwmon name.
407+
*
408+
* Returns true if the char is invalid, false otherwise.
409+
*/
410+
static inline bool hwmon_is_bad_char(const char ch)
411+
{
412+
switch (ch) {
413+
case '-':
414+
case '*':
415+
case ' ':
416+
case '\t':
417+
case '\n':
418+
return true;
419+
default:
420+
return false;
421+
}
422+
}
423+
401424
#endif

0 commit comments

Comments
 (0)