summaryrefslogtreecommitdiffstats
path: root/drivers/scsi/hosts.c
diff options
context:
space:
mode:
authorJoe Eykholt <jeykholt@cisco.com>2009-06-15 23:22:14 -0700
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2009-06-21 10:52:42 -0500
commit30c9afa6cc477f6f21f8a0b36f3b81080941a0c9 (patch)
tree863c391cc13e13d005e55096ff3436e973c06453 /drivers/scsi/hosts.c
parent111986593561fc4c94a1fba3f3cd84476fb40b22 (diff)
downloadlinux-30c9afa6cc477f6f21f8a0b36f3b81080941a0c9.tar.bz2
fix race that can give duplicate host number
Just once, two fcoe instances got the same host number from scsi_add_host(). Use atomic_t and atomic_inc_return() to get next host number. Subtract 1, so that scsi_host still starts with 0. [jejb: added comment about unusual subtraction] Signed-off-by: Joe Eykholt <jeykholt@cisco.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/scsi/hosts.c')
-rw-r--r--drivers/scsi/hosts.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 89d41a424b33..5fd2da494d08 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -40,7 +40,7 @@
#include "scsi_logging.h"
-static int scsi_host_next_hn; /* host_no for next new host */
+static atomic_t scsi_host_next_hn; /* host_no for next new host */
static void scsi_host_cls_release(struct device *dev)
@@ -333,7 +333,11 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
mutex_init(&shost->scan_mutex);
- shost->host_no = scsi_host_next_hn++; /* XXX(hch): still racy */
+ /*
+ * subtract one because we increment first then return, but we need to
+ * know what the next host number was before increment
+ */
+ shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
shost->dma_channel = 0xff;
/* These three are default values which can be overridden */