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)
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);
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;
}