public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Devendra Naga <develkernel412222@gmail.com>
To: Anton Vorontsov <cbou@mail.ru>,
	David Woodhouse <dwmw2@infradead.org>,
	ramakrishna.pallala@intel.com, linux-kernel@vger.kernel.org
Cc: Devendra Naga <develkernel412222@gmail.com>
Subject: [PATCH V2 2/2] lp8727_charger: unregister power supply at error path of lp8727_register_psy
Date: Mon, 30 Jul 2012 16:10:46 +0545	[thread overview]
Message-ID: <1343643946-12815-1-git-send-email-develkernel412222@gmail.com> (raw)

if usb power supply registration fails,
        we wont unregister the ac power supply
if battery power supply registration fails,
        we wont unregister the usb, and ac supply,

take care of those things and also no need of goto -err_mem: at the fail case of
kzalloc simply can have return -ENOMEM

Signed-off-by: Devendra Naga <develkernel412222@gmail.com>
---
Changes since V2:
 * fix the comments from the Ramakrishna (ramakrishna.pallala@intel.com)
quoting his comments:

>       if (power_supply_register(pchg->dev, &psy->usb))
> -             goto err_psy;
> +             goto err_psy_ac;

"err_psy_ac" label name is confusing. Why can't you use err_psy_usb

>       if (power_supply_register(pchg->dev, &psy->batt))
> -             goto err_psy;
> +             goto err_psy_usb;

Same here, why don't you use err_psy_batt

 drivers/power/lp8727_charger.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c
index 6c0e0f9..8fb1c0f 100644
--- a/drivers/power/lp8727_charger.c
+++ b/drivers/power/lp8727_charger.c
@@ -362,7 +362,7 @@ static int lp8727_register_psy(struct lp8727_chg *pchg)
 
 	psy = kzalloc(sizeof(*psy), GFP_KERNEL);
 	if (!psy)
-		goto err_mem;
+		return -ENOMEM;
 
 	pchg->psy = psy;
 
@@ -386,7 +386,7 @@ static int lp8727_register_psy(struct lp8727_chg *pchg)
 	psy->usb.num_supplicants = ARRAY_SIZE(battery_supplied_to);
 
 	if (power_supply_register(pchg->dev, &psy->usb))
-		goto err_psy;
+		goto err_psy_usb;
 
 	psy->batt.name = "main_batt";
 	psy->batt.type = POWER_SUPPLY_TYPE_BATTERY;
@@ -396,12 +396,14 @@ static int lp8727_register_psy(struct lp8727_chg *pchg)
 	psy->batt.external_power_changed = lp8727_charger_changed;
 
 	if (power_supply_register(pchg->dev, &psy->batt))
-		goto err_psy;
+		goto err_psy_batt;
 
 	return 0;
 
-err_mem:
-	return -ENOMEM;
+err_psy_batt:
+	power_supply_unregister(&psy->usb);
+err_psy_usb:
+	power_supply_unregister(&psy->ac);
 err_psy:
 	kfree(psy);
 	return -EPERM;
-- 
1.7.9.5


                 reply	other threads:[~2012-07-30 10:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1343643946-12815-1-git-send-email-develkernel412222@gmail.com \
    --to=develkernel412222@gmail.com \
    --cc=cbou@mail.ru \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ramakrishna.pallala@intel.com \
    /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