Skip to content

Commit

Permalink
fix race that can give duplicate host number
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Joe Eykholt authored and James Bottomley committed Jun 21, 2009
1 parent 1119865 commit 30c9afa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/scsi/hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 30c9afa

Please sign in to comment.