power: supply: bq27xxx: Don't report missing battery properties as invalid
PATCH 1/1 power: supply: bq27xxx: Don't report missing battery properties as invalid
When the device tree leaves out energy-full-design-microwatt-hours or charge-full-design-microamp-hours, power_supply_get_battery_info() sets the field to -EINVAL. bq27xxx_battery_settings() then compares it with an unsigned limit, so -EINVAL becomes a large positive number and the missing property is also reported as invalid:
bq27xxx-battery 10-0055: missing battery:energy-full-design-microwatt-hours bq27xxx-battery 10-0055: invalid battery:energy-full-design-microwatt-hours -22
Skip the range check when the value is -EINVAL, as the check for voltage-min-design-microvolt below already does. The field is -EINVAL either way, so only the message goes away.
Tested on a OnePlus 6T (bq27411), whose device tree has the charge but not the energy property: only the "missing" warning remains.
An AI assistant helped find and test this change and drafted this message.
--- drivers/power/supply/bq27xxx_battery.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/power/supply/bq27xxx_battery.c +4 -2
@@ -1548,7 +1548,8 @@ static void bq27xxx_battery_settings(struct bq27xxx_device_info *di)/* assume min == 0 */ max = di->dm_regs[BQ27XXX_DM_DESIGN_ENERGY ].max; -if (info->energy_full_design_uwh > max *1000 ) { +if (info->energy_full_design_uwh != -EINVAL && + info->energy_full_design_uwh > max *1000 ) {dev_err (di->dev,"invalid battery:energy-full-design-microwatt-hours %d\n" , info->energy_full_design_uwh); info->energy_full_design_uwh = -EINVAL ;
@@ -1556,7 +1557,8 @@ static void bq27xxx_battery_settings(struct bq27xxx_device_info *di)/* assume min == 0 */ max = di->dm_regs[BQ27XXX_DM_DESIGN_CAPACITY ].max; -if (info->charge_full_design_uah > max *1000 ) { +if (info->charge_full_design_uah != -EINVAL && + info->charge_full_design_uah > max *1000 ) {dev_err (di->dev,"invalid battery:charge-full-design-microamp-hours %d\n" , info->charge_full_design_uah); info->charge_full_design_uah = -EINVAL ;
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.56.0
Sebastian Reichel
AppliedQuoted 10 lines · Hex Lindqvist
When the device tree leaves out energy-full-design-microwatt-hours or charge-full-design-microamp-hours,
power_supply_get_battery_info()sets the field to-EINVAL.bq27xxx_battery_settings()then compares it with an unsigned limit, so-EINVALbecomes a large positive number and the missing property is also reported as invalid:bq27xxx-battery 10-0055: missing battery:energy-full-design-microwatt-hours bq27xxx-battery 10-0055: invalid battery:energy-full-design-microwatt-hours -22
[...]
Applied, thanks!
[1/1] power: supply: bq27xxx: Don't report missing battery properties as invalid
commit: 376589960dd90ed09679a2c835c288a0f5456940
Best regards,
Signature · 1 line
Sebastian Reichel <[email protected]>