Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Aug 2010 09:05:03 +0000 (UTC)
From:      Jeff Roberson <jeff@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r210791 - projects/ofed/head/sys/ofed/include/linux
Message-ID:  <201008030905.o73953nR096423@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jeff
Date: Tue Aug  3 09:05:03 2010
New Revision: 210791
URL: http://svn.freebsd.org/changeset/base/210791

Log:
   - Use BIT_MASK() rather than re-implementing it everywhere.
   - Since we're going from longs to ints cast earlier in set_bit, clr_bit,
     and test_bit so we don't compute array subscripts as longs.
   - Don't allow offsets larger than sizes for the next_bit routines.
  
  Sponsored by:	Isilon Systems, iX Systems, and Panasas.

Modified:
  projects/ofed/head/sys/ofed/include/linux/bitops.h

Modified: projects/ofed/head/sys/ofed/include/linux/bitops.h
==============================================================================
--- projects/ofed/head/sys/ofed/include/linux/bitops.h	Tue Aug  3 08:38:25 2010	(r210790)
+++ projects/ofed/head/sys/ofed/include/linux/bitops.h	Tue Aug  3 09:05:03 2010	(r210791)
@@ -138,8 +138,10 @@ find_next_bit(unsigned long *addr, unsig
 	int bit;
 	int pos;
 
+	if (offset >= size)
+		return (size);
 	pos = offset / BITS_PER_LONG;
-	offs = size % BITS_PER_LONG;
+	offs = offset % BITS_PER_LONG;
 	bit = BITS_PER_LONG * pos;
 	addr += pos;
 	if (offs) {
@@ -174,8 +176,10 @@ find_next_zero_bit(unsigned long *addr, 
 	int bit;
 	int pos;
 
+	if (offset >= size)
+		return (size);
 	pos = offset / BITS_PER_LONG;
-	offs = size % BITS_PER_LONG;
+	offs = offset % BITS_PER_LONG;
 	bit = BITS_PER_LONG * pos;
 	addr += pos;
 	if (offs) {
@@ -216,13 +220,11 @@ bitmap_fill(unsigned long *addr, int siz
 	int tail;
 	int len;
 
-	len = BITS_TO_LONGS(size) * sizeof(long);
+	len = (size / BITS_PER_LONG) * sizeof(long);
 	memset(addr, 0xff, len);
 	tail = size & (BITS_PER_LONG - 1);
-	if (tail)  {
-		len /= sizeof(long);
-		addr[len - 1] = ((unsigned long)-1L) >> (BITS_PER_LONG - tail);
-	}
+	if (tail) 
+		addr[size / BITS_PER_LONG] = BIT_MASK(tail);
 }
 
 static inline int
@@ -235,11 +237,11 @@ bitmap_full(unsigned long *addr, int siz
 
 	len = size / BITS_PER_LONG;
 	for (i = 0; i < len; i++)
-		if (addr[i] != (unsigned long)-1)
+		if (addr[i] != ~0UL)
 			return (0);
 	tail = size & (BITS_PER_LONG - 1);
 	if (tail) {
-		mask = ((unsigned long)-1L) >> (BITS_PER_LONG - tail);
+		mask = BIT_MASK(tail);
 		if ((addr[i] & mask) != mask)
 			return (0);
 	}
@@ -260,7 +262,7 @@ bitmap_empty(unsigned long *addr, int si
 			return (0);
 	tail = size & (BITS_PER_LONG - 1);
 	if (tail) {
-		mask = ((unsigned long)-1L) >> (BITS_PER_LONG - tail);
+		mask = BIT_MASK(tail);
 		if ((addr[i] & mask) != 0)
 			return (0);
 	}
@@ -270,12 +272,12 @@ bitmap_empty(unsigned long *addr, int si
 #define	NBINT	(NBBY * sizeof(int))
 
 #define	set_bit(i, a)							\
-    atomic_set_int((volatile int *)&(a)[(i)/NBINT], 1 << (i) % NBINT)
+    atomic_set_int(&((volatile int *)(a))[(i)/NBINT], 1 << (i) % NBINT)
 
 #define	clear_bit(i, a)							\
-    atomic_clear_int((volatile int *)&(a)[(i)/NBINT], 1 << (i) % NBINT)
+    atomic_clear_int(&((volatile int *)(a))[(i)/NBINT], 1 << (i) % NBINT)
 
 #define	test_bit(i, a)							\
-    !!(atomic_load_acq_int((volatile int *)&(a)[(i)/NBINT]) & 1 << ((i) % NBINT))
+    !!(atomic_load_acq_int(&((volatile int *)(a))[(i)/NBINT]) & 1 << ((i) % NBINT))
 
 #endif	/* _LINUX_BITOPS_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201008030905.o73953nR096423>