power: max77843_charger: fix to unregister extcon interest 48/83948/2 accepted/tizen/common/20160816.130236 accepted/tizen/ivi/20160816.233654 accepted/tizen/mobile/20160816.233602 accepted/tizen/tv/20160816.233620 accepted/tizen/wearable/20160816.233638 submit/tizen/20160816.052346
authorDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 16 Aug 2016 02:44:16 +0000 (11:44 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 16 Aug 2016 04:21:06 +0000 (13:21 +0900)
The extcon interest should be unregistered when probe fails or the driver is
removed. This patch fixes to call extcon_unregister_interest() on both cases.

Change-Id: I6639d7a4685c11985d08e642ebb32eb031b3326d
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
drivers/power/max77843_charger.c

index ed8df6f..2c59672 100644 (file)
@@ -496,11 +496,21 @@ static int max77843_extcon_register(struct max77843_charger *charger)
                        dev_err(charger->dev, "Cannot register OTG notifier\n");
                        return ret;
                }
+
+               charger->edev = edev;
        }
 
        return 0;
 }
 
+static void max77843_extcon_unregister(struct max77843_charger *charger)
+{
+       if (charger->edev) {
+               extcon_unregister_interest(&charger->otg_cable_nb);
+               charger->edev = NULL;
+       }
+}
+
 static const struct power_supply_desc max77843_charger_desc = {
        .name           = "max77843-charger",
        .type           = POWER_SUPPLY_TYPE_MAINS,
@@ -533,23 +543,28 @@ static int max77843_charger_probe(struct platform_device *pdev)
                return ret;
 
        charger->info = max77843_charger_dt_init(pdev);
-       if (IS_ERR(charger->info))
-               return PTR_ERR(charger->info);
-
+       if (IS_ERR(charger->info)) {
+               ret = PTR_ERR(charger->info);
+               goto err_extcon;
+       }
 
        ret = max77843_charger_init(charger);
        if (ret)
-               return ret;
+               goto err_extcon;
 
        charger->psy = power_supply_register(&pdev->dev, &max77843_charger_desc, &psy_cfg);
        if (IS_ERR(charger->psy)) {
                ret = PTR_ERR(charger->psy);
                dev_err(&pdev->dev,
                        "Failed to register power supply %d\n", ret);
-               return ret;
+               goto err_extcon;
        }
 
        return 0;
+
+err_extcon:
+       max77843_extcon_unregister(charger);
+       return ret;
 }
 
 static int max77843_charger_remove(struct platform_device *pdev)
@@ -557,7 +572,7 @@ static int max77843_charger_remove(struct platform_device *pdev)
        struct max77843_charger *charger = platform_get_drvdata(pdev);
 
        power_supply_unregister(charger->psy);
-
+       max77843_extcon_unregister(charger);
        return 0;
 }