Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82e0a32e authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "power: qpnp-fg-gen3: Fix race condition in Time To Empty (TTE)"

parents 85255aa0 55da5994
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -3270,15 +3270,18 @@ static int fg_get_time_to_empty(struct fg_dev *fg, int *val)
	struct fg_gen3_chip *chip = container_of(fg, struct fg_gen3_chip, fg);
	int rc, ibatt_avg, msoc, full_soc, act_cap_mah, divisor;

	mutex_lock(&chip->ttf.lock);
	rc = fg_circ_buf_median(&chip->ttf.ibatt, &ibatt_avg);
	if (rc < 0) {
		/* try to get instantaneous current */
		rc = fg_get_battery_current(fg, &ibatt_avg);
		if (rc < 0) {
			pr_err("failed to get battery current, rc=%d\n", rc);
			mutex_unlock(&chip->ttf.lock);
			return rc;
		}
	}
	mutex_unlock(&chip->ttf.lock);

	ibatt_avg /= MILLI_UNIT;
	/* clamp ibatt_avg to 100mA */