62 lines
1.5 KiB
Diff
62 lines
1.5 KiB
Diff
From eeb3d396ee5401114bf0d486d200dffb03f54ac5 Mon Sep 17 00:00:00 2001
|
|
From: Chunsheng Luo <luochunsheng@huawei.com>
|
|
Date: Tue, 15 Nov 2022 15:21:31 +0800
|
|
Subject: [PATCH] fix wrong nodemask_sz when CONFIG_NODES_SHIFT is less than 5
|
|
|
|
Signed-off-by: buque <wuxu.wu@huawei.com>
|
|
---
|
|
libnuma.c | 22 ++++++++++++++--------
|
|
1 file changed, 14 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/libnuma.c b/libnuma.c
|
|
index b8e5603..896e995 100644
|
|
--- a/libnuma.c
|
|
+++ b/libnuma.c
|
|
@@ -370,13 +370,11 @@ set_configured_nodes(void)
|
|
}
|
|
}
|
|
|
|
-/*
|
|
- * Convert the string length of an ascii hex mask to the number
|
|
- * of bits represented by that mask.
|
|
- */
|
|
-static int s2nbits(const char *s)
|
|
+static inline int is_digit(char s)
|
|
{
|
|
- return strlen(s) * 32 / 9;
|
|
+ return (s >= '0' && s <= '9')
|
|
+ || (s >= 'a' && s <= 'f')
|
|
+ || (s >= 'A' && s <= 'F');
|
|
}
|
|
|
|
/* Is string 'pre' a prefix of string 's'? */
|
|
@@ -398,6 +396,8 @@ set_nodemask_size(void)
|
|
{
|
|
FILE *fp;
|
|
char *buf = NULL;
|
|
+ char *tmp_buf = NULL;
|
|
+ int digit_len = 0;
|
|
size_t bufsize = 0;
|
|
|
|
if ((fp = fopen(mask_size_file, "r")) == NULL)
|
|
@@ -405,8 +405,14 @@ set_nodemask_size(void)
|
|
|
|
while (getline(&buf, &bufsize, fp) > 0) {
|
|
if (strprefix(buf, nodemask_prefix)) {
|
|
- nodemask_sz = s2nbits(buf + strlen(nodemask_prefix));
|
|
- break;
|
|
+ tmp_buf = buf;
|
|
+ tmp_buf += strlen(nodemask_prefix);
|
|
+ while (*tmp_buf != '\n' && *tmp_buf != '\0') {
|
|
+ if (is_digit(*tmp_buf))
|
|
+ digit_len++;
|
|
+ tmp_buf++;
|
|
+ }
|
|
+ nodemask_sz = digit_len * 4;
|
|
}
|
|
}
|
|
free(buf);
|
|
--
|
|
2.33.0
|
|
|