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

hwmon: (iio_hwmon) Allow the driver to accept hypen in device tree node names

Currently the driver calls hwmon_device_register_with_groups which
does not accept hypen in node name and returns EINVAL. Use of hypen
in device tree node name results in probe failure., however use of
hypen in device tree node name is perfectly acceptable.

Change this by allocating a duplicate managed string, replacing
hypen with underscore and then calling hwmon_device_register_with_groups.
This allows the use of hypen in device tree node name while maintaining
backwards compatibility and preventing any possible regressions with
user space.

Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Sanchayan Maity and committed by
Guenter Roeck
b92fe9e3 df922703

+10 -1
+10 -1
drivers/hwmon/iio_hwmon.c
··· 67 67 enum iio_chan_type type; 68 68 struct iio_channel *channels; 69 69 const char *name = "iio_hwmon"; 70 + char *sname; 70 71 71 72 if (dev->of_node && dev->of_node->name) 72 73 name = dev->of_node->name; ··· 145 144 146 145 st->attr_group.attrs = st->attrs; 147 146 st->groups[0] = &st->attr_group; 148 - st->hwmon_dev = hwmon_device_register_with_groups(dev, name, st, 147 + 148 + sname = devm_kstrdup(dev, name, GFP_KERNEL); 149 + if (!sname) { 150 + ret = -ENOMEM; 151 + goto error_release_channels; 152 + } 153 + 154 + strreplace(sname, '-', '_'); 155 + st->hwmon_dev = hwmon_device_register_with_groups(dev, sname, st, 149 156 st->groups); 150 157 if (IS_ERR(st->hwmon_dev)) { 151 158 ret = PTR_ERR(st->hwmon_dev);