Not applied, but patch 0812_cw_endian pulled


Subject: [PATCH] revert the ill-fated attempt to fix the 64 bit problem
From: Arnd Bergmann <arnd@arndb.de>
Date: Thu, 22 Jan 2009 18:43:11 +0100

The patch that adds the big_endian64() function and uses it
changes the _getbit() in a way that is incorrect. Bitmasks in
the Linux kernel are defined to operate on native-endian unsigned
long arrays.
The read_mask function used to read the data in the wrong order
on ppc64, and while your _getbit() would attempt to reconstruct
the right bit, it would still be wrong when you try to pass
the same bitmask to a system call.
Worse, with my patch applied, _getbit now returns the wrong bit
again.

It still crashes, unless I revert your patch.
I'm attaching the revert patch for reference, please apply.

Arnd

---
 libnuma.c |   42 ++++--------------------------------------
 1 file changed, 4 insertions(+), 38 deletions(-)

Index: numactl-dev/libnuma.c
===================================================================
--- numactl-dev.orig/libnuma.c
+++ numactl-dev/libnuma.c
@@ -69,37 +69,12 @@ static int maxprocnode = -1;
 static int maxproccpu = -1;
 static int nodemask_sz = 0;
 static int cpumask_sz = 0;
-static int is_bigendian_64;
 
 int numa_exit_on_error = 0;
 int numa_exit_on_warn = 0;
 static void set_sizes(void);
 
 /*
- * return 1 if this machine is big-endian 64-bit
- */
-int
-big_endian64()
-{
-	union {
-		struct {
-			int a;
-			int b;
-		} ints;
-		struct {
-			long a;
-		} lng;
-	} ua;
-	if (sizeof(long) != 8)
-		return 0;
-	ua.ints.a = 0;
-	ua.ints.b = 3;
-	if (ua.lng.a == 3)
-		return 1;
-	return 0;
-}
-
-/*
  * There are two special functions, _init(void) and _fini(void), which
  * are called automatically by the dynamic loader whenever a library is loaded.
  *
@@ -116,7 +91,6 @@ numa_init(void)
         for (i = 0; i < max; i++)
                 nodemask_set_compat((nodemask_t *)&numa_all_nodes, i);
 	memset(&numa_no_nodes, 0, sizeof(numa_no_nodes));
-	is_bigendian_64 = big_endian64();
 }
 
 /*
@@ -129,18 +103,10 @@ numa_init(void)
 static unsigned int
 _getbit(const struct bitmask *bmp, unsigned int n)
 {
-	unsigned int *ip;
-
-        if (n < bmp->size) {
-		if (is_bigendian_64) {
-			ip = (unsigned int *)bmp->maskp;
-                	return (ip[n/bitsperint] >>
-				(n % bitsperint)) & 1;
-		} else
-                	return (bmp->maskp[n/bitsperlong] >>
-				(n % bitsperlong)) & 1;
-        } else
-                return 0;
+	if (n < bmp->size)
+		return (bmp->maskp[n/bitsperlong] >> (n % bitsperlong)) & 1;
+	else
+		return 0;
 }
 
 static void
