Skip to content

Commit

Permalink
power: supply: ab8500_fg: Init battery data in bind()
Browse files Browse the repository at this point in the history
We were assigning some battery data state in probe() but
this is insecure as it depends on the proper probe order
between the components: the charger must probe first so
that the battery data is populated. Move the init to
the bind() call which is certain to happen after the
probe of the master and all components has happened.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
  • Loading branch information
Linus Walleij authored and Sebastian Reichel committed Nov 22, 2021
1 parent 2a5f418 commit fc81c43
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/power/supply/ab8500_fg.c
Original file line number Diff line number Diff line change
Expand Up @@ -3023,6 +3023,10 @@ static int ab8500_fg_bind(struct device *dev, struct device *master,
return -ENOMEM;
}

di->bat_cap.max_mah_design = di->bm->bi.charge_full_design_uah;
di->bat_cap.max_mah = di->bat_cap.max_mah_design;
di->vbat_nom_uv = di->bm->bi.voltage_max_design_uv;

/* Start the coulomb counter */
ab8500_fg_coulomb_counter(di, true);
/* Run the FG algorithm */
Expand Down Expand Up @@ -3082,10 +3086,6 @@ static int ab8500_fg_probe(struct platform_device *pdev)
psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);
psy_cfg.drv_data = di;

di->bat_cap.max_mah_design = di->bm->bi.charge_full_design_uah;
di->bat_cap.max_mah = di->bat_cap.max_mah_design;
di->vbat_nom_uv = di->bm->bi.voltage_max_design_uv;

di->init_capacity = true;

ab8500_fg_charge_state_to(di, AB8500_FG_CHARGE_INIT);
Expand Down

0 comments on commit fc81c43

Please sign in to comment.