Commit 1cb82fdb authored by Himangi Saraogi's avatar Himangi Saraogi Committed by Sebastian Reichel

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: default avatarHimangi Saraogi <himangi774@gmail.com>
Acked-by: default avatarJulia Lawall <julia.lawall@lip6.fr>
Signed-off-by: default avatarSebastian Reichel <sre@kernel.org>
parent c93e12c0
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
* http://www.ti.com/product/bq27425-g1 * http://www.ti.com/product/bq27425-g1
*/ */
#include <linux/device.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/param.h> #include <linux/param.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
...@@ -804,7 +805,7 @@ static int bq27x00_battery_probe(struct i2c_client *client, ...@@ -804,7 +805,7 @@ static int bq27x00_battery_probe(struct i2c_client *client,
goto batt_failed_1; goto batt_failed_1;
} }
di = kzalloc(sizeof(*di), GFP_KERNEL); di = devm_kzalloc(&client->dev, sizeof(*di), GFP_KERNEL);
if (!di) { if (!di) {
dev_err(&client->dev, "failed to allocate device info data\n"); dev_err(&client->dev, "failed to allocate device info data\n");
retval = -ENOMEM; retval = -ENOMEM;
...@@ -819,14 +820,12 @@ static int bq27x00_battery_probe(struct i2c_client *client, ...@@ -819,14 +820,12 @@ static int bq27x00_battery_probe(struct i2c_client *client,
retval = bq27x00_powersupply_init(di); retval = bq27x00_powersupply_init(di);
if (retval) if (retval)
goto batt_failed_3; goto batt_failed_2;
i2c_set_clientdata(client, di); i2c_set_clientdata(client, di);
return 0; return 0;
batt_failed_3:
kfree(di);
batt_failed_2: batt_failed_2:
kfree(name); kfree(name);
batt_failed_1: batt_failed_1:
...@@ -849,8 +848,6 @@ static int bq27x00_battery_remove(struct i2c_client *client) ...@@ -849,8 +848,6 @@ static int bq27x00_battery_remove(struct i2c_client *client)
idr_remove(&battery_id, di->id); idr_remove(&battery_id, di->id);
mutex_unlock(&battery_mutex); mutex_unlock(&battery_mutex);
kfree(di);
return 0; return 0;
} }
...@@ -933,7 +930,6 @@ static int bq27000_battery_probe(struct platform_device *pdev) ...@@ -933,7 +930,6 @@ static int bq27000_battery_probe(struct platform_device *pdev)
{ {
struct bq27x00_device_info *di; struct bq27x00_device_info *di;
struct bq27000_platform_data *pdata = pdev->dev.platform_data; struct bq27000_platform_data *pdata = pdev->dev.platform_data;
int ret;
if (!pdata) { if (!pdata) {
dev_err(&pdev->dev, "no platform_data supplied\n"); dev_err(&pdev->dev, "no platform_data supplied\n");
...@@ -945,7 +941,7 @@ static int bq27000_battery_probe(struct platform_device *pdev) ...@@ -945,7 +941,7 @@ static int bq27000_battery_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
di = kzalloc(sizeof(*di), GFP_KERNEL); di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
if (!di) { if (!di) {
dev_err(&pdev->dev, "failed to allocate device info data\n"); dev_err(&pdev->dev, "failed to allocate device info data\n");
return -ENOMEM; return -ENOMEM;
...@@ -959,16 +955,7 @@ static int bq27000_battery_probe(struct platform_device *pdev) ...@@ -959,16 +955,7 @@ static int bq27000_battery_probe(struct platform_device *pdev)
di->bat.name = pdata->name ?: dev_name(&pdev->dev); di->bat.name = pdata->name ?: dev_name(&pdev->dev);
di->bus.read = &bq27000_read_platform; di->bus.read = &bq27000_read_platform;
ret = bq27x00_powersupply_init(di); return bq27x00_powersupply_init(di);
if (ret)
goto err_free;
return 0;
err_free:
kfree(di);
return ret;
} }
static int bq27000_battery_remove(struct platform_device *pdev) static int bq27000_battery_remove(struct platform_device *pdev)
...@@ -977,8 +964,6 @@ static int bq27000_battery_remove(struct platform_device *pdev) ...@@ -977,8 +964,6 @@ static int bq27000_battery_remove(struct platform_device *pdev)
bq27x00_powersupply_unregister(di); bq27x00_powersupply_unregister(di);
kfree(di);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment