From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lee Schermerhorn Subject: [PATCH 4/8] numactl/libnuma - return freeable bitmasks Date: Tue, 28 Apr 2009 12:36:44 -0400 Message-ID: <20090428163644.24945.43171.sendpatchset@localhost.localdomain> References: <20090428163621.24945.95516.sendpatchset@localhost.localdomain> Return-path: In-Reply-To: <20090428163621.24945.95516.sendpatchset@localhost.localdomain> Sender: linux-numa-owner@vger.kernel.org List-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Cliff Wickman Cc: Kornilios Kourtis , Brice Goglin , linux-numa@vger.kernel.org, eric.whitney@hp.com [PATCH 04/08] - Return freeable masks Against: numactl-2.0.3-rc2 The V2+ libnuma API provides functions to free masks [bit, cpu, node] returned by some functions. [It should probably be more specific about it being the caller's responsibility to free such masks.] However, in some cases, the library returns pointers to libnuma internal masks, such as numa_no_nodes. Instead, return pointer to freshly allocated mask that the caller can free without affecting the library's internal operation. Kornilious replaced my bogus structure assignments with calls to copy_bitmask_to_bitmask() --lts libnuma.c | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-) Index: numactl-2.0.3-rc2/libnuma.c =================================================================== --- numactl-2.0.3-rc2.orig/libnuma.c 2009-04-27 16:49:39.000000000 -0400 +++ numactl-2.0.3-rc2/libnuma.c 2009-04-27 16:50:00.000000000 -0400 @@ -896,9 +896,9 @@ numa_get_interleave_mask_v2(void) bmp = numa_allocate_nodemask(); getpol(&oldpolicy, bmp); - if (oldpolicy == MPOL_INTERLEAVE) - return bmp; - return numa_no_nodes_ptr; + if (oldpolicy != MPOL_INTERLEAVE) + copy_bitmask_to_bitmask(numa_no_nodes_ptr, bmp); + return bmp; } __asm__(".symver numa_get_interleave_mask_v2,numa_get_interleave_mask@@libnuma_1.2"); @@ -1055,9 +1055,9 @@ numa_get_membind_v2(void) bmp = numa_allocate_nodemask(); getpol(&oldpolicy, bmp); - if (oldpolicy == MPOL_BIND) - return bmp; - return numa_all_nodes_ptr; + if (oldpolicy != MPOL_BIND) + copy_bitmask_to_bitmask(numa_all_nodes_ptr, bmp); + return bmp; } __asm__(".symver numa_get_membind_v2,numa_get_membind@@libnuma_1.2"); @@ -1629,8 +1629,10 @@ numa_parse_nodestring(char *s) mask = numa_allocate_nodemask(); - if (s[0] == 0) - return numa_no_nodes_ptr; + if (s[0] == 0){ + copy_bitmask_to_bitmask(numa_no_nodes_ptr, mask); + return mask; /* return freeable mask */ + } if (*s == '!') { invert = 1; s++;