Skip to contentSkip to conversation

lib/bitmap.c: Change prototype of bitmap_copy_le

PATCH New Rasmus Villemoes 1 participant 2 messages Dec 31, 2014

Subsystems (2)
lore
Share & tools
lore

Rasmus Villemoes

author reviewer
#0 lore raw

PATCH 1/2 lib/bitmap.c: Change prototype of bitmap_copy_le

Make the prototype of bitmap_copy_le the same as bitmap_copy's. All other bitmap_* functions take unsigned long* parameters; there's no reason this should be special.

The only current user is the static inline uwb_mas_bm_copy_le, which already does the void* laundering, so the end users can pass their u8 or __le32 buffers without a cast.

Furthermore, this allows us to simply let bitmap_copy_le be an alias for bitmap_copy on little-endian; see next patch.

---
 include/linux/bitmap.h | 2 +-
 lib/bitmap.c           | 9 ++++-----
 2 files changed, 5 insertions(+), 6 deletions(-)
include/linux/bitmap.h +1 -1
index 202e4034fe26..bd1748919872 100644
@@ -170,7 +170,7 @@ extern void bitmap_fold(unsigned long *dst, const unsigned long *orig,
 extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order);
 extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order);
 extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order);
-extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits);
+extern void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int nbits);
 extern int bitmap_ord_to_pos(const unsigned long *bitmap, int n, int bits);
 extern int bitmap_print_to_pagebuf(bool list, char *buf,
 				   const unsigned long *maskp, int nmaskbits);
lib/bitmap.c +4 -5
index 324ea9eab8c1..5ded9180528b 100644
@@ -1207,16 +1207,15 @@ EXPORT_SYMBOL(bitmap_allocate_region);
  *
  * Require nbits % BITS_PER_LONG == 0.
  */
-void bitmap_copy_le(void *dst, const unsigned long *src, int nbits)
+void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int nbits)
 {
-	unsigned long *d = dst;
-	int i;
+	unsigned int i;
 
 	for (i = 0; i < nbits/BITS_PER_LONG; i++) {
 		if (BITS_PER_LONG == 64)
-			d[i] = cpu_to_le64(src[i]);
+			dst[i] = cpu_to_le64(src[i]);
 		else
-			d[i] = cpu_to_le32(src[i]);
+			dst[i] = cpu_to_le32(src[i]);
 	}
 }
 EXPORT_SYMBOL(bitmap_copy_le);
Signature · 1 line
2.1.3
author reviewer
#1 lore raw

PATCH 2/2 lib/bitmap.c: Elide bitmap_copy_le on little-endian

On little-endian, there's no reason to have an extra, presumably less efficient, way of copying a bitmap.

---
 include/linux/bitmap.h | 4 ++++
 lib/bitmap.c           | 2 ++
 2 files changed, 6 insertions(+)
include/linux/bitmap.h +4 -0
index bd1748919872..a1977e153e63 100644
@@ -170,7 +170,11 @@ extern void bitmap_fold(unsigned long *dst, const unsigned long *orig,
 extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order);
 extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order);
 extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order);
+#ifdef __BIG_ENDIAN
 extern void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int nbits);
+#else
+#define bitmap_copy_le bitmap_copy
+#endif
 extern int bitmap_ord_to_pos(const unsigned long *bitmap, int n, int bits);
 extern int bitmap_print_to_pagebuf(bool list, char *buf,
 				   const unsigned long *maskp, int nmaskbits);
lib/bitmap.c +2 -0
index 5ded9180528b..8014996b1531 100644
@@ -1207,6 +1207,7 @@ EXPORT_SYMBOL(bitmap_allocate_region);
  *
  * Require nbits % BITS_PER_LONG == 0.
  */
+#ifdef __BIG_ENDIAN
 void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int nbits)
 {
 	unsigned int i;
@@ -1219,3 +1220,4 @@ void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int n
 	}
 }
 EXPORT_SYMBOL(bitmap_copy_le);
+#endif
Signature · 1 line
2.1.3