From 68485f8516884377e54c623b0deff73f97321d96 Mon Sep 17 00:00:00 2001
From: "Hongzhi.Song" <hongzhi.song@windriver.com>
Date: Thu, 19 Sep 2019 04:32:31 -0400
Subject: [PATCH] numademo: fix error on 32bit system

Error Info on 32bit:
root@intel-x86:~# numademo -t -e 1M
Configured Nodes does not match available memory nodes

That's because sizeof(long)=4Word, but sizeof(long long)=8Word
on 32bit. So (long long) assigning to (long) maybe cause overflow.

long numa_node_size(int node, long *freep)
{
    ...
    long sz = numa_node_size64_int(node, &f2);
    ~^^~
    return sz;
    ...
}
long long numa_node_size64(int node, long long *freep)
~^^   ^^~
{
    ...
}

Unify the return type of above functions.

Upstream-Status: Accepted [next version is after 2.0.13 or 2.0.14]
[https://github.com/numactl/numactl/commit/a7c4bc790a191d3e42b63850b409c1a72b75a4e1]
                 Submitted [https://github.com/numactl/numactl/pull/79]
[The first patch was merged but has a error, then the second fix it.]

Signed-off-by: Hongzhi.Song <hongzhi.song@windriver.com>
---
 libnuma.c         | 4 ++--
 numa.h            | 2 +-
 numademo.c        | 2 +-
 test/move_pages.c | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libnuma.c b/libnuma.c
index cac8851..8b5c6aa 100644
--- a/libnuma.c
+++ b/libnuma.c
@@ -791,10 +791,10 @@ long long numa_node_size64(int node, long long *freep)
 
 make_internal_alias(numa_node_size64);
 
-long numa_node_size(int node, long *freep)
+long long numa_node_size(int node, long long *freep)
 {
 	long long f2;
-	long sz = numa_node_size64_int(node, &f2);
+	long long sz = numa_node_size64_int(node, &f2);
 	if (freep)
 		*freep = f2;
 	return sz;
diff --git a/numa.h b/numa.h
index 3a8c543..268fb1d 100644
--- a/numa.h
+++ b/numa.h
@@ -143,7 +143,7 @@ int numa_preferred(void);
 
 /* Return node size and free memory */
 long long numa_node_size64(int node, long long *freep);
-long numa_node_size(int node, long *freep);
+long long numa_node_size(int node, long long *freep);
 
 int numa_pagesize(void);
 
diff --git a/numademo.c b/numademo.c
index a720db0..8c56da8 100644
--- a/numademo.c
+++ b/numademo.c
@@ -301,7 +301,7 @@ int max_node, numnodes;
 int get_node_list(void)
 {
         int a, got_nodes = 0;
-        long free_node_sizes;
+        long long free_node_sizes;
 
         numnodes = numa_num_configured_nodes();
         node_to_use = (int *)malloc(numnodes * sizeof(int));
diff --git a/test/move_pages.c b/test/move_pages.c
index d1d8436..f8ff25d 100644
--- a/test/move_pages.c
+++ b/test/move_pages.c
@@ -26,7 +26,7 @@ int *node_to_use;
 int get_node_list()
 {
         int a, got_nodes = 0, max_node, numnodes;
-        long free_node_sizes;
+        long long free_node_sizes;
 
         numnodes = numa_num_configured_nodes();
         node_to_use = (int *)malloc(numnodes * sizeof(int));
-- 
2.23.0

