power: qpnp-smbcharger: fix bug in find_closest_in_array

This method uses a variable to track the current closest value's
index. The implementation was checking the distance between the
value and this index instead of the value at that index. Fix
this bug.

CRs-Fixed: 923805
Change-Id: Iac3cc125c4c5fabbe027ec38890d5c47e199187e
Signed-off-by: Devesh Jhunjhunwala <deveshj@codeaurora.org>
This commit is contained in:
Devesh Jhunjhunwala 2015-10-22 01:51:17 -07:00 committed by Gerrit - the friendly Code Review server
parent a1206eb583
commit f02f1565b9
1 changed files with 1 additions and 1 deletions

View File

@ -1058,7 +1058,7 @@ static int find_closest_in_array(const int *arr, int len, int val)
if (len == 0)
return closest;
for (i = 0; i < len; i++)
if (abs(val - arr[i]) < abs(val - closest))
if (abs(val - arr[i]) < abs(val - arr[closest]))
closest = i;
return closest;