Skip to content

Commit a464189

Browse files
EOltmannsJeff Garzik
authored andcommitted
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>
1 parent 3c32428 commit a464189

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/ata/libata-scsi.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static ssize_t ata_scsi_park_show(struct device *device,
190190
struct ata_port *ap;
191191
struct ata_link *link;
192192
struct ata_device *dev;
193-
unsigned long flags;
193+
unsigned long flags, now;
194194
unsigned int uninitialized_var(msecs);
195195
int rc = 0;
196196

@@ -208,10 +208,11 @@ static ssize_t ata_scsi_park_show(struct device *device,
208208
}
209209

210210
link = dev->link;
211+
now = jiffies;
211212
if (ap->pflags & ATA_PFLAG_EH_IN_PROGRESS &&
212213
link->eh_context.unloaded_mask & (1 << dev->devno) &&
213-
time_after(dev->unpark_deadline, jiffies))
214-
msecs = jiffies_to_msecs(dev->unpark_deadline - jiffies);
214+
time_after(dev->unpark_deadline, now))
215+
msecs = jiffies_to_msecs(dev->unpark_deadline - now);
215216
else
216217
msecs = 0;
217218

0 commit comments

Comments
 (0)