From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2058B2118DC43 for ; Thu, 8 Nov 2018 09:49:06 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87A843154873; Thu, 8 Nov 2018 17:49:05 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-121-147.rdu2.redhat.com [10.10.121.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEF27170F4; Thu, 8 Nov 2018 17:49:04 +0000 (UTC) To: Jeff Brasen , edk2-devel@lists.01.org References: <5e0b0bba39ff2234a7005612a8d718719a952145.1541696528.git.jbrasen@nvidia.com> From: Laszlo Ersek Message-ID: <71c3a9df-f1a2-3649-cd7e-6c0589cd571b@redhat.com> Date: Thu, 8 Nov 2018 18:49:03 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <5e0b0bba39ff2234a7005612a8d718719a952145.1541696528.git.jbrasen@nvidia.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 08 Nov 2018 17:49:05 +0000 (UTC) Subject: Re: [PATCH v2 1/2] EmbeddedPkg/PrePiMemoryAllocationLib: Added AllocateZeroPool() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Nov 2018 17:49:06 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 11/08/18 18:09, Jeff Brasen wrote: > This function is exposed by the MemoryAllocationLib header. > An AllocateZeroPool() function has been added to fix modules depending on > this library and this function. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jeff Brasen > --- > .../PrePiMemoryAllocationLib/MemoryAllocationLib.c | 32 ++++++++++++++++++++++ > 1 file changed, 32 insertions(+) > > diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c > index 0e75e23..c39d140 100644 > --- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c > +++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c > @@ -16,6 +16,7 @@ > #include > > #include > +#include > #include > #include > > @@ -195,6 +196,37 @@ AllocatePool ( > } > > /** > + Allocates and zeros a buffer of type EfiBootServicesData. > + > + Allocates the number bytes specified by AllocationSize of type EfiBootServicesData, clears the > + buffer with zeros, and returns a pointer to the allocated buffer. If AllocationSize is 0, then a > + valid buffer of 0 size is returned. If there is not enough memory remaining to satisfy the > + request, then NULL is returned. > + > + @param AllocationSize The number of bytes to allocate and zero. > + > + @return A pointer to the allocated buffer or NULL if allocation fails. > + > +**/ > +VOID * > +EFIAPI > +AllocateZeroPool ( > + IN UINTN AllocationSize > + ) > +{ > + VOID *Buffer; > + > + Buffer = AllocatePool (AllocationSize); > + if (Buffer == NULL) { > + return NULL; > + } > + > + SetMem (Buffer, AllocationSize, 0); > + > + return Buffer; > +} > + > +/** > Frees a buffer that was previously allocated with one of the pool allocation functions in the > Memory Allocation Library. > > Drive-by comment: can you use ZeroMem()? It's a tiny bit more idiomatic. Thanks Laszlo