From: Stefan Richter Date: Sat, 29 Nov 2008 13:55:47 +0000 (+0100) Subject: ieee1394: sbp2: fix race condition in state change X-Git-Tag: v2.6.28-rc7~28^2 X-Git-Url: http://pilppa.com/gitweb/?a=commitdiff_plain;h=2642b11295ebcc94843045933061bfbb263fce7f;p=linux-2.6-omap-h63xx.git 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 --- diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index 3f5dbcb2160..a373c18cf7b 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -895,12 +895,13 @@ static void sbp2_host_reset(struct hpsb_host *host) return; read_lock_irqsave(&sbp2_hi_logical_units_lock, flags); + list_for_each_entry(lu, &hi->logical_units, lu_list) - if (likely(atomic_read(&lu->state) != - SBP2LU_STATE_IN_SHUTDOWN)) { - atomic_set(&lu->state, SBP2LU_STATE_IN_RESET); + if (atomic_cmpxchg(&lu->state, + SBP2LU_STATE_RUNNING, SBP2LU_STATE_IN_RESET) + == SBP2LU_STATE_RUNNING) scsi_block_requests(lu->shost); - } + read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags); }