greybus: power_supply: fix unregister on error path

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>
This commit is contained in:
Rui Miguel Silva 2016-01-08 13:53:43 +00:00 committed by Greg Kroah-Hartman
parent 7ccac20d59
commit ff85f723ca
1 changed files with 8 additions and 2 deletions

View 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,8 +558,10 @@ static void _gb_power_supply_release(struct gb_power_supply *gbpsy)
cancel_delayed_work_sync(&gbpsy->work);
#ifdef DRIVER_OWNS_PSY_STRUCT
if (gbpsy->registered)
power_supply_unregister(&gbpsy->psy);
#else
if (gbpsy->registered)
power_supply_unregister(gbpsy->psy);
#endif
@ -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;
}