mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-23 04:34:11 +08:00
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland/infiniband
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland/infiniband: IB/mthca: Use IRQ safe locks to protect allocation bitmaps
This commit is contained in:
commit
b63fe1ba44
@ -41,9 +41,11 @@
|
|||||||
/* Trivial bitmap-based allocator */
|
/* Trivial bitmap-based allocator */
|
||||||
u32 mthca_alloc(struct mthca_alloc *alloc)
|
u32 mthca_alloc(struct mthca_alloc *alloc)
|
||||||
{
|
{
|
||||||
|
unsigned long flags;
|
||||||
u32 obj;
|
u32 obj;
|
||||||
|
|
||||||
spin_lock(&alloc->lock);
|
spin_lock_irqsave(&alloc->lock, flags);
|
||||||
|
|
||||||
obj = find_next_zero_bit(alloc->table, alloc->max, alloc->last);
|
obj = find_next_zero_bit(alloc->table, alloc->max, alloc->last);
|
||||||
if (obj >= alloc->max) {
|
if (obj >= alloc->max) {
|
||||||
alloc->top = (alloc->top + alloc->max) & alloc->mask;
|
alloc->top = (alloc->top + alloc->max) & alloc->mask;
|
||||||
@ -56,19 +58,24 @@ u32 mthca_alloc(struct mthca_alloc *alloc)
|
|||||||
} else
|
} else
|
||||||
obj = -1;
|
obj = -1;
|
||||||
|
|
||||||
spin_unlock(&alloc->lock);
|
spin_unlock_irqrestore(&alloc->lock, flags);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mthca_free(struct mthca_alloc *alloc, u32 obj)
|
void mthca_free(struct mthca_alloc *alloc, u32 obj)
|
||||||
{
|
{
|
||||||
|
unsigned long flags;
|
||||||
|
|
||||||
obj &= alloc->max - 1;
|
obj &= alloc->max - 1;
|
||||||
spin_lock(&alloc->lock);
|
|
||||||
|
spin_lock_irqsave(&alloc->lock, flags);
|
||||||
|
|
||||||
clear_bit(obj, alloc->table);
|
clear_bit(obj, alloc->table);
|
||||||
alloc->last = min(alloc->last, obj);
|
alloc->last = min(alloc->last, obj);
|
||||||
alloc->top = (alloc->top + alloc->max) & alloc->mask;
|
alloc->top = (alloc->top + alloc->max) & alloc->mask;
|
||||||
spin_unlock(&alloc->lock);
|
|
||||||
|
spin_unlock_irqrestore(&alloc->lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask,
|
int mthca_alloc_init(struct mthca_alloc *alloc, u32 num, u32 mask,
|
||||||
|
Loading…
Reference in New Issue
Block a user