From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 80E38C5479D for ; Mon, 9 Jan 2023 08:06:16 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6867E84E8F; Mon, 9 Jan 2023 09:06:13 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com 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=canonical.com header.i=@canonical.com header.b="JZw/toqP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 37FA585007; Mon, 9 Jan 2023 09:06:11 +0100 (CET) Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 21F7784879 for ; Mon, 9 Jan 2023 09:06:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 650333F75C for ; Mon, 9 Jan 2023 08:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1673251567; bh=8NNdmeG5euPtuPt7SbmCUjDNHAgmpH71LBdTm9esU74=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=JZw/toqPA0AP9GOZnlsP6T9cxtEzyymbZu45s2s/O44jq+09W+q5bS3kWpba4pOUv nbefqHszarQQuAyyz62eUKTtISpJelrIefH48dD7oZ2U7M9qo2yzXN7ytSMR1qloLi b6adjssWpCJiAW20M9Sfv6w+oyzMEZRqRMOlyU5exoKHD7hNiVJviEqaKzkj1psN4f 4z138HQjvaAFShgnmA1X2cir9bTLOHgUxYk56luCGrdk2b8x4pYPtZQop6EzB6D4iq EOm7dcaXT3smnARlpfMvZEqijBN9v1Z8491Sj9kGoYcJ0KmeDw2gTcX27NZ648m7wB cqOWZwiUTEJYA== Received: by mail-wr1-f70.google.com with SMTP id i2-20020adfaac2000000b002bc40f98167so310898wrc.2 for ; Mon, 09 Jan 2023 00:06:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8NNdmeG5euPtuPt7SbmCUjDNHAgmpH71LBdTm9esU74=; b=zWeOgkScDuv1Md9q7rZkwk+x7xBnr9ul2j1eRcw2fOuKz66wOrVkqb3icpsGfQHpBi jJPLD9r9yGo47jOehVj8fypa1jcFeM3/mg/miUK0jhUVb0Wk9ncRS1anCBV4cz1MbDiv brDF4Y6K1AXCInge77ehxsPKT7vs107K5N0ZAGXYA0Ph+XFV6P2gf07wREsP4ICnPcvs mEli8qPoSkgEHkVPSQn2FbPPmi9m9hed+1Ko66b49jDaXcA3cNWklfjLxiZNou4bskBc NuTgneGwzrZhL6DZ7KZR6zkvFP+w0z5GJbWIiCCAn7fdIxC0gmtzGjsRFyALfLLZz0mz NA1A== X-Gm-Message-State: AFqh2kokPmaQDmKkort/PxgppY3pNvjbhN/5WZtBLWFx24wNyWh8mOMP SaLOXy8jOSDTMWTHuzZYbDaR2Rureonlo6iSkOrZ8yIhb5/iSH+KX9w+btPcZcHGCz3Cky4bmeU L0drTlgSdAbaO9YcRiTkbleR93ezvEJ8= X-Received: by 2002:a05:600c:3c9b:b0:3d9:f14e:9061 with SMTP id bg27-20020a05600c3c9b00b003d9f14e9061mr1183786wmb.24.1673251567004; Mon, 09 Jan 2023 00:06:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXvkxJqJRn0bODaSagBbsqQfuXn3etQ0SBdzUHzuNYan4oOf0kjaRy/C/ka6NSGIW2mUos+vgg== X-Received: by 2002:a05:600c:3c9b:b0:3d9:f14e:9061 with SMTP id bg27-20020a05600c3c9b00b003d9f14e9061mr1183760wmb.24.1673251566652; Mon, 09 Jan 2023 00:06:06 -0800 (PST) Received: from [192.168.123.67] (ip-088-152-145-137.um26.pools.vodafone-ip.de. [88.152.145.137]) by smtp.gmail.com with ESMTPSA id t8-20020a1c7708000000b003d9f00c8f07sm2439147wmi.21.2023.01.09.00.06.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Jan 2023 00:06:06 -0800 (PST) Message-ID: Date: Mon, 9 Jan 2023 09:06:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH v2 2/3] efi_loader: carve out efi_get_memory_map_alloc() To: Ilias Apalodimas Cc: Tom Rini , Liviu Dudau , Simon Glass , Stefan Roese , Patrick Delaunay , Jaehoon Chung , Michal Simek , Patrice Chotard , Ashok Reddy Soma , u-boot@lists.denx.de References: <20230105202536.190392-1-heinrich.schuchardt@canonical.com> <20230105202536.190392-3-heinrich.schuchardt@canonical.com> Content-Language: en-US From: Heinrich Schuchardt In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 On 1/9/23 08:18, Ilias Apalodimas wrote: > On Thu, Jan 05, 2023 at 09:25:35PM +0100, Heinrich Schuchardt wrote: >> Carve out code from efidebug command used to read the memory map. >> >> Signed-off-by: Heinrich Schuchardt >> --- >> v2: >> new patch >> --- >> cmd/efidebug.c | 18 ++++-------------- >> include/efi_loader.h | 3 +++ >> lib/efi_loader/efi_memory.c | 34 ++++++++++++++++++++++++++++++++++ >> 3 files changed, 41 insertions(+), 14 deletions(-) >> >> diff --git a/cmd/efidebug.c b/cmd/efidebug.c >> index 569003ae2e..e6959ede93 100644 >> --- a/cmd/efidebug.c >> +++ b/cmd/efidebug.c >> @@ -591,25 +591,15 @@ static void print_memory_attributes(u64 attributes) >> static int do_efi_show_memmap(struct cmd_tbl *cmdtp, int flag, >> int argc, char *const argv[]) >> { >> - struct efi_mem_desc *memmap = NULL, *map; >> - efi_uintn_t map_size = 0; >> + struct efi_mem_desc *memmap, *map; >> + efi_uintn_t map_size; >> const char *type; >> int i; >> efi_status_t ret; >> >> - ret = efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL); >> - if (ret == EFI_BUFFER_TOO_SMALL) { >> - map_size += sizeof(struct efi_mem_desc); /* for my own */ >> - ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, map_size, >> - (void *)&memmap); >> - if (ret != EFI_SUCCESS) >> - return CMD_RET_FAILURE; >> - ret = efi_get_memory_map(&map_size, memmap, NULL, NULL, NULL); >> - } >> - if (ret != EFI_SUCCESS) { >> - efi_free_pool(memmap); >> + ret = efi_get_memory_map_alloc(&map_size, &memmap); >> + if (ret != EFI_SUCCESS) >> return CMD_RET_FAILURE; >> - } >> >> printf("Type Start%.*s End%.*s Attributes\n", >> EFI_PHYS_ADDR_WIDTH - 5, spc, EFI_PHYS_ADDR_WIDTH - 3, spc); >> diff --git a/include/efi_loader.h b/include/efi_loader.h >> index 0899e293e5..02d151b715 100644 >> --- a/include/efi_loader.h >> +++ b/include/efi_loader.h >> @@ -734,6 +734,9 @@ efi_status_t efi_allocate_pool(enum efi_memory_type pool_type, >> efi_uintn_t size, void **buffer); >> /* EFI pool memory free function. */ >> efi_status_t efi_free_pool(void *buffer); >> +/* Allocate and retrieve EFI memory map */ >> +efi_status_t efi_get_memory_map_alloc(efi_uintn_t *map_size, >> + struct efi_mem_desc **memory_map); >> /* Returns the EFI memory map */ >> efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size, >> struct efi_mem_desc *memory_map, >> diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c >> index 8d347f101f..32254d2433 100644 >> --- a/lib/efi_loader/efi_memory.c >> +++ b/lib/efi_loader/efi_memory.c >> @@ -736,6 +736,40 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size, >> return EFI_SUCCESS; >> } >> >> +/** >> + * efi_get_memory_map_alloc() - allocate map describing memory usage >> + * >> + * The caller is responsible for calling FreePool() if the call succeeds. >> + * >> + * @memory_map buffer to which the memory map is written >> + * @map_size size of the memory map >> + * Return: status code >> + */ >> +efi_status_t efi_get_memory_map_alloc(efi_uintn_t *map_size, >> + struct efi_mem_desc **memory_map) >> +{ >> + efi_status_t ret; >> + >> + *memory_map = NULL; >> + *map_size = 0; >> + ret = efi_get_memory_map(map_size, *memory_map, NULL, NULL, NULL); > > Although this is correct and efi_get_memory_map() will only return > EFI_BUFFER_TOO_SMALL, since we initialize the map_size to 0, I don't know > if code analysis tools are smart enough to understand this. Perhaps we > should initialize ret? After an assignment ret cannot be uninitialized. Did you find a path through efi_get_memory_map() returning an undefined value? Best regards Heinrich > > >> + if (ret == EFI_BUFFER_TOO_SMALL) { >> + *map_size += sizeof(struct efi_mem_desc); /* for the map */ >> + ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, *map_size, >> + (void **)memory_map); >> + if (ret != EFI_SUCCESS) >> + return ret; >> + ret = efi_get_memory_map(map_size, *memory_map, >> + NULL, NULL, NULL); >> + if (ret != EFI_SUCCESS) { >> + efi_free_pool(*memory_map); >> + *memory_map = NULL; >> + } >> + } >> + >> + return ret; >> +} >> + >> /** >> * efi_add_conventional_memory_map() - add a RAM memory area to the map >> * >> -- >> 2.37.2 >> > > Reviewed-by: Ilias Apalodimas >