[PATCH] efi: payload: gracefully handle OOM in initrd allocation

Ahmad Fatoum <[email protected]>
Newsgroups org.infradead.lists.barebox
Message-ID <[email protected]>
An initrd can get quite big, so we should not assume that this an
infallible allocation and instead propagate any OOM error code.

Signed-off-by: Ahmad Fatoum <[email protected]>
---
 efi/payload/handover.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/efi/payload/handover.c b/efi/payload/handover.c
index bef726ae303c..544fdfb3c6ad 100644
--- a/efi/payload/handover.c
+++ b/efi/payload/handover.c
@@ -146,7 +146,13 @@ static int do_bootm_efi(struct image_data *data)
 			ret = -errno;
 			goto err_free;
 		}
-		initrd = xmemalign(PAGE_SIZE, PAGE_ALIGN(size));
+		initrd = memalign(PAGE_SIZE, PAGE_ALIGN(size));
+		if (!initrd) {
+			free(tmp);
+			ret = -ENOMEM;
+			goto err_free;
+		}
+
 		memcpy(initrd, tmp, size);
 		memset(initrd + size, 0, PAGE_ALIGN(size) - size);
 		free(tmp);
-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.