From: Rui Miguel Silva Date: Fri, 8 Jan 2016 13:53:43 +0000 (+0000) Subject: greybus: power_supply: fix unregister on error path X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ff85f723ca362986dc984217433cbdd133fc03d6;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git 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 Reported-by: Johan Hovold Reviewed-by: Johan Hovold Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/power_supply.c b/drivers/staging/greybus/power_supply.c index 1ce57f6333da..764d2f640164 100644 --- a/drivers/staging/greybus/power_supply.c +++ b/drivers/staging/greybus/power_supply.c @@ -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; }