ieee1394: sbp2: fix race condition in state change

An intermediate transition from _RUNNING to _IN_SHUTDOWN could have been
missed by the former code.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
This commit is contained in:
Stefan Richter 2008-11-29 14:55:47 +01:00
parent e47c1feb17
commit 2642b11295
1 changed files with 5 additions and 4 deletions

View File

@ -895,12 +895,13 @@ static void sbp2_host_reset(struct hpsb_host *host)
return; return;
read_lock_irqsave(&sbp2_hi_logical_units_lock, flags); read_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
list_for_each_entry(lu, &hi->logical_units, lu_list) list_for_each_entry(lu, &hi->logical_units, lu_list)
if (likely(atomic_read(&lu->state) != if (atomic_cmpxchg(&lu->state,
SBP2LU_STATE_IN_SHUTDOWN)) { SBP2LU_STATE_RUNNING, SBP2LU_STATE_IN_RESET)
atomic_set(&lu->state, SBP2LU_STATE_IN_RESET); == SBP2LU_STATE_RUNNING)
scsi_block_requests(lu->shost); scsi_block_requests(lu->shost);
}
read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags); read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
} }