Commit 5e19b013f55a884c59a14391b22138899d1cc4cc

Authored by Michal Nazarewicz
Committed by Linus Torvalds
1 parent c8475d144a

lib: bitmap: add alignment offset for bitmap_find_next_zero_area()

Add a bitmap_find_next_zero_area_off() function which works like
bitmap_find_next_zero_area() function except it allows an offset to be
specified when alignment is checked.  This lets caller request a bit such
that its number plus the offset is aligned according to the mask.

[gregory.0xf0@gmail.com: Retrieved from https://patchwork.linuxtv.org/patch/6254/ and updated documentation]
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Gregory Fong <gregory.0xf0@gmail.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Kukjin Kim <kgene.kim@samsung.com>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 2 changed files with 44 additions and 16 deletions Side-by-side Diff

include/linux/bitmap.h
... ... @@ -45,6 +45,7 @@
45 45 * bitmap_set(dst, pos, nbits) Set specified bit area
46 46 * bitmap_clear(dst, pos, nbits) Clear specified bit area
47 47 * bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area
  48 + * bitmap_find_next_zero_area_off(buf, len, pos, n, mask) as above
48 49 * bitmap_shift_right(dst, src, n, nbits) *dst = *src >> n
49 50 * bitmap_shift_left(dst, src, n, nbits) *dst = *src << n
50 51 * bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src)
... ... @@ -114,11 +115,36 @@
114 115  
115 116 extern void bitmap_set(unsigned long *map, unsigned int start, int len);
116 117 extern void bitmap_clear(unsigned long *map, unsigned int start, int len);
117   -extern unsigned long bitmap_find_next_zero_area(unsigned long *map,
118   - unsigned long size,
119   - unsigned long start,
120   - unsigned int nr,
121   - unsigned long align_mask);
  118 +
  119 +extern unsigned long bitmap_find_next_zero_area_off(unsigned long *map,
  120 + unsigned long size,
  121 + unsigned long start,
  122 + unsigned int nr,
  123 + unsigned long align_mask,
  124 + unsigned long align_offset);
  125 +
  126 +/**
  127 + * bitmap_find_next_zero_area - find a contiguous aligned zero area
  128 + * @map: The address to base the search on
  129 + * @size: The bitmap size in bits
  130 + * @start: The bitnumber to start searching at
  131 + * @nr: The number of zeroed bits we're looking for
  132 + * @align_mask: Alignment mask for zero area
  133 + *
  134 + * The @align_mask should be one less than a power of 2; the effect is that
  135 + * the bit offset of all zero areas this function finds is multiples of that
  136 + * power of 2. A @align_mask of 0 means no alignment is required.
  137 + */
  138 +static inline unsigned long
  139 +bitmap_find_next_zero_area(unsigned long *map,
  140 + unsigned long size,
  141 + unsigned long start,
  142 + unsigned int nr,
  143 + unsigned long align_mask)
  144 +{
  145 + return bitmap_find_next_zero_area_off(map, size, start, nr,
  146 + align_mask, 0);
  147 +}
122 148  
123 149 extern int bitmap_scnprintf(char *buf, unsigned int len,
124 150 const unsigned long *src, int nbits);
... ... @@ -326,30 +326,32 @@
326 326 }
327 327 EXPORT_SYMBOL(bitmap_clear);
328 328  
329   -/*
330   - * bitmap_find_next_zero_area - find a contiguous aligned zero area
  329 +/**
  330 + * bitmap_find_next_zero_area_off - find a contiguous aligned zero area
331 331 * @map: The address to base the search on
332 332 * @size: The bitmap size in bits
333 333 * @start: The bitnumber to start searching at
334 334 * @nr: The number of zeroed bits we're looking for
335 335 * @align_mask: Alignment mask for zero area
  336 + * @align_offset: Alignment offset for zero area.
336 337 *
337 338 * The @align_mask should be one less than a power of 2; the effect is that
338   - * the bit offset of all zero areas this function finds is multiples of that
339   - * power of 2. A @align_mask of 0 means no alignment is required.
  339 + * the bit offset of all zero areas this function finds plus @align_offset
  340 + * is multiple of that power of 2.
340 341 */
341   -unsigned long bitmap_find_next_zero_area(unsigned long *map,
342   - unsigned long size,
343   - unsigned long start,
344   - unsigned int nr,
345   - unsigned long align_mask)
  342 +unsigned long bitmap_find_next_zero_area_off(unsigned long *map,
  343 + unsigned long size,
  344 + unsigned long start,
  345 + unsigned int nr,
  346 + unsigned long align_mask,
  347 + unsigned long align_offset)
346 348 {
347 349 unsigned long index, end, i;
348 350 again:
349 351 index = find_next_zero_bit(map, size, start);
350 352  
351 353 /* Align allocation */
352   - index = __ALIGN_MASK(index, align_mask);
  354 + index = __ALIGN_MASK(index + align_offset, align_mask) - align_offset;
353 355  
354 356 end = index + nr;
355 357 if (end > size)
... ... @@ -361,7 +363,7 @@
361 363 }
362 364 return index;
363 365 }
364   -EXPORT_SYMBOL(bitmap_find_next_zero_area);
  366 +EXPORT_SYMBOL(bitmap_find_next_zero_area_off);
365 367  
366 368 /*
367 369 * Bitmap printing & parsing functions: first version by Nadia Yvette Chambers,