libata: Fix a potential race condition in ata_scsi_park_show()

Peter Moulder has pointed out that there is a slight chance that a
negative value might be passed to jiffies_to_msecs() in
ata_scsi_park_show(). This is fixed by saving the value of jiffies in a
local variable, thus also reducing code since the volatile variable
jiffies is accessed only once.

Signed-off-by: Elias Oltmanns <eo@nebensachen.de>
Signed-off-by: Tejun Heo <tj.kernel.org>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>

authored by Elias Oltmanns and committed by Jeff Garzik a464189d 3c324283

+4 -3
+4 -3
drivers/ata/libata-scsi.c
··· 190 struct ata_port *ap; 191 struct ata_link *link; 192 struct ata_device *dev; 193 - unsigned long flags; 194 unsigned int uninitialized_var(msecs); 195 int rc = 0; 196 ··· 208 } 209 210 link = dev->link; 211 if (ap->pflags & ATA_PFLAG_EH_IN_PROGRESS && 212 link->eh_context.unloaded_mask & (1 << dev->devno) && 213 - time_after(dev->unpark_deadline, jiffies)) 214 - msecs = jiffies_to_msecs(dev->unpark_deadline - jiffies); 215 else 216 msecs = 0; 217
··· 190 struct ata_port *ap; 191 struct ata_link *link; 192 struct ata_device *dev; 193 + unsigned long flags, now; 194 unsigned int uninitialized_var(msecs); 195 int rc = 0; 196 ··· 208 } 209 210 link = dev->link; 211 + now = jiffies; 212 if (ap->pflags & ATA_PFLAG_EH_IN_PROGRESS && 213 link->eh_context.unloaded_mask & (1 << dev->devno) && 214 + time_after(dev->unpark_deadline, now)) 215 + msecs = jiffies_to_msecs(dev->unpark_deadline - now); 216 else 217 msecs = 0; 218