diff options
author | Guenter Roeck <linux@roeck-us.net> | 2012-02-22 11:56:47 -0500 |
---|---|---|
committer | Guenter Roeck <guenter.roeck@ericsson.com> | 2012-03-18 21:27:48 -0400 |
commit | f15df57ded710bd018794a264b900975ce3599a0 (patch) | |
tree | ca1b652e423860d7d01eca040af4ccdd94b5c73d /drivers/hwmon/jc42.c | |
parent | 918ddef35f518407d6ed6e72faf6df75e49cee24 (diff) |
hwmon: (jc42) Convert to use devm_kzalloc
Marginally less code and eliminate the possibility of memory leaks.
Also replace new_client variable with client and introduce dev variable to make
the code a bit easier to read.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/jc42.c')
-rw-r--r-- | drivers/hwmon/jc42.c | 60 |
1 files changed, 25 insertions, 35 deletions
diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c index 877e1593655b..a002bdac470a 100644 --- a/drivers/hwmon/jc42.c +++ b/drivers/hwmon/jc42.c | |||
@@ -469,20 +469,19 @@ static const struct attribute_group jc42_group = { | |||
469 | }; | 469 | }; |
470 | 470 | ||
471 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 471 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
472 | static int jc42_detect(struct i2c_client *new_client, | 472 | static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info) |
473 | struct i2c_board_info *info) | ||
474 | { | 473 | { |
475 | struct i2c_adapter *adapter = new_client->adapter; | 474 | struct i2c_adapter *adapter = client->adapter; |
476 | int i, config, cap, manid, devid; | 475 | int i, config, cap, manid, devid; |
477 | 476 | ||
478 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | | 477 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | |
479 | I2C_FUNC_SMBUS_WORD_DATA)) | 478 | I2C_FUNC_SMBUS_WORD_DATA)) |
480 | return -ENODEV; | 479 | return -ENODEV; |
481 | 480 | ||
482 | cap = i2c_smbus_read_word_swapped(new_client, JC42_REG_CAP); | 481 | cap = i2c_smbus_read_word_swapped(client, JC42_REG_CAP); |
483 | config = i2c_smbus_read_word_swapped(new_client, JC42_REG_CONFIG); | 482 | config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG); |
484 | manid = i2c_smbus_read_word_swapped(new_client, JC42_REG_MANID); | 483 | manid = i2c_smbus_read_word_swapped(client, JC42_REG_MANID); |
485 | devid = i2c_smbus_read_word_swapped(new_client, JC42_REG_DEVICEID); | 484 | devid = i2c_smbus_read_word_swapped(client, JC42_REG_DEVICEID); |
486 | 485 | ||
487 | if (cap < 0 || config < 0 || manid < 0 || devid < 0) | 486 | if (cap < 0 || config < 0 || manid < 0 || devid < 0) |
488 | return -ENODEV; | 487 | return -ENODEV; |
@@ -501,47 +500,42 @@ static int jc42_detect(struct i2c_client *new_client, | |||
501 | return -ENODEV; | 500 | return -ENODEV; |
502 | } | 501 | } |
503 | 502 | ||
504 | static int jc42_probe(struct i2c_client *new_client, | 503 | static int jc42_probe(struct i2c_client *client, const struct i2c_device_id *id) |
505 | const struct i2c_device_id *id) | ||
506 | { | 504 | { |
507 | struct jc42_data *data; | 505 | struct jc42_data *data; |
508 | int config, cap, err; | 506 | int config, cap, err; |
507 | struct device *dev = &client->dev; | ||
509 | 508 | ||
510 | data = kzalloc(sizeof(struct jc42_data), GFP_KERNEL); | 509 | data = devm_kzalloc(dev, sizeof(struct jc42_data), GFP_KERNEL); |
511 | if (!data) { | 510 | if (!data) |
512 | err = -ENOMEM; | 511 | return -ENOMEM; |
513 | goto exit; | ||
514 | } | ||
515 | 512 | ||
516 | i2c_set_clientdata(new_client, data); | 513 | i2c_set_clientdata(client, data); |
517 | mutex_init(&data->update_lock); | 514 | mutex_init(&data->update_lock); |
518 | 515 | ||
519 | cap = i2c_smbus_read_word_swapped(new_client, JC42_REG_CAP); | 516 | cap = i2c_smbus_read_word_swapped(client, JC42_REG_CAP); |
520 | if (cap < 0) { | 517 | if (cap < 0) |
521 | err = -EINVAL; | 518 | return cap; |
522 | goto exit_free; | 519 | |
523 | } | ||
524 | data->extended = !!(cap & JC42_CAP_RANGE); | 520 | data->extended = !!(cap & JC42_CAP_RANGE); |
525 | 521 | ||
526 | config = i2c_smbus_read_word_swapped(new_client, JC42_REG_CONFIG); | 522 | config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG); |
527 | if (config < 0) { | 523 | if (config < 0) |
528 | err = -EINVAL; | 524 | return config; |
529 | goto exit_free; | 525 | |
530 | } | ||
531 | data->orig_config = config; | 526 | data->orig_config = config; |
532 | if (config & JC42_CFG_SHUTDOWN) { | 527 | if (config & JC42_CFG_SHUTDOWN) { |
533 | config &= ~JC42_CFG_SHUTDOWN; | 528 | config &= ~JC42_CFG_SHUTDOWN; |
534 | i2c_smbus_write_word_swapped(new_client, JC42_REG_CONFIG, | 529 | i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, config); |
535 | config); | ||
536 | } | 530 | } |
537 | data->config = config; | 531 | data->config = config; |
538 | 532 | ||
539 | /* Register sysfs hooks */ | 533 | /* Register sysfs hooks */ |
540 | err = sysfs_create_group(&new_client->dev.kobj, &jc42_group); | 534 | err = sysfs_create_group(&dev->kobj, &jc42_group); |
541 | if (err) | 535 | if (err) |
542 | goto exit_free; | 536 | return err; |
543 | 537 | ||
544 | data->hwmon_dev = hwmon_device_register(&new_client->dev); | 538 | data->hwmon_dev = hwmon_device_register(dev); |
545 | if (IS_ERR(data->hwmon_dev)) { | 539 | if (IS_ERR(data->hwmon_dev)) { |
546 | err = PTR_ERR(data->hwmon_dev); | 540 | err = PTR_ERR(data->hwmon_dev); |
547 | goto exit_remove; | 541 | goto exit_remove; |
@@ -550,10 +544,7 @@ static int jc42_probe(struct i2c_client *new_client, | |||
550 | return 0; | 544 | return 0; |
551 | 545 | ||
552 | exit_remove: | 546 | exit_remove: |
553 | sysfs_remove_group(&new_client->dev.kobj, &jc42_group); | 547 | sysfs_remove_group(&dev->kobj, &jc42_group); |
554 | exit_free: | ||
555 | kfree(data); | ||
556 | exit: | ||
557 | return err; | 548 | return err; |
558 | } | 549 | } |
559 | 550 | ||
@@ -565,7 +556,6 @@ static int jc42_remove(struct i2c_client *client) | |||
565 | if (data->config != data->orig_config) | 556 | if (data->config != data->orig_config) |
566 | i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, | 557 | i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, |
567 | data->orig_config); | 558 | data->orig_config); |
568 | kfree(data); | ||
569 | return 0; | 559 | return 0; |
570 | } | 560 | } |
571 | 561 | ||