__add_pages() can fail if we run out of memory. The caller already handles that, so we shouldn't WARN_ON_ONCE() just because an allocation failed. Let's return the error instead, and only update the end-of-memory variables after __add_pages() succeeds. Fixes: 10f22dde556d ("x86: arch/x86/mm/init_64.c printk fixes") Reported-by: David Hildenbrand Link: https://lore.kernel.org/all/d4fac8af-fd71-47a2-bfe9-3c6559b92209@kernel.org/ Suggested-by: Muchun Song Link: https://lore.kernel.org/all/203892F4-B04A-4F69-A1B3-DC1619176C67@linux.dev/ Signed-off-by: Lance Yang --- arch/x86/mm/init_64.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 70e682180291a..8b6d86fb5a42e 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -970,7 +970,8 @@ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages, return -ERANGE; ret = __add_pages(nid, start_pfn, nr_pages, params); - WARN_ON_ONCE(ret); + if (ret) + return ret; /* * Special case: add_pages() is called by memremap_pages() for adding device -- 2.49.0