[PATCH] ieee1394: sbp2: fix race condition in state change

From: Stefan Richter
Date: Sat Nov 29 2008 - 08:56:24 EST


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

Signed-off-by: Stefan Richter <stefanr@xxxxxxxxxxxxxxxxx>
---
drivers/ieee1394/sbp2.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

Index: linux/drivers/ieee1394/sbp2.c
===================================================================
--- linux.orig/drivers/ieee1394/sbp2.c
+++ linux/drivers/ieee1394/sbp2.c
@@ -895,12 +895,13 @@ static void sbp2_host_reset(struct hpsb_
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);
}


--
Stefan Richter
-=====-==--- =-== ===-=
http://arcgraph.de/sr/

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/