From: Linus Walleij linus.walleij@linaro.org
stable inclusion from stable-v5.10.91 commit 998d157e3b2acf5f605e49805f4c34947f3bad56 bugzilla: 186187 https://gitee.com/openeuler/kernel/issues/I4SI2C
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=...
--------------------------------
commit 51c7b6a0398f54b9120795796a4cff4fc9634f7d upstream.
We should not go on looking for more capacity tables after we realize we have looked at the last one in power_supply_find_ocv2cap_table().
Fixes: 3afb50d7125b ("power: supply: core: Add some helpers to use the battery OCV capacity table") Cc: Chunyan Zhang chunyan.zhang@unisoc.com Cc: Baolin Wang baolin.wang@linux.alibaba.com Signed-off-by: Linus Walleij linus.walleij@linaro.org Reviewed-by: Baolin Wang baolin.wang@linux.alibaba.com Signed-off-by: Sebastian Reichel sebastian.reichel@collabora.com Signed-off-by: Greg Kroah-Hartman gregkh@linuxfoundation.org Signed-off-by: Chen Jun chenjun102@huawei.com Signed-off-by: Zheng Zengkai zhengzengkai@huawei.com --- drivers/power/supply/power_supply_core.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index 38e3aa642131..280c54c23e37 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -834,6 +834,10 @@ power_supply_find_ocv2cap_table(struct power_supply_battery_info *info, return NULL;
for (i = 0; i < POWER_SUPPLY_OCV_TEMP_MAX; i++) { + /* Out of capacity tables */ + if (!info->ocv_table[i]) + break; + temp_diff = abs(info->ocv_temp[i] - temp);
if (temp_diff < best_temp_diff) {