Skip to contentSkip to conversation

ahci: fix hang on failed softreset

PATCH Applied Tejun Heo 2 participants 2 messages Aug 27, 2010 – Sep 5, 2010 libata

lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/1 ahci: fix hang on failed softreset

ahci_do_softreset() compared the current time and deadline in reverse when calculating timeout for SRST issue. The result is that if @deadline is in future, SRST is issued with 0 timeout, which hasn't caused any problem because it later waits for DRDY with the correct timeout. If deadline is already exceeded by the time SRST is about to be issued, the timeout calculation underflows and if the device doesn't respond, timeout doesn't trigger for a _very_ long time.

Reverse the incorrect comparison order.

---
 drivers/ata/libahci.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/libahci.c +1 -1
index 81e772a..98c80e1 100644
@@ -1320,7 +1320,7 @@ int ahci_do_softreset(struct ata_link *link, unsigned int *class,
 	/* issue the first D2H Register FIS */
 	msecs = 0;
 	now = jiffies;
-	if (time_after(now, deadline))
+	if (time_after(deadline, now))
 		msecs = jiffies_to_msecs(deadline - now);
 
 	tf.ctl |= ATA_SRST;
Applied
#1 lore raw
Quoted 10 lines · Tejun Heo

ahci_do_softreset() compared the current time and deadline in reverse when calculating timeout for SRST issue. The result is that if @deadline is in future, SRST is issued with 0 timeout, which hasn't caused any problem because it later waits for DRDY with the correct timeout. If deadline is already exceeded by the time SRST is about to be issued, the timeout calculation underflows and if the device doesn't respond, timeout doesn't trigger for a _very_ long time.

Reverse the incorrect comparison order.

Quoted 7 lines
---
  drivers/ata/libahci.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

applied, good catch, sorry for the delay.