Merge "power: qpnp-fg-gen3: Fix possible integer overflow"
This commit is contained in:
commit
eaeca093b4
1 changed files with 11 additions and 5 deletions
|
@ -491,7 +491,7 @@ static void fg_encode_default(struct fg_sram_param *sp,
|
||||||
int i, mask = 0xff;
|
int i, mask = 0xff;
|
||||||
int64_t temp;
|
int64_t temp;
|
||||||
|
|
||||||
temp = DIV_ROUND_CLOSEST(val * sp[id].numrtr, sp[id].denmtr);
|
temp = (int64_t)div_s64((s64)val * sp[id].numrtr, sp[id].denmtr);
|
||||||
pr_debug("temp: %llx id: %d, val: %d, buf: [ ", temp, id, val);
|
pr_debug("temp: %llx id: %d, val: %d, buf: [ ", temp, id, val);
|
||||||
for (i = 0; i < sp[id].len; i++) {
|
for (i = 0; i < sp[id].len; i++) {
|
||||||
buf[i] = temp & mask;
|
buf[i] = temp & mask;
|
||||||
|
@ -1320,9 +1320,16 @@ static int fg_cap_learning_process_full_data(struct fg_chip *chip)
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_soc_delta_pct = DIV_ROUND_CLOSEST(
|
cc_soc_delta_pct =
|
||||||
abs(cc_soc_sw - chip->cl.init_cc_soc_sw) * 100,
|
div64_s64((int64_t)(cc_soc_sw - chip->cl.init_cc_soc_sw) * 100,
|
||||||
CC_SOC_30BIT);
|
CC_SOC_30BIT);
|
||||||
|
|
||||||
|
/* If the delta is < 50%, then skip processing full data */
|
||||||
|
if (cc_soc_delta_pct < 50) {
|
||||||
|
pr_err("cc_soc_delta_pct: %d\n", cc_soc_delta_pct);
|
||||||
|
return -ERANGE;
|
||||||
|
}
|
||||||
|
|
||||||
delta_cc_uah = div64_s64(chip->cl.learned_cc_uah * cc_soc_delta_pct,
|
delta_cc_uah = div64_s64(chip->cl.learned_cc_uah * cc_soc_delta_pct,
|
||||||
100);
|
100);
|
||||||
chip->cl.final_cc_uah = chip->cl.init_cc_uah + delta_cc_uah;
|
chip->cl.final_cc_uah = chip->cl.init_cc_uah + delta_cc_uah;
|
||||||
|
@ -1392,7 +1399,6 @@ out:
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FULL_SOC_RAW 255
|
|
||||||
static void fg_cap_learning_update(struct fg_chip *chip)
|
static void fg_cap_learning_update(struct fg_chip *chip)
|
||||||
{
|
{
|
||||||
int rc, batt_soc, batt_soc_msb;
|
int rc, batt_soc, batt_soc_msb;
|
||||||
|
|
Loading…
Add table
Reference in a new issue