From: Phil Reid Date: Mon, 25 Jul 2016 02:42:57 +0000 (+0800) Subject: power: sbs-battery: Use devm_kzalloc to alloc data X-Git-Tag: v4.9-rc1~100^2~42 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=9239a86f0976b58d3da7a2261ed659ac9eba0f25;p=linux.git power: sbs-battery: Use devm_kzalloc to alloc data Use devm_kzalloc to allow memory to be freed automatically on driver probe failure or removal. Signed-off-by: Phil Reid Signed-off-by: Sebastian Reichel --- diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c index 768b9fcb58ea..20f3be6f5b9a 100644 --- a/drivers/power/supply/sbs-battery.c +++ b/drivers/power/supply/sbs-battery.c @@ -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 @@ static int sbs_probe(struct i2c_client *client, 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; }