Add an activate() callback to the power-supply LED triggers so that the LED being activated will properly reflect the current power-supply state for power-supply devices which are already fully registered when the trigger gets activated. This fixes e.g. wrong LED state (1) when the LED gets registered after the power-supply device. 1) Until the psy driver has a reason to call power_supply_changed() which may take quite a while Signed-off-by: Hans de Goede <hdegoede@xxxxxxxxxx> --- Changes in v2: - Use trigger_to_psy_trigger() macro --- drivers/power/supply/power_supply_leds.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/power/supply/power_supply_leds.c b/drivers/power/supply/power_supply_leds.c index f2d6b8d33707..f4a7e566bea1 100644 --- a/drivers/power/supply/power_supply_leds.c +++ b/drivers/power/supply/power_supply_leds.c @@ -27,6 +27,16 @@ struct power_supply_led_trigger { #define trigger_to_psy_trigger(trigger) \ container_of(trigger, struct power_supply_led_trigger, trig) +static int power_supply_led_trigger_activate(struct led_classdev *led_cdev) +{ + struct power_supply_led_trigger *psy_trig = + trigger_to_psy_trigger(led_cdev->trigger); + + /* Sync current power-supply state to LED being activated */ + power_supply_update_leds(psy_trig->psy); + return 0; +} + static int power_supply_register_led_trigger(struct power_supply *psy, const char *name_template, struct led_trigger **tp, int *err) @@ -46,6 +56,7 @@ static int power_supply_register_led_trigger(struct power_supply *psy, if (!psy_trig->trig.name) goto err_free_trigger; + psy_trig->trig.activate = power_supply_led_trigger_activate; psy_trig->psy = psy; ret = led_trigger_register(&psy_trig->trig); -- 2.45.1