Skip to contentSkip to conversation

scsi: aic7xxx: fix ahc_delay and ahd_delay

PATCH New Denys Vlasenko 1 participant 1 message Oct 14, 2016

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

PATCH 1/1 scsi: aic7xxx: fix ahc_delay and ahd_delay

They are buggy:

        while (usec > 0)
               udelay(usec % 1024);
               usec -= 1024;

For example, for usec = 100*1024 + 1, old code will udelay(1) 101 times, i.e. it will be approximately equivalent to udelay(101),
not the expected udelay(102400).

This did not bite because all callers use values far from "pathological" ones, such as 500 and 1000 - these work fine with buggy code.

This was reported in 2006 but was missed.

---
 drivers/scsi/aic7xxx/aic79xx_osm.c | 7 ++++---
 drivers/scsi/aic7xxx/aic7xxx_osm.c | 7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/scsi/aic7xxx/aic79xx_osm.c +4 -3
index 2588b8f..e7a7838 100644
@@ -380,9 +380,10 @@ ahd_delay(long usec)
 	 * multi-millisecond waits.  Wait at most
 	 * 1024us per call.
 	 */
-	while (usec > 0) {
-		udelay(usec % 1024);
-		usec -= 1024;
+	udelay(usec & 1023);
+	usec >>= 10;
+	while (--usec >= 0) {
+		udelay(1024);
 	}
 }
 
drivers/scsi/aic7xxx/aic7xxx_osm.c +4 -3
index fc6a831..c81798e 100644
@@ -388,9 +388,10 @@ ahc_delay(long usec)
 	 * multi-millisecond waits.  Wait at most
 	 * 1024us per call.
 	 */
-	while (usec > 0) {
-		udelay(usec % 1024);
-		usec -= 1024;
+	udelay(usec & 1023);
+	usec >>= 10;
+	while (--usec >= 0) {
+		udelay(1024);
 	}
 }
 
Signature · 1 line
2.9.2