linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Reid <preid@electromag.com.au>
To: sre@kernel.org, dbaryshkov@gmail.com, dwmw2@infradead.org,
	linux-pm@vger.kernel.org
Cc: Phil Reid <preid@electromag.com.au>
Subject: [PATCH v2 1/4] power: sbs-battery: Use devm_kzalloc to alloc data
Date: Mon, 25 Jul 2016 10:42:57 +0800	[thread overview]
Message-ID: <1469414580-14121-2-git-send-email-preid@electromag.com.au> (raw)
In-Reply-To: <1469414580-14121-1-git-send-email-preid@electromag.com.au>

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>
---
 drivers/power/sbs-battery.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c
index 768b9fc..20f3be6 100644
--- a/drivers/power/sbs-battery.c
+++ b/drivers/power/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 @@ 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;
 }
 
-- 
1.8.3.1


  reply	other threads:[~2016-07-25  2:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-25  2:42 [PATCH v2 0/4] power: sbs-battery fixup gpio detect irq handling Phil Reid
2016-07-25  2:42 ` Phil Reid [this message]
2016-07-25  2:42 ` [PATCH v2 2/4] power: sbs-battery: Request threaded irq and fix dev callback cookie Phil Reid
2016-07-25  2:42 ` [PATCH v2 3/4] power: sbs-battery: Use devm_power_supply_register Phil Reid
2016-07-25  2:43 ` [PATCH v2 4/4] power: sbs-battery: Use gpio_desc and sleeping calls for battery detect Phil Reid
2016-07-30 23:37   ` kbuild test robot
2016-07-31  0:14   ` kbuild test robot
2016-07-31  1:28   ` kbuild test robot
2016-08-15 21:08   ` Sebastian Reichel
2016-08-16  9:35     ` Phil Reid
2016-08-16 10:26       ` Sebastian Reichel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1469414580-14121-2-git-send-email-preid@electromag.com.au \
    --to=preid@electromag.com.au \
    --cc=dbaryshkov@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).