--- zzzz-none-000/linux-3.10.107/drivers/hwmon/iio_hwmon.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/hwmon/iio_hwmon.c 2021-02-04 17:41:59.000000000 +0000 @@ -31,6 +31,7 @@ int num_channels; struct device *hwmon_dev; struct attribute_group attr_group; + const struct attribute_group *groups[2]; struct attribute **attrs; }; @@ -56,28 +57,19 @@ return sprintf(buf, "%d\n", result); } -static ssize_t show_name(struct device *dev, struct device_attribute *attr, - char *buf) -{ - const char *name = "iio_hwmon"; - - if (dev->of_node && dev->of_node->name) - name = dev->of_node->name; - - return sprintf(buf, "%s\n", name); -} - -static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); - static int iio_hwmon_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct iio_hwmon_state *st; struct sensor_device_attribute *a; int ret, i; - int in_i = 1, temp_i = 1, curr_i = 1; + int in_i = 1, temp_i = 1, curr_i = 1, humidity_i = 1; enum iio_chan_type type; struct iio_channel *channels; + const char *name = "iio_hwmon"; + + if (dev->of_node && dev->of_node->name) + name = dev->of_node->name; channels = iio_channel_get_all(dev); if (IS_ERR(channels)) @@ -96,7 +88,7 @@ st->num_channels++; st->attrs = devm_kzalloc(dev, - sizeof(*st->attrs) * (st->num_channels + 2), + sizeof(*st->attrs) * (st->num_channels + 1), GFP_KERNEL); if (st->attrs == NULL) { ret = -ENOMEM; @@ -117,19 +109,24 @@ switch (type) { case IIO_VOLTAGE: - a->dev_attr.attr.name = kasprintf(GFP_KERNEL, - "in%d_input", - in_i++); + a->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, + "in%d_input", + in_i++); break; case IIO_TEMP: - a->dev_attr.attr.name = kasprintf(GFP_KERNEL, - "temp%d_input", - temp_i++); + a->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, + "temp%d_input", + temp_i++); break; case IIO_CURRENT: - a->dev_attr.attr.name = kasprintf(GFP_KERNEL, - "curr%d_input", - curr_i++); + a->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, + "curr%d_input", + curr_i++); + break; + case IIO_HUMIDITYRELATIVE: + a->dev_attr.attr.name = devm_kasprintf(dev, GFP_KERNEL, + "humidity%d_input", + humidity_i++); break; default: ret = -EINVAL; @@ -144,22 +141,18 @@ a->index = i; st->attrs[i] = &a->dev_attr.attr; } - st->attrs[st->num_channels] = &dev_attr_name.attr; - st->attr_group.attrs = st->attrs; - platform_set_drvdata(pdev, st); - ret = sysfs_create_group(&dev->kobj, &st->attr_group); - if (ret < 0) - goto error_release_channels; - st->hwmon_dev = hwmon_device_register(dev); + st->attr_group.attrs = st->attrs; + st->groups[0] = &st->attr_group; + st->hwmon_dev = hwmon_device_register_with_groups(dev, name, st, + st->groups); if (IS_ERR(st->hwmon_dev)) { ret = PTR_ERR(st->hwmon_dev); - goto error_remove_group; + goto error_release_channels; } + platform_set_drvdata(pdev, st); return 0; -error_remove_group: - sysfs_remove_group(&dev->kobj, &st->attr_group); error_release_channels: iio_channel_release_all(channels); return ret; @@ -170,21 +163,20 @@ struct iio_hwmon_state *st = platform_get_drvdata(pdev); hwmon_device_unregister(st->hwmon_dev); - sysfs_remove_group(&pdev->dev.kobj, &st->attr_group); iio_channel_release_all(st->channels); return 0; } -static struct of_device_id iio_hwmon_of_match[] = { +static const struct of_device_id iio_hwmon_of_match[] = { { .compatible = "iio-hwmon", }, { } }; +MODULE_DEVICE_TABLE(of, iio_hwmon_of_match); static struct platform_driver __refdata iio_hwmon_driver = { .driver = { .name = "iio_hwmon", - .owner = THIS_MODULE, .of_match_table = iio_hwmon_of_match, }, .probe = iio_hwmon_probe,