aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/max16065.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-02-22 11:56:46 -0500
committerGuenter Roeck <guenter.roeck@ericsson.com>2012-03-18 21:27:48 -0400
commit918ddef35f518407d6ed6e72faf6df75e49cee24 (patch)
tree269d2ef9e3ddedc16cda4309857814857c4bba4d /drivers/hwmon/max16065.c
parentb8a5a7cebded23eb311b8db73a11ed23b4135170 (diff)
hwmon: (max16065) Convert to use devm_kzalloc
Marginally less code and eliminate the possibility of memory leaks. Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/max16065.c')
-rw-r--r--drivers/hwmon/max16065.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/drivers/hwmon/max16065.c b/drivers/hwmon/max16065.c
index 51edae93baa2..822261be84dd 100644
--- a/drivers/hwmon/max16065.c
+++ b/drivers/hwmon/max16065.c
@@ -554,7 +554,7 @@ static int max16065_probe(struct i2c_client *client,
554 | I2C_FUNC_SMBUS_READ_WORD_DATA)) 554 | I2C_FUNC_SMBUS_READ_WORD_DATA))
555 return -ENODEV; 555 return -ENODEV;
556 556
557 data = kzalloc(sizeof(*data), GFP_KERNEL); 557 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
558 if (unlikely(!data)) 558 if (unlikely(!data))
559 return -ENOMEM; 559 return -ENOMEM;
560 560
@@ -567,20 +567,16 @@ static int max16065_probe(struct i2c_client *client,
567 567
568 if (have_secondary) { 568 if (have_secondary) {
569 val = i2c_smbus_read_byte_data(client, MAX16065_SW_ENABLE); 569 val = i2c_smbus_read_byte_data(client, MAX16065_SW_ENABLE);
570 if (unlikely(val < 0)) { 570 if (unlikely(val < 0))
571 ret = val; 571 return val;
572 goto out_free;
573 }
574 secondary_is_max = val & MAX16065_WARNING_OV; 572 secondary_is_max = val & MAX16065_WARNING_OV;
575 } 573 }
576 574
577 /* Read scale registers, convert to range */ 575 /* Read scale registers, convert to range */
578 for (i = 0; i < DIV_ROUND_UP(data->num_adc, 4); i++) { 576 for (i = 0; i < DIV_ROUND_UP(data->num_adc, 4); i++) {
579 val = i2c_smbus_read_byte_data(client, MAX16065_SCALE(i)); 577 val = i2c_smbus_read_byte_data(client, MAX16065_SCALE(i));
580 if (unlikely(val < 0)) { 578 if (unlikely(val < 0))
581 ret = val; 579 return val;
582 goto out_free;
583 }
584 for (j = 0; j < 4 && i * 4 + j < data->num_adc; j++) { 580 for (j = 0; j < 4 && i * 4 + j < data->num_adc; j++) {
585 data->range[i * 4 + j] = 581 data->range[i * 4 + j] =
586 max16065_adc_range[(val >> (j * 2)) & 0x3]; 582 max16065_adc_range[(val >> (j * 2)) & 0x3];
@@ -595,10 +591,8 @@ static int max16065_probe(struct i2c_client *client,
595 for (j = 0; j < data->num_adc; j++) { 591 for (j = 0; j < data->num_adc; j++) {
596 val = i2c_smbus_read_byte_data(client, 592 val = i2c_smbus_read_byte_data(client,
597 MAX16065_LIMIT(i, j)); 593 MAX16065_LIMIT(i, j));
598 if (unlikely(val < 0)) { 594 if (unlikely(val < 0))
599 ret = val; 595 return val;
600 goto out_free;
601 }
602 data->limit[i][j] = LIMIT_TO_MV(val, data->range[j]); 596 data->limit[i][j] = LIMIT_TO_MV(val, data->range[j]);
603 } 597 }
604 } 598 }
@@ -661,8 +655,6 @@ static int max16065_probe(struct i2c_client *client,
661 655
662out: 656out:
663 max16065_cleanup(client); 657 max16065_cleanup(client);
664out_free:
665 kfree(data);
666 return ret; 658 return ret;
667} 659}
668 660
@@ -672,7 +664,6 @@ static int max16065_remove(struct i2c_client *client)
672 664
673 hwmon_device_unregister(data->hwmon_dev); 665 hwmon_device_unregister(data->hwmon_dev);
674 max16065_cleanup(client); 666 max16065_cleanup(client);
675 kfree(data);
676 667
677 return 0; 668 return 0;
678} 669}