[PATCH 2/2] lp8727_charger: unregister power supply at error path of lp8727_register_psy

From: Devendra Naga
Date: Sun Jul 29 2012 - 13:46:58 EST


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@xxxxxxxxx>
---
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 699f0ef..401b66e 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_ac;

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_usb;

return 0;

-err_mem:
- return -ENOMEM;
+err_psy_usb:
+ power_supply_unregister(&psy->usb);
+err_psy_ac:
+ power_supply_unregister(&psy->ac);
err_psy:
kfree(psy);
return -EPERM;
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/