From patchwork Wed Jan 17 19:15:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 862499 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3zMGzR37sLz9t4B for ; Thu, 18 Jan 2018 06:16:33 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id E7F37C21E66; Wed, 17 Jan 2018 19:16:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 9478BC21C3F; Wed, 17 Jan 2018 19:16:24 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 12001C21DE5; Wed, 17 Jan 2018 19:16:22 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lists.denx.de (Postfix) with ESMTPS id A2C01C21C51 for ; Wed, 17 Jan 2018 19:16:22 +0000 (UTC) Received: from workstation4.fritz.box ([95.222.46.37]) by mail.gmx.com (mrgmx002 [212.227.17.184]) with ESMTPSA (Nemesis) id 0Leux5-1fBDpL25eB-00qh1a; Wed, 17 Jan 2018 20:16:20 +0100 From: Heinrich Schuchardt To: Alexander Graf Date: Wed, 17 Jan 2018 20:15:55 +0100 Message-Id: <20180117191612.17108-2-xypron.glpk@gmx.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180117191612.17108-1-xypron.glpk@gmx.de> References: <20180117191612.17108-1-xypron.glpk@gmx.de> X-Provags-ID: V03:K0:L7DD9vgBcdgBuBp9rsGPorVuQfY5MF6PWl//kcB7Ov7HUmZubID 4f4sCYBrHety9g0wzLEgkgi/NoVJUFwTzMEgcL8DB2VdThu7Lgyz/2r2OXDgXUdiWG+do7w D7L/7EE61csVpQmZGfJ8NiWOx9TMI5lq0+sYflnwy6WWfc+y6zGZG/eYba6hn5cCcZ/VWrH rI+nqnPx69aQM7QXs+38g== X-UI-Out-Filterresults: notjunk:1; V01:K0:jF8ij28hBrE=:loI8BLIHoZ1CnIQza2QWs+ o2+6CoW3LykkKdozrdEo0v8adTLU3kKXXwP9408asxpmyaBr0natfsw+KI0b3k7KUGhzbF8Ax Rknf773Jxsfc6qWip+UVGwL7aXMXFObpnYaK8ZcIWBX0MKDNWoG/+kCEmjsCWubs4NN5pblub JzNayBCUyI1j4DZ505gMa1D9oOj69u1OnaJqtkkSz5i16QXt1q/mcqov8SgW13Ihdw09Pxnkz lP6JMURjSoumbYjp7QCU+hC+sVt++4dM/SdOgccRNWfzrFs7v6UKVKY9oRCzpFzSUGXSVzYNt VEBb0FWmZzUHRG567FDx/Y2J/faKKvrVoW41a2CR8WIeEFDSeTtDJruQkvzsZN+G5/yUcQpTn hxxCV4S7MsJu8FZUd0kkcmc8dhsW/oAbUbUr7zkv/IhaL/q1e+x1LGH4BqzfPB1oUq3QJuJ+L YJ3oKdu2mOF9PPILLwPN7pxpRyxAUWKj20NfF2xR5TIXi1SRT57PzEMReUwF5Su2d2WbH6Lmr dtIpOhLUJdtVZE9HKpqSUvqKOfoJR1Ie+Xhk09BG1R8YyQxzi6IRjAS1FH6ymQxZV7bf4lIsK YmL5UR5/m0ssWL3+3J77SQRN32chQ80+qX0FFKx/9vHA93/VkqwvSNbc4JNbitl7YoWQPThaR eESKxFd4C6m7RWa5v0zLGIalGvCUJqcE8z3L7cmpmAoMmVG3a8hnvZA4/MAdcMHahsdtsl+hs ooqWFiEIYgdfvVbxx1kOh72VEOsRdynwCUvljqvMM7zuHF2qm6tDyhXRbMQoS3kao+MAtbMGG zJbrQDfY3Pk7No7pWkcdoNDWI7pqQ== Cc: Heinrich Schuchardt , Tom Rini , u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 01/18] efi_loader: return NULL from device path functions X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" For the construction of device paths we need to call the AllocatePool service. We should not ignore if it fails due to an out of memory situation. This patch changes the device path functions to return NULL if the memory allocation fails. Additional patches will be needed to fix the callers. Signed-off-by: Heinrich Schuchardt --- v2 No change --- include/efi_loader.h | 6 +++--- lib/efi_loader/efi_device_path.c | 42 ++++++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 37389c33cc..6b623d8327 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -304,9 +304,9 @@ struct efi_device_path *efi_dp_from_eth(void); struct efi_device_path *efi_dp_from_mem(uint32_t mem_type, uint64_t start_address, uint64_t end_address); -void efi_dp_split_file_path(struct efi_device_path *full_path, - struct efi_device_path **device_path, - struct efi_device_path **file_path); +efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path, + struct efi_device_path **device_path, + struct efi_device_path **file_path); #define EFI_DP_TYPE(_dp, _type, _subtype) \ (((_dp)->type == DEVICE_PATH_TYPE_##_type) && \ diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 2a8efea6e7..c1ba54e6bd 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -58,8 +58,11 @@ static void *dp_alloc(size_t sz) { void *buf; - if (efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, sz, &buf) != EFI_SUCCESS) + if (efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, sz, &buf) != + EFI_SUCCESS) { + debug("EFI: ERROR: out of memory in %s\n", __func__); return NULL; + } return buf; } @@ -227,6 +230,8 @@ struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp) return NULL; ndp = dp_alloc(sz); + if (!ndp) + return NULL; memcpy(ndp, dp, sz); return ndp; @@ -246,6 +251,8 @@ struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1, unsigned sz1 = efi_dp_size(dp1); unsigned sz2 = efi_dp_size(dp2); void *p = dp_alloc(sz1 + sz2 + sizeof(END)); + if (!p) + return NULL; memcpy(p, dp1, sz1); memcpy(p + sz1, dp2, sz2); memcpy(p + sz1 + sz2, &END, sizeof(END)); @@ -267,6 +274,8 @@ struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp, } else if (!dp) { unsigned sz = node->length; void *p = dp_alloc(sz + sizeof(END)); + if (!p) + return NULL; memcpy(p, node, sz); memcpy(p + sz, &END, sizeof(END)); ret = p; @@ -274,6 +283,8 @@ struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp, /* both dp and node are non-null */ unsigned sz = efi_dp_size(dp); void *p = dp_alloc(sz + node->length + sizeof(END)); + if (!p) + return NULL; memcpy(p, dp, sz); memcpy(p + sz, node, node->length); memcpy(p + sz + node->length, &END, sizeof(END)); @@ -435,6 +446,8 @@ struct efi_device_path *efi_dp_from_dev(struct udevice *dev) void *buf, *start; start = buf = dp_alloc(dp_size(dev) + sizeof(END)); + if (!buf) + return NULL; buf = dp_fill(buf, dev); *((struct efi_device_path *)buf) = END; @@ -576,6 +589,8 @@ struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part) void *buf, *start; start = buf = dp_alloc(dp_part_size(desc, part) + sizeof(END)); + if (!buf) + return NULL; buf = dp_part_fill(buf, desc, part); @@ -614,6 +629,8 @@ struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part, dpsize += fpsize; start = buf = dp_alloc(dpsize + sizeof(END)); + if (!buf) + return NULL; if (desc) buf = dp_part_fill(buf, desc, part); @@ -648,6 +665,8 @@ struct efi_device_path *efi_dp_from_eth(void) dpsize += sizeof(*ndp); start = buf = dp_alloc(dpsize + sizeof(END)); + if (!buf) + return NULL; #ifdef CONFIG_DM_ETH buf = dp_fill(buf, eth_get_dev()); @@ -678,6 +697,8 @@ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, void *buf, *start; start = buf = dp_alloc(sizeof(*mdp) + sizeof(END)); + if (!buf) + return NULL; mdp = buf; mdp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE; @@ -697,22 +718,31 @@ struct efi_device_path *efi_dp_from_mem(uint32_t memory_type, * Helper to split a full device path (containing both device and file * parts) into it's constituent parts. */ -void efi_dp_split_file_path(struct efi_device_path *full_path, - struct efi_device_path **device_path, - struct efi_device_path **file_path) +efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path, + struct efi_device_path **device_path, + struct efi_device_path **file_path) { struct efi_device_path *p, *dp, *fp; + *device_path = NULL; + *file_path = NULL; dp = efi_dp_dup(full_path); + if (!dp) + return EFI_OUT_OF_RESOURCES; p = dp; - while (!EFI_DP_TYPE(p, MEDIA_DEVICE, FILE_PATH)) + while (!EFI_DP_TYPE(p, MEDIA_DEVICE, FILE_PATH)) { p = efi_dp_next(p); + if (!p) + return EFI_OUT_OF_RESOURCES; + } fp = efi_dp_dup(p); - + if (!fp) + return EFI_OUT_OF_RESOURCES; p->type = DEVICE_PATH_TYPE_END; p->sub_type = DEVICE_PATH_SUB_TYPE_END; p->length = sizeof(*p); *device_path = dp; *file_path = fp; + return EFI_SUCCESS; }