From patchwork Mon Dec 19 02:33:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 635106 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2095557pvb; Sun, 18 Dec 2022 18:33:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf4qerqdzolZlLQKXFIRJosgQ1wOV/lsZ2PPJ5xwq3zWGqaGBePrrYXVDqJ5ZYywEYLchIq7 X-Received: by 2002:a9d:6405:0:b0:661:dfeb:ea34 with SMTP id h5-20020a9d6405000000b00661dfebea34mr18342617otl.25.1671417226423; Sun, 18 Dec 2022 18:33:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671417226; cv=none; d=google.com; s=arc-20160816; b=nt2+rQ7Mw2+arhMz9LRV2wp7Q8dQ3OeVtkvK/VSa3ozgWhAHYA/PiCzvXMWPLk1GgH 6Yu43Q/MCZmhcO8GWyB7iN69VevUTnwCj5B6hjsoiTxASd1OLAJyP9erj1BwgLheG0wR YeiEnJy+4Koqjz6uYseIoRmpEp0eUHe1nELASjN57BQUdC5CBSj44Fk9bBDFAMYgJbKl ISa9cn60gwjLxb7+3GPgd9WH/JrrJm6IVY5GnluUshpaGAq6p0Mf3H0F29o9ArlGoZGv ncBD7OIUutEgJBCjvHInRQdhAjg/wD8nkdQxKDRDsMqovZW/Mb6FnKeGf64JEb2+8SeK xLHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=csu5NL0LcGdAQa43Ej8iJxCtW0p+sUgW7HHoiBz+t+E=; b=RzdoOyIUyWdOacEx9j/kagyYgBoDNbppBBA1m5mcVrDJW710aYokUzsdgeQTrjxPE0 hRDnZJXJj0bgIgeMBrfLfnPdwcG7LkfR3f94Yul5BbdGGrYo1AMWeSAZTNM0KcP3Y9pC sD3BOaaiRKMpwa0pgpoYvSWAhxasaJcr5ms7w3DYAW+VOPtmpQr2ehu/6FxW/getOPX0 4RWTrfrlJxecoqLRcXO1esucsLP1iYuAGy0rHZWJcIynciq6n0rE/mkIA2URu3LZUSK6 tx4evsoImcmmjCZwxRtQ9+MbZvD69eN4pxSIbs3DcLaSATq3ufiz6zyA7ZSDZ8tPMxpp Areg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="QgXRR/Uc"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id h6-20020a9d5546000000b0066dc58a8d9fsi6456466oti.48.2022.12.18.18.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Dec 2022 18:33:46 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="QgXRR/Uc"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6C05985003; Mon, 19 Dec 2022 03:33:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="QgXRR/Uc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D57AE85003; Mon, 19 Dec 2022 03:33:19 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D86C98363D for ; Mon, 19 Dec 2022 03:33:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pj1-x1035.google.com with SMTP id e7-20020a17090a77c700b00216928a3917so11551593pjs.4 for ; Sun, 18 Dec 2022 18:33:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=csu5NL0LcGdAQa43Ej8iJxCtW0p+sUgW7HHoiBz+t+E=; b=QgXRR/UcMP+4i6vYLkVkhn0LMlNbMKkB7cRkczAJIW1L/Fk0ong1X41+wAG4PY9Wy2 htyJunZxnJzsQNIqxl5e91yQCFuB4aH2ZwONVtDea9RtQXWz6CqL05DPPO+TFnWb67kF uBOtuiCakM2F4DQp3pHAE8F+UPRXE8sBgckAL8YeNZd/NhNlWgr9zwDjx6WE3HiCCQde BXrSTTW1qeb7OvnAlSoKphu3CKu/54mGOCpWfB+IrxHrP4RRzVF5JO6U+6WgcpiNkDYQ 5e9xpdXMn4Gpfqx0eWRQJq7q5h5+uJqAOgrxlM+l67ELRk2EGDveKuSXjZkBwuOTF30e d9Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=csu5NL0LcGdAQa43Ej8iJxCtW0p+sUgW7HHoiBz+t+E=; b=lf73F1K7paqmHeE0ENBEPX+wO0X9F/wJXoM1qM0Psh4u9iEDzUkV1H5o2MZ2RWI1Dp z1IL7Mo1QL21/eWt0S0iHkZhPkRwXhlH2nUT/h76QXsLXvkFzI/zcXU0qIecuDv8Rb2b nJnW7gERLznx8hOAKpBadzgkfWv3zEGTsLwW/fUyiRdy27qkU8ImFux7oZbEfOGqkUJk olR+7rZElsd13Kdrg8aw50gkTTDV4Y+I8VcOZiXCypHGq/lD55Z+KSmFXvLEMXGvaOos X2FsqV6OszfODCjaR9h3ySuf7bMpTJqitKzQJhzQPP7altUO/FHJ+OPpYkNwFltfzKeX yVHg== X-Gm-Message-State: ANoB5pnA0k1aRIrxBxgayj0lMCjCiVyMiYK24ZjKDmzlskSZrCz3qGBL onhUbZBGCbJXYwzh6shxWPAHtDLSnmO5gFfl X-Received: by 2002:a17:90a:ce16:b0:218:a672:bcab with SMTP id f22-20020a17090ace1600b00218a672bcabmr41490797pju.14.1671417190122; Sun, 18 Dec 2022 18:33:10 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id ne8-20020a17090b374800b00219dab2d7a0sm4761523pjb.9.2022.12.18.18.33.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Dec 2022 18:33:09 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima Subject: [PATCH v2 2/2] eficonfig: avoid SetVariable between GetNextVariableName calls Date: Mon, 19 Dec 2022 11:33:13 +0900 Message-Id: <20221219023314.23959-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221219023314.23959-1-masahisa.kojima@linaro.org> References: <20221219023314.23959-1-masahisa.kojima@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The current code calls efi_set_variable_int() to delete the invalid boot option between calls to efi_get_next_variable_name_int(), it may produce unpredictable results. This commit moves removal of the invalid boot option outside of the efi_get_next_variable_name_int() calls. EFI_NOT_FOUND returned from efi_get_next_variable_name_int() indicates we retrieved all EFI variables, it should be treated as EFI_SUCEESS. To address the checkpatch warning of too many leading tabs, combine two if statement into one. Signed-off-by: Masahisa Kojima Reviewed-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- Changes in v2: - fix typos - use '!guidcmp()' instead of 'guidcmp() == 0' - remove superfluous malloc() branch cmd/eficonfig.c | 54 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 0b07dfc958..ce7175a566 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -2310,13 +2310,14 @@ out: efi_status_t eficonfig_delete_invalid_boot_option(struct eficonfig_media_boot_option *opt, efi_status_t count) { - u32 i; efi_uintn_t size; void *load_option; + u32 i, list_size = 0; struct efi_load_option lo; u16 *var_name16 = NULL; u16 varname[] = u"Boot####"; efi_status_t ret = EFI_SUCCESS; + u16 *delete_index_list = NULL, *p; efi_uintn_t buf_size; buf_size = 128; @@ -2331,8 +2332,14 @@ efi_status_t eficonfig_delete_invalid_boot_option(struct eficonfig_media_boot_op efi_uintn_t tmp; ret = efi_next_variable_name(&buf_size, &var_name16, &guid); - if (ret == EFI_NOT_FOUND) + if (ret == EFI_NOT_FOUND) { + /* + * EFI_NOT_FOUND indicates we retrieved all EFI variables. + * This should be treated as success. + */ + ret = EFI_SUCCESS; break; + } if (ret != EFI_SUCCESS) goto out; @@ -2349,31 +2356,46 @@ efi_status_t eficonfig_delete_invalid_boot_option(struct eficonfig_media_boot_op if (ret != EFI_SUCCESS) goto next; - if (size >= sizeof(efi_guid_bootmenu_auto_generated)) { - if (guidcmp(lo.optional_data, &efi_guid_bootmenu_auto_generated) == 0) { - for (i = 0; i < count; i++) { - if (opt[i].size == tmp && - memcmp(opt[i].lo, load_option, tmp) == 0) { - opt[i].exist = true; - break; - } + if (size >= sizeof(efi_guid_bootmenu_auto_generated) && + !guidcmp(lo.optional_data, &efi_guid_bootmenu_auto_generated)) { + for (i = 0; i < count; i++) { + if (opt[i].size == tmp && + memcmp(opt[i].lo, load_option, tmp) == 0) { + opt[i].exist = true; + break; } + } - if (i == count) { - ret = delete_boot_option(i); - if (ret != EFI_SUCCESS) { - free(load_option); - goto out; - } + /* + * The entire list of variables must be retrieved by + * efi_get_next_variable_name_int() before deleting the invalid + * boot option, just save the index here. + */ + if (i == count) { + p = realloc(delete_index_list, sizeof(u32) * + (list_size + 1)); + if (!p) { + ret = EFI_OUT_OF_RESOURCES; + goto out; } + delete_index_list = p; + delete_index_list[list_size++] = index; } } next: free(load_option); } + /* delete all invalid boot options */ + for (i = 0; i < list_size; i++) { + ret = delete_boot_option(delete_index_list[i]); + if (ret != EFI_SUCCESS) + goto out; + } + out: free(var_name16); + free(delete_index_list); return ret; }