From owner-svn-src-projects@FreeBSD.ORG Tue Aug 3 09:05:03 2010 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DE28A106566B; Tue, 3 Aug 2010 09:05:03 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C1B518FC17; Tue, 3 Aug 2010 09:05:03 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o7395340096425; Tue, 3 Aug 2010 09:05:03 GMT (envelope-from jeff@svn.freebsd.org) Received: (from jeff@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o73953nR096423; Tue, 3 Aug 2010 09:05:03 GMT (envelope-from jeff@svn.freebsd.org) Message-Id: <201008030905.o73953nR096423@svn.freebsd.org> From: Jeff Roberson Date: Tue, 3 Aug 2010 09:05:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210791 - projects/ofed/head/sys/ofed/include/linux X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Aug 2010 09:05:03 -0000 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_ */