aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/power/bq27x00_battery.c25
1 files changed, 5 insertions, 20 deletions
diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index b309713b63bc..a0f205b0471d 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -25,6 +25,7 @@
25 * http://www.ti.com/product/bq27425-g1 25 * http://www.ti.com/product/bq27425-g1
26 */ 26 */
27 27
28#include <linux/device.h>
28#include <linux/module.h> 29#include <linux/module.h>
29#include <linux/param.h> 30#include <linux/param.h>
30#include <linux/jiffies.h> 31#include <linux/jiffies.h>
@@ -804,7 +805,7 @@ static int bq27x00_battery_probe(struct i2c_client *client,
804 goto batt_failed_1; 805 goto batt_failed_1;
805 } 806 }
806 807
807 di = kzalloc(sizeof(*di), GFP_KERNEL); 808 di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL);
808 if (!di) { 809 if (!di) {
809 dev_err(&client->dev, "failed to allocate device info data\n"); 810 dev_err(&client->dev, "failed to allocate device info data\n");
810 retval = -ENOMEM; 811 retval = -ENOMEM;
@@ -819,14 +820,12 @@ static int bq27x00_battery_probe(struct i2c_client *client,
819 820
820 retval = bq27x00_powersupply_init(di); 821 retval = bq27x00_powersupply_init(di);
821 if (retval) 822 if (retval)
822 goto batt_failed_3; 823 goto batt_failed_2;
823 824
824 i2c_set_clientdata(client, di); 825 i2c_set_clientdata(client, di);
825 826
826 return 0; 827 return 0;
827 828
828batt_failed_3:
829 kfree(di);
830batt_failed_2: 829batt_failed_2:
831 kfree(name); 830 kfree(name);
832batt_failed_1: 831batt_failed_1:
@@ -849,8 +848,6 @@ static int bq27x00_battery_remove(struct i2c_client *client)
849 idr_remove(&battery_id, di->id); 848 idr_remove(&battery_id, di->id);
850 mutex_unlock(&battery_mutex); 849 mutex_unlock(&battery_mutex);
851 850
852 kfree(di);
853
854 return 0; 851 return 0;
855} 852}
856 853
@@ -933,7 +930,6 @@ static int bq27000_battery_probe(struct platform_device *pdev)
933{ 930{
934 struct bq27x00_device_info *di; 931 struct bq27x00_device_info *di;
935 struct bq27000_platform_data *pdata = pdev->dev.platform_data; 932 struct bq27000_platform_data *pdata = pdev->dev.platform_data;
936 int ret;
937 933
938 if (!pdata) { 934 if (!pdata) {
939 dev_err(&pdev->dev, "no platform_data supplied\n"); 935 dev_err(&pdev->dev, "no platform_data supplied\n");
@@ -945,7 +941,7 @@ static int bq27000_battery_probe(struct platform_device *pdev)
945 return -EINVAL; 941 return -EINVAL;
946 } 942 }
947 943
948 di = kzalloc(sizeof(*di), GFP_KERNEL); 944 di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
949 if (!di) { 945 if (!di) {
950 dev_err(&pdev->dev, "failed to allocate device info data\n"); 946 dev_err(&pdev->dev, "failed to allocate device info data\n");
951 return -ENOMEM; 947 return -ENOMEM;
@@ -959,16 +955,7 @@ static int bq27000_battery_probe(struct platform_device *pdev)
959 di->bat.name = pdata->name ?: dev_name(&pdev->dev); 955 di->bat.name = pdata->name ?: dev_name(&pdev->dev);
960 di->bus.read = &bq27000_read_platform; 956 di->bus.read = &bq27000_read_platform;
961 957
962 ret = bq27x00_powersupply_init(di); 958 return bq27x00_powersupply_init(di);
963 if (ret)
964 goto err_free;
965
966 return 0;
967
968err_free:
969 kfree(di);
970
971 return ret;
972} 959}
973 960
974static int bq27000_battery_remove(struct platform_device *pdev) 961static int bq27000_battery_remove(struct platform_device *pdev)
@@ -977,8 +964,6 @@ static int bq27000_battery_remove(struct platform_device *pdev)
977 964
978 bq27x00_powersupply_unregister(di); 965 bq27x00_powersupply_unregister(di);
979 966
980 kfree(di);
981
982 return 0; 967 return 0;
983} 968}
984 969