From: Lee Schermerhorn <lee.schermerhorn@hp.com>
To: Cliff Wickman <cpi@sgi.com>
Cc: Kornilios Kourtis <kkourt@cslab.ece.ntua.gr>,
	Brice Goglin <Brice.Goglin@inria.fr>, <linux-numa@vger.kernel.org>,
	<eric.whitney@hp.com>
Date:	Tue, 28 Apr 2009 12:36:50 -0400
Subject: [PATCH 5/8] numactl/libnuma - fix parsing of cpu, node mask

[PATCH 05/08] - Fix Parsing of maxproc{cpu|node} in set_thread_constraints()

Against:  numactl-2.0.3-rc2

NOTE:  a patch to fix this has already been posted to linux-numa by
Brice Goglin.  This is the version that I had in my tree.

Hard-coded '+15' was dropping the first character of the mask.
This caused, e.g., numactl to error out on last 4 processors of a
platform--on a 32-cpu system, in my case.

That's a tab separating the tag from the mask, so look for tab
explicitly.

 libnuma.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Index: numactl-dev/libnuma.c
===================================================================
--- numactl-dev.orig/libnuma.c
+++ numactl-dev/libnuma.c
@@ -375,6 +375,9 @@ read_mask(char *s, struct bitmask *bmp)
 	unsigned int *start = tmp;
 	unsigned int i, n = 0, m = 0;
 
+	if (!s)
+		return 0;	/* shouldn't happen */
+
 	i = strtoul(s, &end, 16);
 
 	/* Skip leading zeros */
@@ -447,12 +450,15 @@ set_thread_constraints(void)
 	}
 
 	while (getline(&buffer, &buflen, f) > 0) {
+		/* mask starts after [last] tab */
+		char  *mask = strrchr(buffer,'\t') + 1;
+
 		if (strncmp(buffer,"Cpus_allowed:",13) == 0)
-			maxproccpu = read_mask(buffer + 15, numa_all_cpus_ptr);
+			maxproccpu = read_mask(mask, numa_all_cpus_ptr);
 
 		if (strncmp(buffer,"Mems_allowed:",13) == 0) {
 			maxprocnode =
-				read_mask(buffer + 15, numa_all_nodes_ptr);
+				read_mask(mask, numa_all_nodes_ptr);
 		}
 		if (strncmp(buffer,"Mems_allowed_list:",18) == 0) {
 			nodes_allowed_list = malloc(strlen(buffer)-18);
