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

Commit 1025a1f7 authored by Jishnu Prakash's avatar Jishnu Prakash Committed by Gerrit - the friendly Code Review server
Browse files

power: fg-alg: Fix race condition in Time To Empty (TTE)



There is a possible race condition in TTE where it might cause
Out of Bound array access because the buffer gets cleared.
Fix this by adding a lock to TTE.

Change-Id: I2074c42aac9655967a8f77a84362507c3954cf20
Signed-off-by: default avatarJishnu Prakash <jprakash@codeaurora.org>
parent 687c0ac9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1545,15 +1545,18 @@ int ttf_get_time_to_empty(struct ttf *ttf, int *val)
		return 0;
	}

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

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