* [PATCH] scsi: fix duplicate host number
@ 2009-06-16 6:22 Joe Eykholt
2009-06-16 17:01 ` Stefan Richter
0 siblings, 1 reply; 3+ messages in thread
From: Joe Eykholt @ 2009-06-16 6:22 UTC (permalink / raw)
To: linux-scsi
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.
Signed-off-by: Joe Eykholt <jeykholt@cisco.com>
---
drivers/scsi/hosts.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 89d41a4..e9aaba9 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,7 @@ 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 */
+ shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
shost->dma_channel = 0xff;
/* These three are default values which can be overridden */
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] scsi: fix duplicate host number
2009-06-16 6:22 [PATCH] scsi: fix duplicate host number Joe Eykholt
@ 2009-06-16 17:01 ` Stefan Richter
2009-06-16 21:02 ` Joe Eykholt
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Richter @ 2009-06-16 17:01 UTC (permalink / raw)
To: Joe Eykholt; +Cc: linux-scsi
Joe Eykholt wrote:
> Subtract 1, so that scsi_host still starts with 0.
...
> -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,7 @@ 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 */
> + shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
Can also be written
static atomic_t scsi_host_next_hn = ATOMIC_INIT(-1);
...
shost->host_no = atomic_inc_return(&scsi_host_next_hn);
--
Stefan Richter
-=====-==--= -==- =----
http://arcgraph.de/sr/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] scsi: fix duplicate host number
2009-06-16 17:01 ` Stefan Richter
@ 2009-06-16 21:02 ` Joe Eykholt
0 siblings, 0 replies; 3+ messages in thread
From: Joe Eykholt @ 2009-06-16 21:02 UTC (permalink / raw)
To: Stefan Richter; +Cc: linux-scsi
Stefan Richter wrote:
> Joe Eykholt wrote:
>> Subtract 1, so that scsi_host still starts with 0.
> ...
>> -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,7 @@ 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 */
>> + shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
>
> Can also be written
>
> static atomic_t scsi_host_next_hn = ATOMIC_INIT(-1);
> ...
> shost->host_no = atomic_inc_return(&scsi_host_next_hn);
Yes, I considered that, but then the variable name and comment wouldn't be correct.
Also, the initializer adds 4 bytes to the initialized data section, and
the code for -1 should increase text size by less than that, so I think it's a wash.
An atomic_fetch_and_add() would be handy.
Cheers,
Joe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-06-16 21:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-16 6:22 [PATCH] scsi: fix duplicate host number Joe Eykholt
2009-06-16 17:01 ` Stefan Richter
2009-06-16 21:02 ` Joe Eykholt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.