--- zzzz-none-000/linux-3.10.107/drivers/hwmon/adt7411.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/hwmon/adt7411.c 2021-02-04 17:41:59.000000000 +0000 @@ -52,7 +52,7 @@ struct mutex update_lock; unsigned long next_update; int vref_cached; - struct device *hwmon_dev; + struct i2c_client *client; }; /* @@ -112,7 +112,8 @@ static ssize_t adt7411_show_vdd(struct device *dev, struct device_attribute *attr, char *buf) { - struct i2c_client *client = to_i2c_client(dev); + struct adt7411_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; int ret = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB, ADT7411_REG_VDD_MSB, 2); @@ -122,7 +123,8 @@ static ssize_t adt7411_show_temp(struct device *dev, struct device_attribute *attr, char *buf) { - struct i2c_client *client = to_i2c_client(dev); + struct adt7411_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; int val = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB, ADT7411_REG_INT_TEMP_MSB, 0); @@ -138,8 +140,8 @@ struct device_attribute *attr, char *buf) { int nr = to_sensor_dev_attr(attr)->index; - struct i2c_client *client = to_i2c_client(dev); - struct adt7411_data *data = i2c_get_clientdata(client); + struct adt7411_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; int val; u8 lsb_reg, lsb_shift; @@ -181,7 +183,8 @@ struct device_attribute *attr, char *buf) { struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr); - struct i2c_client *client = to_i2c_client(dev); + struct adt7411_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; int ret = i2c_smbus_read_byte_data(client, attr2->index); return ret < 0 ? ret : sprintf(buf, "%u\n", !!(ret & attr2->nr)); @@ -192,8 +195,8 @@ size_t count) { struct sensor_device_attribute_2 *s_attr2 = to_sensor_dev_attr_2(attr); - struct i2c_client *client = to_i2c_client(dev); - struct adt7411_data *data = i2c_get_clientdata(client); + struct adt7411_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; int ret; unsigned long flag; @@ -246,9 +249,7 @@ NULL }; -static const struct attribute_group adt7411_attr_grp = { - .attrs = adt7411_attrs, -}; +ATTRIBUTE_GROUPS(adt7411); static int adt7411_detect(struct i2c_client *client, struct i2c_board_info *info) @@ -282,14 +283,17 @@ static int adt7411_probe(struct i2c_client *client, const struct i2c_device_id *id) { + struct device *dev = &client->dev; struct adt7411_data *data; + struct device *hwmon_dev; int ret; - data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; i2c_set_clientdata(client, data); + data->client = client; mutex_init(&data->device_lock); mutex_init(&data->update_lock); @@ -303,32 +307,10 @@ /* force update on first occasion */ data->next_update = jiffies; - ret = sysfs_create_group(&client->dev.kobj, &adt7411_attr_grp); - if (ret) - return ret; - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - ret = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "successfully registered\n"); - - return 0; - - exit_remove: - sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp); - return ret; -} - -static int adt7411_remove(struct i2c_client *client) -{ - struct adt7411_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp); - return 0; + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, + data, + adt7411_groups); + return PTR_ERR_OR_ZERO(hwmon_dev); } static const struct i2c_device_id adt7411_id[] = { @@ -342,7 +324,6 @@ .name = "adt7411", }, .probe = adt7411_probe, - .remove = adt7411_remove, .id_table = adt7411_id, .detect = adt7411_detect, .address_list = normal_i2c,