Skip to content

Commit

Permalink
pm8001: add a new spinlock to protect the CCB
Browse files Browse the repository at this point in the history
Patch adds a new spinlock to protect the ccb management.
It may happen that concurrent threads become the same tag value
from the 'alloc' function', the spinlock prevents this situation.

Signed-off-by: Tomas Henzl <[email protected]>
Acked-by: Suresh Thiagarajan <[email protected]>
Acked-by: Jack Wang <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
  • Loading branch information
thenzl authored and Christoph Hellwig committed Jul 25, 2014
1 parent 5533abc commit 646cdf0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions drivers/scsi/pm8001/pm8001_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
{
int i;
spin_lock_init(&pm8001_ha->lock);
spin_lock_init(&pm8001_ha->bitmap_lock);
PM8001_INIT_DBG(pm8001_ha,
pm8001_printk("pm8001_alloc: PHY:%x\n",
pm8001_ha->chip->n_phy));
Expand Down
7 changes: 6 additions & 1 deletion drivers/scsi/pm8001/pm8001_sas.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,16 @@ inline int pm8001_tag_alloc(struct pm8001_hba_info *pm8001_ha, u32 *tag_out)
{
unsigned int tag;
void *bitmap = pm8001_ha->tags;
unsigned long flags;

spin_lock_irqsave(&pm8001_ha->bitmap_lock, flags);
tag = find_first_zero_bit(bitmap, pm8001_ha->tags_num);
if (tag >= pm8001_ha->tags_num)
if (tag >= pm8001_ha->tags_num) {
spin_unlock_irqrestore(&pm8001_ha->bitmap_lock, flags);
return -SAS_QUEUE_FULL;
}
set_bit(tag, bitmap);
spin_unlock_irqrestore(&pm8001_ha->bitmap_lock, flags);
*tag_out = tag;
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions drivers/scsi/pm8001/pm8001_sas.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ struct pm8001_hba_info {
struct list_head list;
unsigned long flags;
spinlock_t lock;/* host-wide lock */
spinlock_t bitmap_lock;
struct pci_dev *pdev;/* our device */
struct device *dev;
struct pm8001_hba_memspace io_mem[6];
Expand Down

0 comments on commit 646cdf0

Please sign in to comment.