Skip to content

Commit

Permalink
da9052-battery: Avoid out-of-range array access
Browse files Browse the repository at this point in the history
Avoid accessing vc_tbl_ref[3], which is one past the end of that array, in
da9052_determine_vc_tbl_index(), by adjusting the loop bound.

(Hint: there is 'i + 1' inside the loop.)

Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
Signed-off-by: Anton Vorontsov <anton@enomsg.org>
  • Loading branch information
Nickolai Zeldovich authored and Anton Vorontsov committed Jan 6, 2013
1 parent 00edfc6 commit c4f3422
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/power/da9052-battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ static unsigned char da9052_determine_vc_tbl_index(unsigned char adc_temp)
if (adc_temp > vc_tbl_ref[DA9052_VC_TBL_REF_SZ - 1])
return DA9052_VC_TBL_REF_SZ - 1;

for (i = 0; i < DA9052_VC_TBL_REF_SZ; i++) {
for (i = 0; i < DA9052_VC_TBL_REF_SZ - 1; i++) {
if ((adc_temp > vc_tbl_ref[i]) &&
(adc_temp <= DA9052_MEAN(vc_tbl_ref[i], vc_tbl_ref[i + 1])))
return i;
Expand Down

0 comments on commit c4f3422

Please sign in to comment.