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

hwmon: (thmc50) Convert to devm_hwmon_device_register_with_groups

Use 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
86fd260e 9b38a66e

+25 -53
+25 -53
drivers/hwmon/thmc50.c
··· 68 68 69 69 /* Each client has this additional data */ 70 70 struct thmc50_data { 71 - struct device *hwmon_dev; 71 + struct i2c_client *client; 72 + const struct attribute_group *groups[3]; 72 73 73 74 struct mutex update_lock; 74 75 enum chips type; ··· 88 87 89 88 static struct thmc50_data *thmc50_update_device(struct device *dev) 90 89 { 91 - struct i2c_client *client = to_i2c_client(dev); 92 - struct thmc50_data *data = i2c_get_clientdata(client); 90 + struct thmc50_data *data = dev_get_drvdata(dev); 91 + struct i2c_client *client = data->client; 93 92 int timeout = HZ / 5 + (data->type == thmc50 ? HZ : 0); 94 93 95 94 mutex_lock(&data->update_lock); ··· 139 138 struct device_attribute *attr, 140 139 const char *buf, size_t count) 141 140 { 142 - struct i2c_client *client = to_i2c_client(dev); 143 - struct thmc50_data *data = i2c_get_clientdata(client); 141 + struct thmc50_data *data = dev_get_drvdata(dev); 142 + struct i2c_client *client = data->client; 144 143 int config; 145 144 unsigned long tmp; 146 145 int err; ··· 193 192 const char *buf, size_t count) 194 193 { 195 194 int nr = to_sensor_dev_attr(attr)->index; 196 - struct i2c_client *client = to_i2c_client(dev); 197 - struct thmc50_data *data = i2c_get_clientdata(client); 195 + struct thmc50_data *data = dev_get_drvdata(dev); 196 + struct i2c_client *client = data->client; 198 197 long val; 199 198 int err; 200 199 ··· 222 221 const char *buf, size_t count) 223 222 { 224 223 int nr = to_sensor_dev_attr(attr)->index; 225 - struct i2c_client *client = to_i2c_client(dev); 226 - struct thmc50_data *data = i2c_get_clientdata(client); 224 + struct thmc50_data *data = dev_get_drvdata(dev); 225 + struct i2c_client *client = data->client; 227 226 long val; 228 227 int err; 229 228 ··· 371 370 return 0; 372 371 } 373 372 374 - static void thmc50_init_client(struct i2c_client *client) 373 + static void thmc50_init_client(struct thmc50_data *data) 375 374 { 376 - struct thmc50_data *data = i2c_get_clientdata(client); 375 + struct i2c_client *client = data->client; 377 376 int config; 378 377 379 378 data->analog_out = i2c_smbus_read_byte_data(client, ··· 394 393 static int thmc50_probe(struct i2c_client *client, 395 394 const struct i2c_device_id *id) 396 395 { 396 + struct device *dev = &client->dev; 397 397 struct thmc50_data *data; 398 - int err; 398 + struct device *hwmon_dev; 399 + int idx = 0; 399 400 400 - data = devm_kzalloc(&client->dev, sizeof(struct thmc50_data), 401 - GFP_KERNEL); 401 + data = devm_kzalloc(dev, sizeof(struct thmc50_data), GFP_KERNEL); 402 402 if (!data) 403 403 return -ENOMEM; 404 404 405 - i2c_set_clientdata(client, data); 405 + data->client = client; 406 406 data->type = id->driver_data; 407 407 mutex_init(&data->update_lock); 408 408 409 - thmc50_init_client(client); 409 + thmc50_init_client(data); 410 410 411 - /* Register sysfs hooks */ 412 - err = sysfs_create_group(&client->dev.kobj, &thmc50_group); 413 - if (err) 414 - return err; 411 + /* sysfs hooks */ 412 + data->groups[idx++] = &thmc50_group; 415 413 416 - /* Register ADM1022 sysfs hooks */ 417 - if (data->has_temp3) { 418 - err = sysfs_create_group(&client->dev.kobj, &temp3_group); 419 - if (err) 420 - goto exit_remove_sysfs_thmc50; 421 - } 422 - 423 - /* Register a new directory entry with module sensors */ 424 - data->hwmon_dev = hwmon_device_register(&client->dev); 425 - if (IS_ERR(data->hwmon_dev)) { 426 - err = PTR_ERR(data->hwmon_dev); 427 - goto exit_remove_sysfs; 428 - } 429 - 430 - return 0; 431 - 432 - exit_remove_sysfs: 414 + /* Register additional ADM1022 sysfs hooks */ 433 415 if (data->has_temp3) 434 - sysfs_remove_group(&client->dev.kobj, &temp3_group); 435 - exit_remove_sysfs_thmc50: 436 - sysfs_remove_group(&client->dev.kobj, &thmc50_group); 437 - return err; 438 - } 416 + data->groups[idx++] = &temp3_group; 439 417 440 - static int thmc50_remove(struct i2c_client *client) 441 - { 442 - struct thmc50_data *data = i2c_get_clientdata(client); 443 - 444 - hwmon_device_unregister(data->hwmon_dev); 445 - sysfs_remove_group(&client->dev.kobj, &thmc50_group); 446 - if (data->has_temp3) 447 - sysfs_remove_group(&client->dev.kobj, &temp3_group); 448 - 449 - return 0; 418 + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, 419 + data, data->groups); 420 + return PTR_ERR_OR_ZERO(hwmon_dev); 450 421 } 451 422 452 423 static const struct i2c_device_id thmc50_id[] = { ··· 434 461 .name = "thmc50", 435 462 }, 436 463 .probe = thmc50_probe, 437 - .remove = thmc50_remove, 438 464 .id_table = thmc50_id, 439 465 .detect = thmc50_detect, 440 466 .address_list = normal_i2c,