greybus: power_supply: fix unregister on error path
authorRui Miguel Silva <rui.silva@linaro.org>
Fri, 8 Jan 2016 13:53:43 +0000 (13:53 +0000)
committerGreg Kroah-Hartman <gregkh@google.com>
Tue, 12 Jan 2016 03:18:14 +0000 (19:18 -0800)
If setup fail the release for each supply needs to know the status at
unregister time. So, add the field to the structure, update it at setup
time and use it at release.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Reported-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/power_supply.c

index 1ce57f6333dad44f51a57e2d20bcb37dea3135ba..764d2f640164dca73c9eb0b860107d63aef2f3bd 100644 (file)
@@ -25,6 +25,7 @@ struct gb_power_supply_prop {
 
 struct gb_power_supply {
        u8                              id;
+       bool                            registered;
 #ifdef DRIVER_OWNS_PSY_STRUCT
        struct power_supply             psy;
 #define to_gb_power_supply(x) container_of(x, struct gb_power_supply, psy)
@@ -557,9 +558,11 @@ static void _gb_power_supply_release(struct gb_power_supply *gbpsy)
 
        cancel_delayed_work_sync(&gbpsy->work);
 #ifdef DRIVER_OWNS_PSY_STRUCT
-       power_supply_unregister(&gbpsy->psy);
+       if (gbpsy->registered)
+               power_supply_unregister(&gbpsy->psy);
 #else
-       power_supply_unregister(gbpsy->psy);
+       if (gbpsy->registered)
+               power_supply_unregister(gbpsy->psy);
 #endif
 
        _gb_power_supply_free(gbpsy);
@@ -628,6 +631,9 @@ static int gb_power_supply_config(struct gb_power_supplies *supplies, int id)
        schedule_delayed_work(&gbpsy->work, 0);
 
 out:
+       /* if everything went fine just mark it for release code to know */
+       if (ret == 0)
+               gbpsy->registered = true;
        return ret;
 }