Fix bitops to be 64bit clean

A patch from bug#1343:

On all 64bit systems (the easiest example is amd64) ld10k1 crashes on
use by lo10k1, some debugging tracked down the problem fairly quickly.

The bitops functions (set_bit and associated) that ld10k1 use come from
the linux kernel, and assume that longs are 32bit only, causing a buffer
overflow of the bit buffer.

The attached patch fixes the bitops to be independent of the size of
longs, and is confirmed to fix the bug on my box.

Zephaniah E. Hull.
This commit is contained in:
Takashi Iwai 2005-08-18 13:01:56 +00:00
parent 1d0881e212
commit 125498519d

View file

@ -15,13 +15,17 @@
*
* C language equivalents written by Theodore Ts'o, 9/26/92
*/
/*
* Converted to be independent of the size of longs.
* Zephaniah E. Hull 2005-08-15.
*/
__inline__ int set_bit(int nr, unsigned long * addr)
{
int mask, retval;
addr += nr >> 5;
mask = 1 << (nr & 0x1f);
addr += nr >> (sizeof(long) + 1);
mask = 1 << (nr & (sizeof(long) * 8 - 1));
retval = (mask & *addr) != 0;
*addr |= mask;
return retval;
@ -31,8 +35,8 @@ __inline__ int clear_bit(int nr, unsigned long * addr)
{
int mask, retval;
addr += nr >> 5;
mask = 1 << (nr & 0x1f);
addr += nr >> (sizeof(long) + 1);
mask = 1 << (nr & (sizeof(long) * 8 - 1));
retval = (mask & *addr) != 0;
*addr &= ~mask;
return retval;
@ -42,8 +46,8 @@ __inline__ int test_bit(int nr, unsigned long * addr)
{
int mask;
addr += nr >> 5;
mask = 1 << (nr & 0x1f);
addr += nr >> (sizeof(long) + 1);
mask = 1 << (nr & (sizeof(long) * 8 - 1));
return ((mask & *addr) != 0);
}