--- zzzz-none-000/linux-3.10.107/drivers/hwmon/smm665.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/hwmon/smm665.c 2021-02-04 17:41:59.000000000 +0000 @@ -140,7 +140,7 @@ struct smm665_data { enum chips type; int conversion_time; /* ADC conversion time */ - struct device *hwmon_dev; + struct i2c_client *client; struct mutex update_lock; bool valid; unsigned long last_updated; /* in jiffies */ @@ -222,7 +222,7 @@ rv = i2c_smbus_read_word_swapped(client, 0); if (rv < 0) { dev_dbg(&client->dev, "Failed to read ADC value: error %d", rv); - return -1; + return rv; } /* * Validate/verify readback adc channel (in bit 11..14). @@ -239,8 +239,8 @@ static struct smm665_data *smm665_update_device(struct device *dev) { - struct i2c_client *client = to_i2c_client(dev); - struct smm665_data *data = i2c_get_clientdata(client); + struct smm665_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; struct smm665_data *ret = data; mutex_lock(&data->update_lock); @@ -315,32 +315,28 @@ static int smm665_get_min(struct device *dev, int index) { - struct i2c_client *client = to_i2c_client(dev); - struct smm665_data *data = i2c_get_clientdata(client); + struct smm665_data *data = dev_get_drvdata(dev); return data->alarm_min_limit[index]; } static int smm665_get_max(struct device *dev, int index) { - struct i2c_client *client = to_i2c_client(dev); - struct smm665_data *data = i2c_get_clientdata(client); + struct smm665_data *data = dev_get_drvdata(dev); return data->alarm_max_limit[index]; } static int smm665_get_lcrit(struct device *dev, int index) { - struct i2c_client *client = to_i2c_client(dev); - struct smm665_data *data = i2c_get_clientdata(client); + struct smm665_data *data = dev_get_drvdata(dev); return data->critical_min_limit[index]; } static int smm665_get_crit(struct device *dev, int index) { - struct i2c_client *client = to_i2c_client(dev); - struct smm665_data *data = i2c_get_clientdata(client); + struct smm665_data *data = dev_get_drvdata(dev); return data->critical_max_limit[index]; } @@ -486,7 +482,7 @@ * Finally, construct an array of pointers to members of the above objects, * as required for sysfs_create_group() */ -static struct attribute *smm665_attributes[] = { +static struct attribute *smm665_attrs[] = { &sensor_dev_attr_in1_input.dev_attr.attr, &sensor_dev_attr_in1_min.dev_attr.attr, &sensor_dev_attr_in1_max.dev_attr.attr, @@ -567,15 +563,14 @@ NULL, }; -static const struct attribute_group smm665_group = { - .attrs = smm665_attributes, -}; +ATTRIBUTE_GROUPS(smm665); static int smm665_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct i2c_adapter *adapter = client->adapter; struct smm665_data *data; + struct device *hwmon_dev; int i, ret; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA @@ -592,6 +587,7 @@ i2c_set_clientdata(client, data); mutex_init(&data->update_lock); + data->client = client; data->type = id->driver_data; data->cmdreg = i2c_new_dummy(adapter, (client->addr & ~SMM665_REGMASK) | SMM665_CMDREG_BASE); @@ -662,21 +658,16 @@ data->alarm_max_limit[i] = smm665_convert(val, i); } - /* Register sysfs hooks */ - ret = sysfs_create_group(&client->dev.kobj, &smm665_group); - if (ret) + hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev, + client->name, data, + smm665_groups); + if (IS_ERR(hwmon_dev)) { + ret = PTR_ERR(hwmon_dev); goto out_unregister; - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - ret = PTR_ERR(data->hwmon_dev); - goto out_remove_group; } return 0; -out_remove_group: - sysfs_remove_group(&client->dev.kobj, &smm665_group); out_unregister: i2c_unregister_device(data->cmdreg); return ret; @@ -687,9 +678,6 @@ struct smm665_data *data = i2c_get_clientdata(client); i2c_unregister_device(data->cmdreg); - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &smm665_group); - return 0; }