Skip to content

Commit a88cde5

Browse files
RichardWeiYangrppt
authored andcommitted
memblock test: fix implicit declaration of function 'memparse'
Commit 1e4c64b ("mm/memblock: Add "reserve_mem" to reserved named memory at boot up") introduce the usage of memparse(), which is not defined in memblock test. Add the definition and link it to fix the build. Signed-off-by: Wei Yang <richard.weiyang@gmail.com> Link: https://lore.kernel.org/r/20240806010319.29194-3-richard.weiyang@gmail.com Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
1 parent 9f76c2a commit a88cde5

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

tools/include/linux/string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ extern char * __must_check skip_spaces(const char *);
4747
extern char *strim(char *);
4848

4949
extern void *memchr_inv(const void *start, int c, size_t bytes);
50+
extern unsigned long long memparse(const char *ptr, char **retptr);
5051
#endif /* _TOOLS_LINUX_STRING_H_ */

tools/lib/cmdline.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* From lib/cmdline.c
4+
*/
5+
#include <stdlib.h>
6+
7+
#if __has_attribute(__fallthrough__)
8+
# define fallthrough __attribute__((__fallthrough__))
9+
#else
10+
# define fallthrough do {} while (0) /* fallthrough */
11+
#endif
12+
13+
unsigned long long memparse(const char *ptr, char **retptr)
14+
{
15+
char *endptr; /* local pointer to end of parsed string */
16+
17+
unsigned long long ret = strtoll(ptr, &endptr, 0);
18+
19+
switch (*endptr) {
20+
case 'E':
21+
case 'e':
22+
ret <<= 10;
23+
fallthrough;
24+
case 'P':
25+
case 'p':
26+
ret <<= 10;
27+
fallthrough;
28+
case 'T':
29+
case 't':
30+
ret <<= 10;
31+
fallthrough;
32+
case 'G':
33+
case 'g':
34+
ret <<= 10;
35+
fallthrough;
36+
case 'M':
37+
case 'm':
38+
ret <<= 10;
39+
fallthrough;
40+
case 'K':
41+
case 'k':
42+
ret <<= 10;
43+
endptr++;
44+
fallthrough;
45+
default:
46+
break;
47+
}
48+
49+
if (retptr)
50+
*retptr = endptr;
51+
52+
return ret;
53+
}

tools/testing/memblock/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LDFLAGS += -fsanitize=address -fsanitize=undefined
88
TARGETS = main
99
TEST_OFILES = tests/alloc_nid_api.o tests/alloc_helpers_api.o tests/alloc_api.o \
1010
tests/basic_api.o tests/common.o tests/alloc_exact_nid_api.o
11-
DEP_OFILES = memblock.o lib/slab.o mmzone.o slab.o
11+
DEP_OFILES = memblock.o lib/slab.o mmzone.o slab.o cmdline.o
1212
OFILES = main.o $(DEP_OFILES) $(TEST_OFILES)
1313
EXTR_SRC = ../../../mm/memblock.c
1414

tools/testing/memblock/linux/kernel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
#include <linux/printk.h>
99
#include <linux/linkage.h>
1010
#include <linux/kconfig.h>
11+
#include <linux/string.h>
1112

1213
#endif

0 commit comments

Comments
 (0)