Skip to contentSkip to conversation

Staging: rts_pstor: off by one in for loop

PATCH New Dan Carpenter 1 participant 1 message Mar 29, 2012

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

PATCH 1/1 Staging: rts_pstor: off by one in for loop

I already fixed the other similar for loop in this file. I'm not sure how I missed this one. We use seg_no+1 inside the loop so we can't go right up to the end of the loop.

Also if we don't break out of the loop then we end up past the end of the array, but with this fix we end up on the last element.

drivers/staging/rts_pstor/ms.c +2 -1
index 66341df..f9a4498 100644
@@ -3498,7 +3498,8 @@ static int ms_rw_multi_sector(struct scsi_cmnd *srb, struct rtsx_chip *chip, u32
 
 		log_blk++;
 
-		for (seg_no = 0; seg_no < sizeof(ms_start_idx)/2; seg_no++) {
+		for (seg_no = 0; seg_no < ARRAY_SIZE(ms_start_idx) - 1;
+				seg_no++) {
 			if (log_blk < ms_start_idx[seg_no+1])
 				break;
 		}