2015-08-15 18:27:10

by Alexander Kuleshov

[permalink] [raw]
Subject: [PATCH] mm/memblock: check memblock_reserve on fail in memblock_virt_alloc_internal

This patch adds a check for memblock_reserve() call in the
memblock_virt_alloc_internal() function, because memblock_reserve()
can return -errno on fail.

Signed-off-by: Alexander Kuleshov <[email protected]>
---
mm/memblock.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index 87108e7..73427546 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1298,7 +1298,9 @@ again:

return NULL;
done:
- memblock_reserve(alloc, size);
+ if (memblock_reserve(alloc, size))
+ return NULL;
+
ptr = phys_to_virt(alloc);
memset(ptr, 0, size);

--
2.5.0


2015-08-17 21:59:34

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] mm/memblock: check memblock_reserve on fail in memblock_virt_alloc_internal

On Sun, 16 Aug 2015 00:26:46 +0600 Alexander Kuleshov <[email protected]> wrote:

> This patch adds a check for memblock_reserve() call in the
> memblock_virt_alloc_internal() function, because memblock_reserve()
> can return -errno on fail.
>
> ...
>
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -1298,7 +1298,9 @@ again:
>
> return NULL;
> done:
> - memblock_reserve(alloc, size);
> + if (memblock_reserve(alloc, size))
> + return NULL;
> +
> ptr = phys_to_virt(alloc);
> memset(ptr, 0, size);

This shouldn't ever happen. If it *does* happen, something is messed
up and we should warn.