Skip to contentSkip to conversation

x86/mm: fix spurious warning on __add_pages() failure

PATCH Applied Lance Yang 4 participants 4 messages Oct 1

Subsystems (3)
lore
Share & tools
lore

Lance Yang

author
#0 lore raw

PATCH 1/1 x86/mm: fix spurious warning on __add_pages() failure

__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.

---
 arch/x86/mm/init_64.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/mm/init_64.c +2 -1
index 70e682180291a..8b6d86fb5a42e 100644
@@ -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
Signature · 1 line
2.49.0
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Lance Yang

__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.

Quoted 6 lines

I noticed that __add_pages() already reports invalid parameters where appropriate, while errors such as -ENOMEM can legitimately occur and are propagated to the caller. Therefore, the additional WARN_ON_ONCE(ret) in add_pages() seems unnecessary to me.

The change looks reasonable.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Lance Yang
Quoted 22 lines · Lance Yang

__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.

---
 arch/x86/mm/init_64.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/mm/init_64.c +0 -0
index 70e682180291a..8b6d86fb5a42e 100644

arch/x86/mm/init_64.c int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages, · line 977

Quoted 9 lines
arch/x86/mm/init_64.c +2 -1
@@ -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
Signature · 3 lines
Cheers,

David
merge bot Applied
#3 lore raw

[tip: x86/mm] x86/mm: Fix spurious warning on __add_pages() failure

In reply to Lance Yang
The following commit has been merged into the x86/mm branch of tip:

The following commit has been merged into the x86/mm branch of tip:

Commit-ID:     d92b5ac5aeba1ffc734576e30a5bca882722de76
Gitweb:        https://git.kernel.org/tip/d92b5ac5aeba1ffc734576e30a5bca882722de76
Author:        Lance Yang <[email protected]>
AuthorDate:    Thu, 01 Oct 2026 16:15:55 +08:00
Committer:     Dave Hansen <[email protected]>
CommitterDate: Thu, 01 Oct 2026 05:04:44 -07:00

x86/mm: Fix spurious warning on __add_pages() failure

__add_pages() can fail if we run out of memory. Callers already handle that. Do not WARN_ON_ONCE() just because an allocation failed.

Return the error instead, and only update the end-of-memory variables after __add_pages() succeeds.

[ dhansen: imperative voice changelog fixups ]

---
 arch/x86/mm/init_64.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/mm/init_64.c +2 -1
index 70e6821..8b6d86f 100644
@@ -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