Skip to contentSkip to conversation

i2c: off by one issue

PATCH In review Dan Carpenter 2 participants 2 messages Apr 7, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: off by one issue

If we don't find the correct rate, we want to end the loop with "i" pointing to the last element in the array.

---
I will be offline for a while, sorry if I delay replying.

drivers/i2c/busses/i2c-stu300.c +1 -1
index 1f5b38b..495be45 100644
@@ -498,7 +498,7 @@ static int stu300_set_clk(struct stu300_dev *dev, unsigned long clkrate)
 	int i = 0;
 
 	/* Locate the apropriate clock setting */
-	while (i < ARRAY_SIZE(stu300_clktable) &&
+	while (i < ARRAY_SIZE(stu300_clktable) - 1 &&
 	       stu300_clktable[i].rate < clkrate)
 		i++;