power: supply: register HWMON devices with valid names
authorRomain Izard <romain.izard.pro@gmail.com>
Fri, 30 Aug 2019 13:15:56 +0000 (15:15 +0200)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Sun, 1 Sep 2019 19:43:04 +0000 (21:43 +0200)
commitf1b937cc86bedf94dbc3478c2c0dc79471081fff
tree1a389bcb61398bae741943800b490080b234b394
parent5f9e832c137075045d15cd6899ab0505cfb2ca4b
power: supply: register HWMON devices with valid names

With the introduction of the HWMON compatibility layer to the power
supply framework in Linux 5.3, all power supply devices' names can be
used directly to create HWMON devices with the same names.

But HWMON has rules on allowable names that are different from those
used in the power supply framework. The dash character is forbidden, as
it is used by the libsensors library in userspace as a separator,
whereas this character is used in the device names in more than half of
the existing power supply drivers. This last case is consistent with the
typical naming usage with MFD and Device Tree.

This leads to warnings in the kernel log, with the format:

power_supply gpio-charger: hwmon: \
'gpio-charger' is not a valid name attribute, please fix

Add a protection to power_supply_add_hwmon_sysfs() that replaces any
dash in the device name with an underscore when registering with the
HWMON framework. Other forbidden characters (star, slash, space, tab,
newline) are not replaced, as they are not in common use.

Fixes: e67d4dfc9ff1 ("power: supply: Add HWMON compatibility layer")
Signed-off-by: Romain Izard <romain.izard.pro@gmail.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/power_supply_hwmon.c