diff mbox series

power: supply: core: Break capacity loop

Message ID 20211114231207.1877495-1-linus.walleij@linaro.org (mailing list archive)
State Not Applicable, archived
Headers show
Series power: supply: core: Break capacity loop | expand

Commit Message

Linus Walleij Nov. 14, 2021, 11:12 p.m. UTC
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>
---
 drivers/power/supply/power_supply_core.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Baolin Wang Nov. 15, 2021, 10:24 a.m. UTC | #1
On 2021/11/15 7:12, Linus Walleij wrote:
> 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>

LGTM.
Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.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 038e35ea7fbe..885c92dc0379 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -852,6 +852,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) {
>
Sebastian Reichel Nov. 15, 2021, 3:19 p.m. UTC | #2
Hi,

On Mon, Nov 15, 2021 at 06:24:49PM +0800, Baolin Wang wrote:
> 
> 
> On 2021/11/15 7:12, Linus Walleij wrote:
> > 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>
> 
> LGTM.
> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com>

Thanks, queued to fixes branch.

-- Sebastian

> > ---
> >   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 038e35ea7fbe..885c92dc0379 100644
> > --- a/drivers/power/supply/power_supply_core.c
> > +++ b/drivers/power/supply/power_supply_core.c
> > @@ -852,6 +852,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) {
> >
diff mbox series

Patch

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 038e35ea7fbe..885c92dc0379 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -852,6 +852,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) {