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

hwmon: (iio_hwmon) Convert to use hwmon_device_register_with_groups

Simplify code and create name attribute automatically.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>

+12 -25
+12 -25
drivers/hwmon/iio_hwmon.c
··· 31 31 int num_channels; 32 32 struct device *hwmon_dev; 33 33 struct attribute_group attr_group; 34 + const struct attribute_group *groups[2]; 34 35 struct attribute **attrs; 35 36 }; 36 37 ··· 57 56 return sprintf(buf, "%d\n", result); 58 57 } 59 58 60 - static ssize_t show_name(struct device *dev, struct device_attribute *attr, 61 - char *buf) 62 - { 63 - const char *name = "iio_hwmon"; 64 - 65 - if (dev->of_node && dev->of_node->name) 66 - name = dev->of_node->name; 67 - 68 - return sprintf(buf, "%s\n", name); 69 - } 70 - 71 - static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 72 - 73 59 static int iio_hwmon_probe(struct platform_device *pdev) 74 60 { 75 61 struct device *dev = &pdev->dev; ··· 66 78 int in_i = 1, temp_i = 1, curr_i = 1; 67 79 enum iio_chan_type type; 68 80 struct iio_channel *channels; 81 + const char *name = "iio_hwmon"; 82 + 83 + if (dev->of_node && dev->of_node->name) 84 + name = dev->of_node->name; 69 85 70 86 channels = iio_channel_get_all(dev); 71 87 if (IS_ERR(channels)) ··· 88 96 st->num_channels++; 89 97 90 98 st->attrs = devm_kzalloc(dev, 91 - sizeof(*st->attrs) * (st->num_channels + 2), 99 + sizeof(*st->attrs) * (st->num_channels + 1), 92 100 GFP_KERNEL); 93 101 if (st->attrs == NULL) { 94 102 ret = -ENOMEM; ··· 136 144 a->index = i; 137 145 st->attrs[i] = &a->dev_attr.attr; 138 146 } 139 - st->attrs[st->num_channels] = &dev_attr_name.attr; 140 - st->attr_group.attrs = st->attrs; 141 - platform_set_drvdata(pdev, st); 142 - ret = sysfs_create_group(&dev->kobj, &st->attr_group); 143 - if (ret < 0) 144 - goto error_release_channels; 145 147 146 - st->hwmon_dev = hwmon_device_register(dev); 148 + st->attr_group.attrs = st->attrs; 149 + st->groups[0] = &st->attr_group; 150 + st->hwmon_dev = hwmon_device_register_with_groups(dev, name, st, 151 + st->groups); 147 152 if (IS_ERR(st->hwmon_dev)) { 148 153 ret = PTR_ERR(st->hwmon_dev); 149 - goto error_remove_group; 154 + goto error_release_channels; 150 155 } 156 + platform_set_drvdata(pdev, st); 151 157 return 0; 152 158 153 - error_remove_group: 154 - sysfs_remove_group(&dev->kobj, &st->attr_group); 155 159 error_release_channels: 156 160 iio_channel_release_all(channels); 157 161 return ret; ··· 158 170 struct iio_hwmon_state *st = platform_get_drvdata(pdev); 159 171 160 172 hwmon_device_unregister(st->hwmon_dev); 161 - sysfs_remove_group(&pdev->dev.kobj, &st->attr_group); 162 173 iio_channel_release_all(st->channels); 163 174 164 175 return 0;