aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/mlx4
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/mlx4')
-rw-r--r--drivers/net/mlx4/alloc.c37
1 files changed, 4 insertions, 33 deletions
diff --git a/drivers/net/mlx4/alloc.c b/drivers/net/mlx4/alloc.c
index ad95d5f7b630..8c8515619b8e 100644
--- a/drivers/net/mlx4/alloc.c
+++ b/drivers/net/mlx4/alloc.c
@@ -72,35 +72,6 @@ void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj)
72 mlx4_bitmap_free_range(bitmap, obj, 1); 72 mlx4_bitmap_free_range(bitmap, obj, 1);
73} 73}
74 74
75static unsigned long find_aligned_range(unsigned long *bitmap,
76 u32 start, u32 nbits,
77 int len, int align)
78{
79 unsigned long end, i;
80
81again:
82 start = ALIGN(start, align);
83
84 while ((start < nbits) && test_bit(start, bitmap))
85 start += align;
86
87 if (start >= nbits)
88 return -1;
89
90 end = start+len;
91 if (end > nbits)
92 return -1;
93
94 for (i = start + 1; i < end; i++) {
95 if (test_bit(i, bitmap)) {
96 start = i + 1;
97 goto again;
98 }
99 }
100
101 return start;
102}
103
104u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align) 75u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
105{ 76{
106 u32 obj, i; 77 u32 obj, i;
@@ -110,13 +81,13 @@ u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt, int align)
110 81
111 spin_lock(&bitmap->lock); 82 spin_lock(&bitmap->lock);
112 83
113 obj = find_aligned_range(bitmap->table, bitmap->last, 84 obj = bitmap_find_next_zero_area(bitmap->table, bitmap->max,
114 bitmap->max, cnt, align); 85 bitmap->last, cnt, align - 1);
115 if (obj >= bitmap->max) { 86 if (obj >= bitmap->max) {
116 bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top) 87 bitmap->top = (bitmap->top + bitmap->max + bitmap->reserved_top)
117 & bitmap->mask; 88 & bitmap->mask;
118 obj = find_aligned_range(bitmap->table, 0, bitmap->max, 89 obj = bitmap_find_next_zero_area(bitmap->table, bitmap->max,
119 cnt, align); 90 0, cnt, align - 1);
120 } 91 }
121 92
122 if (obj < bitmap->max) { 93 if (obj < bitmap->max) {