Date: Mon, 16 Jun 2014 20:43:43 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r267555 - stable/9/sys/ofed/include/linux Message-ID: <201406162043.s5GKhheI017509@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Mon Jun 16 20:43:43 2014 New Revision: 267555 URL: http://svnweb.freebsd.org/changeset/base/267555 Log: MFC r254120, r257862 and r267395: - Fix out of range shifting bug in bitops.h. - Make code a bit easier to read by adding parenthesis. Approved by: re, gjb @ Modified: stable/9/sys/ofed/include/linux/bitops.h Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/ofed/include/linux/bitops.h ============================================================================== --- stable/9/sys/ofed/include/linux/bitops.h Mon Jun 16 20:21:15 2014 (r267554) +++ stable/9/sys/ofed/include/linux/bitops.h Mon Jun 16 20:43:43 2014 (r267555) @@ -272,23 +272,26 @@ bitmap_empty(unsigned long *addr, int si return (1); } -#define NBINT (NBBY * sizeof(int)) +#define NBLONG (NBBY * sizeof(long)) #define set_bit(i, a) \ - atomic_set_int(&((volatile int *)(a))[(i)/NBINT], 1 << (i) % NBINT) + atomic_set_long(&((volatile long *)(a))[(i)/NBLONG], 1UL << ((i) % NBLONG)) #define clear_bit(i, a) \ - atomic_clear_int(&((volatile int *)(a))[(i)/NBINT], 1 << (i) % NBINT) + atomic_clear_long(&((volatile long *)(a))[(i)/NBLONG], 1UL << ((i) % NBLONG)) #define test_bit(i, a) \ - !!(atomic_load_acq_int(&((volatile int *)(a))[(i)/NBINT]) & 1 << ((i) % NBINT)) + !!(atomic_load_acq_long(&((volatile long *)(a))[(i)/NBLONG]) & \ + (1UL << ((i) % NBLONG))) static inline long test_and_clear_bit(long bit, long *var) { long val; - bit = 1 << bit; + var += bit / (sizeof(long) * NBBY); + bit %= sizeof(long) * NBBY; + bit = (1UL << bit); do { val = *(volatile long *)var; } while (atomic_cmpset_long(var, val, val & ~bit) == 0); @@ -301,7 +304,9 @@ test_and_set_bit(long bit, long *var) { long val; - bit = 1 << bit; + var += bit / (sizeof(long) * NBBY); + bit %= sizeof(long) * NBBY; + bit = (1UL << bit); do { val = *(volatile long *)var; } while (atomic_cmpset_long(var, val, val | bit) == 0);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406162043.s5GKhheI017509>