Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib: Fix ia64 bootloader linkage

kbuild robot reports that since commit ce76d938dd98 ("lib: Add memcat_p():
paste 2 pointer arrays together") the ia64/hp/sim/boot fails to link:

> LD arch/ia64/hp/sim/boot/bootloader
> lib/string.o: In function `__memcat_p':
> string.c:(.text+0x1f22): undefined reference to `__kmalloc'
> string.c:(.text+0x1ff2): undefined reference to `__kmalloc'
> make[1]: *** [arch/ia64/hp/sim/boot/Makefile:37: arch/ia64/hp/sim/boot/bootloader] Error 1

The reason is, the above commit, via __memcat_p(), adds a call to
__kmalloc to string.o, which happens to be used in the bootloader, but
there's no kmalloc or slab or anything.

Since the linker would only pull in objects that contain referenced
symbols, moving __memcat_p() to a different compilation unit solves the
problem.

Fixes: ce76d938dd98 ("lib: Add memcat_p(): paste 2 pointer arrays together")
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Reported-by: kbuild test robot <lkp@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alexander Shishkin and committed by
Greg Kroah-Hartman
93048c09 9793c1fd

+36 -32
+1 -1
lib/Makefile
··· 24 24 flex_proportions.o ratelimit.o show_mem.o \ 25 25 is_single_threaded.o plist.o decompress.o kobject_uevent.o \ 26 26 earlycpio.o seq_buf.o siphash.o dec_and_lock.o \ 27 - nmi_backtrace.o nodemask.o win_minmax.o 27 + nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o 28 28 29 29 lib-$(CONFIG_PRINTK) += dump_stack.o 30 30 lib-$(CONFIG_MMU) += ioremap.o
+34
lib/memcat_p.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include <linux/slab.h> 4 + 5 + /* 6 + * Merge two NULL-terminated pointer arrays into a newly allocated 7 + * array, which is also NULL-terminated. Nomenclature is inspired by 8 + * memset_p() and memcat() found elsewhere in the kernel source tree. 9 + */ 10 + void **__memcat_p(void **a, void **b) 11 + { 12 + void **p = a, **new; 13 + int nr; 14 + 15 + /* count the elements in both arrays */ 16 + for (nr = 0, p = a; *p; nr++, p++) 17 + ; 18 + for (p = b; *p; nr++, p++) 19 + ; 20 + /* one for the NULL-terminator */ 21 + nr++; 22 + 23 + new = kmalloc_array(nr, sizeof(void *), GFP_KERNEL); 24 + if (!new) 25 + return NULL; 26 + 27 + /* nr -> last index; p points to NULL in b[] */ 28 + for (nr--; nr >= 0; nr--, p = p == b ? &a[nr] : p - 1) 29 + new[nr] = *p; 30 + 31 + return new; 32 + } 33 + EXPORT_SYMBOL_GPL(__memcat_p); 34 +
-30
lib/string.c
··· 891 891 EXPORT_SYMBOL(memscan); 892 892 #endif 893 893 894 - /* 895 - * Merge two NULL-terminated pointer arrays into a newly allocated 896 - * array, which is also NULL-terminated. Nomenclature is inspired by 897 - * memset_p() and memcat() found elsewhere in the kernel source tree. 898 - */ 899 - void **__memcat_p(void **a, void **b) 900 - { 901 - void **p = a, **new; 902 - int nr; 903 - 904 - /* count the elements in both arrays */ 905 - for (nr = 0, p = a; *p; nr++, p++) 906 - ; 907 - for (p = b; *p; nr++, p++) 908 - ; 909 - /* one for the NULL-terminator */ 910 - nr++; 911 - 912 - new = kmalloc_array(nr, sizeof(void *), GFP_KERNEL); 913 - if (!new) 914 - return NULL; 915 - 916 - /* nr -> last index; p points to NULL in b[] */ 917 - for (nr--; nr >= 0; nr--, p = p == b ? &a[nr] : p - 1) 918 - new[nr] = *p; 919 - 920 - return new; 921 - } 922 - EXPORT_SYMBOL_GPL(__memcat_p); 923 - 924 894 #ifndef __HAVE_ARCH_STRSTR 925 895 /** 926 896 * strstr - Find the first substring in a %NUL terminated string
+1 -1
lib/test_memcat_p.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 - * Test cases for memcat_p() in lib/string.c 3 + * Test cases for memcat_p() in lib/memcat_p.c 4 4 */ 5 5 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 6 6