power: sbs-battery: Use devm_kzalloc to alloc data
authorPhil Reid <preid@electromag.com.au>
Mon, 25 Jul 2016 02:42:57 +0000 (10:42 +0800)
committerSebastian Reichel <sre@kernel.org>
Mon, 15 Aug 2016 19:51:30 +0000 (21:51 +0200)
Use devm_kzalloc to allow memory to be freed automatically on
driver probe failure or removal.

Signed-off-by: Phil Reid <preid@electromag.com.au>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
drivers/power/supply/sbs-battery.c

index 768b9fcb58eacdc533e8094f8f68327bfae518e2..20f3be6f5b9aad57ea36807c28c38586abf62c51 100644 (file)
@@ -819,7 +819,7 @@ static int sbs_probe(struct i2c_client *client,
        if (!sbs_desc->name)
                return -ENOMEM;
 
-       chip = kzalloc(sizeof(struct sbs_info), GFP_KERNEL);
+       chip = devm_kzalloc(&client->dev, sizeof(struct sbs_info), GFP_KERNEL);
        if (!chip)
                return -ENOMEM;
 
@@ -920,8 +920,6 @@ exit_psupply:
        if (chip->gpio_detect)
                gpio_free(pdata->battery_detect);
 
-       kfree(chip);
-
        return rc;
 }
 
@@ -938,9 +936,6 @@ static int sbs_remove(struct i2c_client *client)
 
        cancel_delayed_work_sync(&chip->work);
 
-       kfree(chip);
-       chip = NULL;
-
        return 0;
 }