diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/find_next_bit.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/find_next_bit.c b/lib/find_next_bit.c index bda0d71a2514..78ccd73a8841 100644 --- a/lib/find_next_bit.c +++ b/lib/find_next_bit.c | |||
@@ -178,4 +178,47 @@ found_middle_swap: | |||
178 | 178 | ||
179 | EXPORT_SYMBOL(generic_find_next_zero_le_bit); | 179 | EXPORT_SYMBOL(generic_find_next_zero_le_bit); |
180 | 180 | ||
181 | unsigned long generic_find_next_le_bit(const unsigned long *addr, unsigned | ||
182 | long size, unsigned long offset) | ||
183 | { | ||
184 | const unsigned long *p = addr + BITOP_WORD(offset); | ||
185 | unsigned long result = offset & ~(BITS_PER_LONG - 1); | ||
186 | unsigned long tmp; | ||
187 | |||
188 | if (offset >= size) | ||
189 | return size; | ||
190 | size -= result; | ||
191 | offset &= (BITS_PER_LONG - 1UL); | ||
192 | if (offset) { | ||
193 | tmp = ext2_swabp(p++); | ||
194 | tmp &= (~0UL << offset); | ||
195 | if (size < BITS_PER_LONG) | ||
196 | goto found_first; | ||
197 | if (tmp) | ||
198 | goto found_middle; | ||
199 | size -= BITS_PER_LONG; | ||
200 | result += BITS_PER_LONG; | ||
201 | } | ||
202 | |||
203 | while (size & ~(BITS_PER_LONG - 1)) { | ||
204 | tmp = *(p++); | ||
205 | if (tmp) | ||
206 | goto found_middle_swap; | ||
207 | result += BITS_PER_LONG; | ||
208 | size -= BITS_PER_LONG; | ||
209 | } | ||
210 | if (!size) | ||
211 | return result; | ||
212 | tmp = ext2_swabp(p); | ||
213 | found_first: | ||
214 | tmp &= (~0UL >> (BITS_PER_LONG - size)); | ||
215 | if (tmp == 0UL) /* Are any bits set? */ | ||
216 | return result + size; /* Nope. */ | ||
217 | found_middle: | ||
218 | return result + __ffs(tmp); | ||
219 | |||
220 | found_middle_swap: | ||
221 | return result + __ffs(ext2_swab(tmp)); | ||
222 | } | ||
223 | EXPORT_SYMBOL(generic_find_next_le_bit); | ||
181 | #endif /* __BIG_ENDIAN */ | 224 | #endif /* __BIG_ENDIAN */ |