diff options
| author | Himangi Saraogi <himangi774@gmail.com> | 2014-05-28 13:28:49 -0400 |
|---|---|---|
| committer | Sebastian Reichel <sre@kernel.org> | 2014-07-18 17:40:22 -0400 |
| commit | 1cb82fdb2a0fb2af9da69eeee92877189ec9a560 (patch) | |
| tree | b0441df1a37b41c1e5d09ce5e930c041d4f0a2f0 | |
| parent | c93e12c0ff42de33514d574ff1292f5347e2a8b5 (diff) | |
bq27x00_battery: Introduce the use of the managed version of kzalloc
This patch moves data allocated using kzalloc to managed data allocated
using devm_kzalloc and cleans now unnecessary kfrees in probe and remove
functions for both platform and i2c drivers. Also, the unecessary
variable ret and labels batt_failed3, err_free were removed.
The following Coccinele script was used for making the change:
@platform@
identifier p, probefn, removefn;
@@
struct platform_driver p = {
.probe = probefn,
.remove = removefn,
};
@prb@
identifier platform.probefn, pdev;
expression e, e1, e2;
@@
probefn(struct platform_device *pdev, ...) {
<+...
- e = kzalloc(e1, e2)
+ e = devm_kzalloc(&pdev->dev, e1, e2)
...
?-kfree(e);
...+>
}
@rem depends on prb@
identifier platform.removefn;
expression e;
@@
removefn(...) {
<...
- kfree(e);
...>
}
Signed-off-by: Himangi Saraogi <himangi774@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
| -rw-r--r-- | drivers/power/bq27x00_battery.c | 25 |
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 | ||
| 828 | batt_failed_3: | ||
| 829 | kfree(di); | ||
| 830 | batt_failed_2: | 829 | batt_failed_2: |
| 831 | kfree(name); | 830 | kfree(name); |
| 832 | batt_failed_1: | 831 | batt_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 | |||
| 968 | err_free: | ||
| 969 | kfree(di); | ||
| 970 | |||
| 971 | return ret; | ||
| 972 | } | 959 | } |
| 973 | 960 | ||
| 974 | static int bq27000_battery_remove(struct platform_device *pdev) | 961 | static 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 | ||
