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

hwmon: (ad7414) Convert to devm_hwmon_device_register_with_groups

Use ATTRIBUTE_GROUPS macro and devm_hwmon_device_register_with_groups() to
simplify the code a bit.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Axel Lin and committed by
Guenter Roeck
045c1391 ed67f087

+16 -41
+16 -41
drivers/hwmon/ad7414.c
··· 39 39 static u8 AD7414_REG_LIMIT[] = { AD7414_REG_T_HIGH, AD7414_REG_T_LOW }; 40 40 41 41 struct ad7414_data { 42 - struct device *hwmon_dev; 42 + struct i2c_client *client; 43 43 struct mutex lock; /* atomic read data updates */ 44 44 char valid; /* !=0 if following fields are valid */ 45 45 unsigned long next_update; /* In jiffies */ ··· 72 72 73 73 static struct ad7414_data *ad7414_update_device(struct device *dev) 74 74 { 75 - struct i2c_client *client = to_i2c_client(dev); 76 - struct ad7414_data *data = i2c_get_clientdata(client); 75 + struct ad7414_data *data = dev_get_drvdata(dev); 76 + struct i2c_client *client = data->client; 77 77 78 78 mutex_lock(&data->lock); 79 79 ··· 127 127 struct device_attribute *attr, 128 128 const char *buf, size_t count) 129 129 { 130 - struct i2c_client *client = to_i2c_client(dev); 131 - struct ad7414_data *data = i2c_get_clientdata(client); 130 + struct ad7414_data *data = dev_get_drvdata(dev); 131 + struct i2c_client *client = data->client; 132 132 int index = to_sensor_dev_attr(attr)->index; 133 133 u8 reg = AD7414_REG_LIMIT[index]; 134 134 long temp; ··· 164 164 static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 3); 165 165 static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 4); 166 166 167 - static struct attribute *ad7414_attributes[] = { 167 + static struct attribute *ad7414_attrs[] = { 168 168 &sensor_dev_attr_temp1_input.dev_attr.attr, 169 169 &sensor_dev_attr_temp1_max.dev_attr.attr, 170 170 &sensor_dev_attr_temp1_min.dev_attr.attr, ··· 173 173 NULL 174 174 }; 175 175 176 - static const struct attribute_group ad7414_group = { 177 - .attrs = ad7414_attributes, 178 - }; 176 + ATTRIBUTE_GROUPS(ad7414); 179 177 180 178 static int ad7414_probe(struct i2c_client *client, 181 179 const struct i2c_device_id *dev_id) 182 180 { 181 + struct device *dev = &client->dev; 183 182 struct ad7414_data *data; 183 + struct device *hwmon_dev; 184 184 int conf; 185 - int err; 186 185 187 186 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA | 188 187 I2C_FUNC_SMBUS_READ_WORD_DATA)) 189 188 return -EOPNOTSUPP; 190 189 191 - data = devm_kzalloc(&client->dev, sizeof(struct ad7414_data), 192 - GFP_KERNEL); 190 + data = devm_kzalloc(dev, sizeof(struct ad7414_data), GFP_KERNEL); 193 191 if (!data) 194 192 return -ENOMEM; 195 193 196 - i2c_set_clientdata(client, data); 194 + data->client = client; 197 195 mutex_init(&data->lock); 198 196 199 197 dev_info(&client->dev, "chip found\n"); ··· 199 201 /* Make sure the chip is powered up. */ 200 202 conf = i2c_smbus_read_byte_data(client, AD7414_REG_CONF); 201 203 if (conf < 0) 202 - dev_warn(&client->dev, 203 - "ad7414_probe unable to read config register.\n"); 204 + dev_warn(dev, "ad7414_probe unable to read config register.\n"); 204 205 else { 205 206 conf &= ~(1 << 7); 206 207 i2c_smbus_write_byte_data(client, AD7414_REG_CONF, conf); 207 208 } 208 209 209 - /* Register sysfs hooks */ 210 - err = sysfs_create_group(&client->dev.kobj, &ad7414_group); 211 - if (err) 212 - return err; 213 - 214 - data->hwmon_dev = hwmon_device_register(&client->dev); 215 - if (IS_ERR(data->hwmon_dev)) { 216 - err = PTR_ERR(data->hwmon_dev); 217 - goto exit_remove; 218 - } 219 - 220 - return 0; 221 - 222 - exit_remove: 223 - sysfs_remove_group(&client->dev.kobj, &ad7414_group); 224 - return err; 225 - } 226 - 227 - static int ad7414_remove(struct i2c_client *client) 228 - { 229 - struct ad7414_data *data = i2c_get_clientdata(client); 230 - 231 - hwmon_device_unregister(data->hwmon_dev); 232 - sysfs_remove_group(&client->dev.kobj, &ad7414_group); 233 - return 0; 210 + hwmon_dev = devm_hwmon_device_register_with_groups(dev, 211 + client->name, 212 + data, ad7414_groups); 213 + return PTR_ERR_OR_ZERO(hwmon_dev); 234 214 } 235 215 236 216 static const struct i2c_device_id ad7414_id[] = { ··· 222 246 .name = "ad7414", 223 247 }, 224 248 .probe = ad7414_probe, 225 - .remove = ad7414_remove, 226 249 .id_table = ad7414_id, 227 250 }; 228 251