Skip to contentSkip to conversation

drivers/power/da9052-battery.c: avoid out-of-range array access

PATCH Anton Vorontsov 1 participant 1 message Jan 6, 2013 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Anton Vorontsov

author Applied
#1 lore raw
Quoted 5 lines · Nickolai Zeldovich

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.

---

Applied, thanks!

Quoted 18 lines
 drivers/power/da9052-battery.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/da9052-battery.c +1 -1
index 3c5c2e4..08193fe 100644
@@ -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;
Signature · 1 line
1.7.10.4