From: Greg Kroah-Hartman Date: Mon, 11 Apr 2022 15:46:14 +0000 (+0200) Subject: 4.14-stable patches X-Git-Tag: v4.9.310~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dafe0a1337619133b4533262b985e4a7c209ac2c;p=thirdparty%2Fkernel%2Fstable-queue.git 4.14-stable patches added patches: mm-sparsemem-fix-mem_section-will-never-be-null-gcc-12-warning.patch --- diff --git a/queue-4.14/mm-sparsemem-fix-mem_section-will-never-be-null-gcc-12-warning.patch b/queue-4.14/mm-sparsemem-fix-mem_section-will-never-be-null-gcc-12-warning.patch new file mode 100644 index 00000000000..9da43b619d9 --- /dev/null +++ b/queue-4.14/mm-sparsemem-fix-mem_section-will-never-be-null-gcc-12-warning.patch @@ -0,0 +1,77 @@ +From a431dbbc540532b7465eae4fc8b56a85a9fc7d17 Mon Sep 17 00:00:00 2001 +From: Waiman Long +Date: Fri, 8 Apr 2022 13:09:01 -0700 +Subject: mm/sparsemem: fix 'mem_section' will never be NULL gcc 12 warning + +From: Waiman Long + +commit a431dbbc540532b7465eae4fc8b56a85a9fc7d17 upstream. + +The gcc 12 compiler reports a "'mem_section' will never be NULL" warning +on the following code: + + static inline struct mem_section *__nr_to_section(unsigned long nr) + { + #ifdef CONFIG_SPARSEMEM_EXTREME + if (!mem_section) + return NULL; + #endif + if (!mem_section[SECTION_NR_TO_ROOT(nr)]) + return NULL; + : + +It happens with CONFIG_SPARSEMEM_EXTREME off. The mem_section definition +is + + #ifdef CONFIG_SPARSEMEM_EXTREME + extern struct mem_section **mem_section; + #else + extern struct mem_section mem_section[NR_SECTION_ROOTS][SECTIONS_PER_ROOT]; + #endif + +In the !CONFIG_SPARSEMEM_EXTREME case, mem_section is a static +2-dimensional array and so the check "!mem_section[SECTION_NR_TO_ROOT(nr)]" +doesn't make sense. + +Fix this warning by moving the "!mem_section[SECTION_NR_TO_ROOT(nr)]" +check up inside the CONFIG_SPARSEMEM_EXTREME block and adding an +explicit NR_SECTION_ROOTS check to make sure that there is no +out-of-bound array access. + +Link: https://lkml.kernel.org/r/20220331180246.2746210-1-longman@redhat.com +Fixes: 3e347261a80b ("sparsemem extreme implementation") +Signed-off-by: Waiman Long +Reported-by: Justin Forbes +Cc: "Kirill A . Shutemov" +Cc: Ingo Molnar +Cc: Rafael Aquini +Signed-off-by: Andrew Morton +Signed-off-by: Linus Torvalds +Signed-off-by: Greg Kroah-Hartman +--- + include/linux/mmzone.h | 11 +++++++---- + 1 file changed, 7 insertions(+), 4 deletions(-) + +--- a/include/linux/mmzone.h ++++ b/include/linux/mmzone.h +@@ -1160,13 +1160,16 @@ extern struct mem_section mem_section[NR + + static inline struct mem_section *__nr_to_section(unsigned long nr) + { ++ unsigned long root = SECTION_NR_TO_ROOT(nr); ++ ++ if (unlikely(root >= NR_SECTION_ROOTS)) ++ return NULL; ++ + #ifdef CONFIG_SPARSEMEM_EXTREME +- if (!mem_section) ++ if (!mem_section || !mem_section[root]) + return NULL; + #endif +- if (!mem_section[SECTION_NR_TO_ROOT(nr)]) +- return NULL; +- return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK]; ++ return &mem_section[root][nr & SECTION_ROOT_MASK]; + } + extern int __section_nr(struct mem_section* ms); + extern unsigned long usemap_size(void); diff --git a/queue-4.14/series b/queue-4.14/series index 28a59436ba6..21a1fbd4900 100644 --- a/queue-4.14/series +++ b/queue-4.14/series @@ -258,3 +258,4 @@ tools-build-use-shell-instead-of-to-get-embedded-libperl-s-ccopts.patch dmaengine-revert-dmaengine-shdma-fix-runtime-pm-imbalance-on-error.patch mm-don-t-skip-swap-entry-even-if-zap_details-specified.patch arm64-module-remove-noload-from-linker-script.patch +mm-sparsemem-fix-mem_section-will-never-be-null-gcc-12-warning.patch