Subject: [PATCH 5.0 057/246] mm/resource: Return real error codes from walk failures

From: Greg Kroah-Hartman <[email-masked]>
Date: Thu, 4 Apr 2019 10:45:57 +0200

5.0-stable review patch.  If anyone has any objections, please let me know.

------------------

[ Upstream commit 5cd401ace914dc68556c6d2fcae0c349444d5f86 ]

walk_system_ram_range() can return an error code either becuase
*it* failed, or because the 'func' that it calls returned an
error.  The memory hotplug does the following:

	ret = walk_system_ram_range(..., func);
        if (ret)
		return ret;

and 'ret' makes it out to userspace, eventually.  The problem
s, walk_system_ram_range() failues that result from *it* failing
(as opposed to 'func') return -1.  That leads to a very odd
-EPERM (-1) return code out to userspace.

Make walk_system_ram_range() return -EINVAL for internal
failures to keep userspace less confused.

This return code is compatible with all the callers that I
audited.

Signed-off-by: Dave Hansen <[email-masked]>
Reviewed-by: Bjorn Helgaas <[email-masked]>
Acked-by: Michael Ellerman <[email-masked]> (powerpc)
Cc: Dan Williams <[email-masked]>
Cc: Dave Jiang <[email-masked]>
Cc: Ross Zwisler <[email-masked]>
Cc: Vishal Verma <[email-masked]>
Cc: Tom Lendacky <[email-masked]>
Cc: Andrew Morton <[email-masked]>
Cc: Michal Hocko <[email-masked]>
Cc: [email-masked]
Cc: [email-masked]
Cc: [email-masked]
Cc: Huang Ying <[email-masked]>
Cc: Fengguang Wu <[email-masked]>
Cc: Borislav Petkov <[email-masked]>
Cc: Yaowei Bai <[email-masked]>
Cc: Takashi Iwai <[email-masked]>
Cc: Jerome Glisse <[email-masked]>
Cc: Benjamin Herrenschmidt <[email-masked]>
Cc: Paul Mackerras <[email-masked]>
Cc: [email-masked]
Cc: Keith Busch <[email-masked]>
Signed-off-by: Dan Williams <[email-masked]>
Signed-off-by: Sasha Levin <[email-masked]>
---
 kernel/resource.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/resource.c b/kernel/resource.c
index 915c02e8e5dd..ca7ed5158cff 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -382,7 +382,7 @@ static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end,
 				 int (*func)(struct resource *, void *))
 {
 	struct resource res;
-	int ret = -1;
+	int ret = -EINVAL;
 
 	while (start < end &&
 	       !find_next_iomem_res(start, end, flags, desc, first_lvl, &res)) {
@@ -462,7 +462,7 @@ int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages,
 	unsigned long flags;
 	struct resource res;
 	unsigned long pfn, end_pfn;
-	int ret = -1;
+	int ret = -EINVAL;
 
 	start = (u64) start_pfn << PAGE_SHIFT;
 	end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1;
-- 
2.19.1