From patchwork Thu Oct 24 10:46:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 838112 Delivered-To: patch@linaro.org Received: by 2002:adf:a399:0:b0:37d:45d0:187 with SMTP id l25csp290112wrb; Thu, 24 Oct 2024 03:46:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVES8yv2/jIWYUsgW6Ud2oJB3LE9nBIY8uWeM/ZQ5NaCr+G0qXF97Wz/grdU0SmM9v5XKY2tA==@linaro.org X-Google-Smtp-Source: AGHT+IH/Dcn15gwfDTMOkAoQMONa55uPlVqx61his1vCewMRojIwtm8B/iJfnZSd2FIn4/XUQ603 X-Received: by 2002:a2e:86ce:0:b0:2fb:3c44:7f8b with SMTP id 38308e7fff4ca-2fc9d5d5421mr26668231fa.43.1729766783038; Thu, 24 Oct 2024 03:46:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1729766783; cv=none; d=google.com; s=arc-20240605; b=eSHpuIlrI1s1J2/AUbru/8lps/mtgdktF8CaOhqUawtt7S++HwfV6Yiy6VQgyJOh5H kauqzY8GmaHiGVP3uecj+G2hi+PQhHyzT9RAeku3Og31hERKAuae8zKHYGTbVFXkmXSa RM4+9BV8Xwv8BHErQGcE3xgVtT7TELVg0zmRqRLvA/yf+p+WknMWJgtrOEcb+YLmpdd+ XgrjPrFSKfamy+VjsZdH1dwPbULLQzxEZaMf6mFX/+Inmg6N2pDq9B2wBCEk4mDyG/ft d+k9FLR9qurRyDWSIGwT2p2xtxeQ96Qz+gMwbK4uY++ShXdD0CpXfnUXSj+JkfJwUtYu KkuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=llggovwtdPHjq8gq0kgQDelnBh9ebffUtwHswj1YMDY=; fh=iuuIBOpmOd3OwexSj7eji6EcG4pTqeKQqUrJ/192Gks=; b=XY8Eua0z1diUL4diceOjJd/3z7PKqwihqHV3pfZ4GT7BwYcjbDSszDbVORVImQeGpP vi4q3yYQe650KwE2fri/200FrYgaw1jvTPePSiOc4aWGItn4LseAL1LGHjThIFhFP+Nt c7Kws5PQ+qoSrgOOn7CC0EIZ7wrcOAVcm0MdxAJZSfQym+QqSVw1Xark7Kb4g4T7hh5x e3s33cDyW8QRwJsnrbcqUEn7YJIolwZdjKrW136fBPt0Bq3HmsxMtpS9v7H4+1XZxwt3 pR5mdEe0oTzNkQwnUiQk6r0xJZ7GmoM8feVS+0u01GP2JEtm4Pew2hqjk2wHJFh4DXme kqvA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="kAaT15/D"; 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; dara=neutral header.i=@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 38308e7fff4ca-2fb9ae6a095si29064511fa.199.2024.10.24.03.46.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 03:46:23 -0700 (PDT) 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="kAaT15/D"; 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; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AD1B288C7B; Thu, 24 Oct 2024 12:46:21 +0200 (CEST) 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="kAaT15/D"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4EB5A88DB7; Thu, 24 Oct 2024 12:46:20 +0200 (CEST) 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,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) (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 4F0F988BB7 for ; Thu, 24 Oct 2024 12:46:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a9a850270e2so118722066b.0 for ; Thu, 24 Oct 2024 03:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729766768; x=1730371568; darn=lists.denx.de; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=llggovwtdPHjq8gq0kgQDelnBh9ebffUtwHswj1YMDY=; b=kAaT15/DejqPTEkU3Yk9bnLlLcXyRxb174qQDleK2ewspaoyFrKVIFssY9FfYh0oRk 99xyDfDab9GTR618SzOmQENv3jZds0sn6zlsWpbF5L5eDM+PT33Ae2hJYmaxX3jBtuHK 2ZesgWBvQqOGaNIEDHF3ImgN5How/ryDkSWwo5Wou07rMYRFcsFyzazR9u/TXlLgJ0WG 3QV3DBA2xKYWEwEye5MaTL7rtUYHSiaYXbzQo6NL83F6+BeB8aylDqHvxYaPi+iXjDYt 8K0m5cUr9z7EXv6UjDSynvGQG/N71bq/R+rWxg0jrH8g3y5RrM37uAY2ph58pT7Lr5OT 116A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729766768; x=1730371568; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=llggovwtdPHjq8gq0kgQDelnBh9ebffUtwHswj1YMDY=; b=vEoyNWBa4EHJv7jlX7f7AEEzMYQngzo1nL4R6rEcUXD42CFyxMdwXuEded9Ykwv6tK wvLe3mW8SoueqpJwV2xtpY0BkINULTXA3/vaIgPeEYS/s2A1cu0CFsBb5foHvHH8bzcA SYZps5iRAtReVj6cUh2hxk7q9mLtf6886raspu3l4IqFaybVWQ3SHnfxERih1pvxrM9X 7tjCemdKBtR+kKQHP6LesxtFuZWARexyzHOLKy2tMETVHtrmhKr8KV5GPtl+n8XvPsdi w3s7YE3CkiEIr6HWkuNJnnuWXwQyx/PKn3oY6y7WUAUjjOJnLvccwCW3dRZejMjFTdsP Qabg== X-Forwarded-Encrypted: i=1; AJvYcCWXlGzcgWFrZrPxP0hly2Yd1rc0VDt6XeEN0AwKMIxZ7E7Adxz5Stx31s5kPJ+UbM6zHhfKs6w=@lists.denx.de X-Gm-Message-State: AOJu0YwpIcZ60D/2PzGW0DJvTU4ULw3NG6mG3J2wvEXNO3YczircuYVG kAveTHXhZhsQJEONdkUjTI0iKuGy+OfdUX1TUfpCIrj4Zr+L6Z89pBV0cvSeySU= X-Received: by 2002:a17:907:1c8b:b0:a9a:522a:ba70 with SMTP id a640c23a62f3a-a9abf8aefb2mr532319366b.32.1729766767608; Thu, 24 Oct 2024 03:46:07 -0700 (PDT) Received: from localhost.localdomain (ppp176092143132.access.hol.gr. [176.92.143.132]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a9159a1a6sm597792766b.204.2024.10.24.03.46.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 03:46:06 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: Ilias Apalodimas , Tom Rini , Sughosh Ganu , Simon Glass , u-boot@lists.denx.de Subject: [PATCH] lmb: Correctly unmap and free memory on errors Date: Thu, 24 Oct 2024 13:46:02 +0300 Message-ID: <20241024104603.1340301-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean We never free and unmap the memory on errors and we never unmap it when freeing it. This won't cause any problems on actual hardware but it will on sandbox Fixes: commit 22f2c9ed9f53 ("efi: memory: use the lmb API's for allocating and freeing memory") Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_memory.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) -- 2.45.2 diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 9f3f08769977..84be5532a655 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -451,7 +451,7 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type, enum efi_memory_type memory_type, efi_uintn_t pages, uint64_t *memory) { - u64 len; + u64 efi_addr, len; uint flags; efi_status_t ret; phys_addr_t addr; @@ -499,14 +499,17 @@ efi_status_t efi_allocate_pages(enum efi_allocate_type type, return EFI_INVALID_PARAMETER; } - addr = (u64)(uintptr_t)map_sysmem(addr, 0); + efi_addr = (u64)(uintptr_t)map_sysmem(addr, 0); /* Reserve that map in our memory maps */ - ret = efi_add_memory_map_pg(addr, pages, memory_type, true); - if (ret != EFI_SUCCESS) + ret = efi_add_memory_map_pg(efi_addr, pages, memory_type, true); + if (ret != EFI_SUCCESS) { /* Map would overlap, bail out */ + lmb_free_flags(addr, (u64)pages << EFI_PAGE_SHIFT, flags); + unmap_sysmem((void *)(uintptr_t)efi_addr); return EFI_OUT_OF_RESOURCES; + } - *memory = addr; + *memory = efi_addr; return EFI_SUCCESS; } @@ -548,6 +551,8 @@ efi_status_t efi_free_pages(uint64_t memory, efi_uintn_t pages) if (ret != EFI_SUCCESS) return EFI_NOT_FOUND; + unmap_sysmem((void *)(uintptr_t)memory); + return ret; }