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

Commit 70a42125 authored by qctecmdr Service's avatar qctecmdr Service Committed by Gerrit - the friendly Code Review server
Browse files

Merge "power: step-chg-jeita: Clip voltages higher than max allowed"

parents cbc6855d 89556e9d
Loading
Loading
Loading
Loading
+34 −5
Original line number Diff line number Diff line
@@ -347,17 +347,46 @@ static int get_val(struct range_data *range, int hysteresis, int current_index,
	int i;

	*new_index = -EINVAL;
	/* first find the matching index without hysteresis */
	for (i = 0; i < MAX_STEP_CHG_ENTRIES; i++)

	/*
	 * If the threshold is lesser than the minimum allowed range,
	 * return -ENODATA.
	 */
	if (threshold < range[0].low_threshold)
		return -ENODATA;

	/* First try to find the matching index without hysteresis */
	for (i = 0; i < MAX_STEP_CHG_ENTRIES; i++) {
		if (!range[i].high_threshold && !range[i].low_threshold) {
			/* First invalid table entry; exit loop */
			break;
		}

		if (is_between(range[i].low_threshold,
			range[i].high_threshold, threshold)) {
			*new_index = i;
			*val = range[i].value;
			break;
		}
	}

	/* if nothing was found, return -ENODATA */
	if (*new_index == -EINVAL)
	/*
	 * If nothing was found, the threshold exceeds the max range for sure
	 * as the other case where it is lesser than the min range is handled
	 * at the very beginning of this function. Therefore, clip it to the
	 * max allowed range value, which is the one corresponding to the last
	 * valid entry in the battery profile data array.
	 */
	if (*new_index == -EINVAL) {
		if (i == 0) {
			/* Battery profile data array is completely invalid */
			return -ENODATA;
		}

		*new_index = (i - 1);
		*val = range[*new_index].value;
	}

	/*
	 * If we don't have a current_index return this
	 * newfound value. There is no hysterisis from out of range