diff mbox series

[v4,05/11] linux: bitmap.h: Add find_next_zero_area function

Message ID 20220127121700.130821-6-aouledameur@baylibre.com
State Accepted
Commit 8a92603a3489f789f8e3a36a1e073bc1c237d73e
Delegated to: Tom Rini
Headers show
Series dra7: bring up and support IPU load/start | expand

Commit Message

Amjad Ouled-Ameur Jan. 27, 2022, 12:16 p.m. UTC
From: Keerthy <j-keerthy@ti.com>

Add find_next_zero_area to fetch the next zero area in the map.

Signed-off-by: Keerthy <j-keerthy@ti.com>
Signed-off-by: Amjad Ouled-Ameur <aouledameur@baylibre.com>
---

(no changes since v1)

 include/linux/bitmap.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

Tom Rini Feb. 8, 2022, 5:33 p.m. UTC | #1
On Thu, Jan 27, 2022 at 01:16:54PM +0100, Amjad Ouled-Ameur wrote:

> From: Keerthy <j-keerthy@ti.com>
> 
> Add find_next_zero_area to fetch the next zero area in the map.
> 
> Signed-off-by: Keerthy <j-keerthy@ti.com>
> Signed-off-by: Amjad Ouled-Ameur <aouledameur@baylibre.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index dae4225be549..0a8503af9f14 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -159,6 +159,32 @@  static inline unsigned long find_first_bit(const unsigned long *addr, unsigned l
 	     (bit) < (size);					\
 	     (bit) = find_next_bit((addr), (size), (bit) + 1))
 
+static inline unsigned long
+bitmap_find_next_zero_area(unsigned long *map,
+			   unsigned long size,
+			   unsigned long start,
+			   unsigned int nr, unsigned long align_mask)
+{
+	unsigned long index, end, i;
+again:
+	index = find_next_zero_bit(map, size, start);
+
+	/*
+	 * Align allocation
+	 */
+	index = (index + align_mask) & ~align_mask;
+
+	end = index + nr;
+	if (end > size)
+		return end;
+	i = find_next_bit(map, end, index);
+	if (i < end) {
+		start = i + 1;
+		goto again;
+	}
+	return index;
+}
+
 static inline void bitmap_fill(unsigned long *dst, unsigned int nbits)
 {
 	if (small_const_nbits(nbits)) {