From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 B4DB22095DE59 for ; Thu, 10 Aug 2017 03:40:08 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Aug 2017 03:42:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,352,1498546800"; d="scan'208";a="138600022" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga006.fm.intel.com with ESMTP; 10 Aug 2017 03:42:27 -0700 Received: from FMSMSX110.amr.corp.intel.com (10.18.116.10) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 10 Aug 2017 03:42:27 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx110.amr.corp.intel.com (10.18.116.10) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 10 Aug 2017 02:55:04 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.183]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.25]) with mapi id 14.03.0319.002; Thu, 10 Aug 2017 17:55:02 +0800 From: "Gao, Liming" To: "Marvin.Haeuser@outlook.com" , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" Thread-Topic: [PATCH v3 1/2] MdePkg/BaseLib: Add IsNodeInList() function. Thread-Index: AQHTDJH9gmDNebNGHE+Aj45jSciTKqJ9ZDjw Date: Thu, 10 Aug 2017 09:55:01 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14D76DA81@shsmsx102.ccr.corp.intel.com> References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v3 1/2] MdePkg/BaseLib: Add IsNodeInList() function. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Aug 2017 10:40:09 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Marvin: I have no other comments. Reviewed-by: Liming Gao Thanks Liming > -----Original Message----- > From: Marvin H=E4user [mailto:Marvin.Haeuser@outlook.com] > Sent: Friday, August 4, 2017 3:52 AM > To: edk2-devel@lists.01.org > Cc: Kinney, Michael D ; Gao, Liming > Subject: [PATCH v3 1/2] MdePkg/BaseLib: Add IsNodeInList() function. >=20 > This patch adds IsNodeInList() to BaseLib, which verifies the given > Node is part of the doubly-linked List provided. >=20 > V2: > - Rename "List" to "FirstEntry" and "Node" to "SecondEntry" to clarify = that > "FirstEntry" does not need to be the doubly-linked list's head node. >=20 > V3: > - Remove ASSERTs from IsNodeInList() which are present in > InternalBaseLibIsListValid(). >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Marvin Haeuser > --- > MdePkg/Library/BaseLib/LinkedList.c | 66 +++++++++++++++++++- > MdePkg/Include/Library/BaseLib.h | 27 ++++++++ > MdePkg/Library/BaseLib/BaseLibInternals.h | 28 --------- > 3 files changed, 92 insertions(+), 29 deletions(-) >=20 > diff --git a/MdePkg/Library/BaseLib/LinkedList.c b/MdePkg/Library/BaseLib= /LinkedList.c > index ba373f4b7be3..af27b0dd9a5c 100644 > --- a/MdePkg/Library/BaseLib/LinkedList.c > +++ b/MdePkg/Library/BaseLib/LinkedList.c > @@ -1,7 +1,7 @@ > /** @file > Linked List Library Functions. >=20 > - Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
> + Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the = BSD License > which accompanies this distribution. The full text of the license may= be found at > @@ -113,6 +113,70 @@ InternalBaseLibIsNodeInList ( > } >=20 > /** > + Checks whether FirstEntry and SecondEntry are part of the same doubly-= linked > + list. > + > + If FirstEntry is NULL, then ASSERT(). > + If FirstEntry->ForwardLink is NULL, then ASSERT(). > + If FirstEntry->BackLink is NULL, then ASSERT(). > + If SecondEntry is NULL, then ASSERT(); > + If PcdMaximumLinkedListLength is not zero, and List contains more than > + PcdMaximumLinkedListLength nodes, then ASSERT(). > + > + @param FirstEntry A pointer to a node in a linked list. > + @param SecondEntry A pointer to the node to locate. > + > + @retval TRUE SecondEntry is in the same doubly-linked list as FirstE= ntry. > + @retval FALSE SecondEntry isn't in the same doubly-linked list as Fir= stEntry, > + or FirstEntry is invalid. > + > +**/ > +BOOLEAN > +EFIAPI > +IsNodeInList ( > + IN CONST LIST_ENTRY *FirstEntry, > + IN CONST LIST_ENTRY *SecondEntry > + ) > +{ > + UINTN Count; > + CONST LIST_ENTRY *Ptr; > + > + // > + // ASSERT List not too long > + // > + ASSERT (InternalBaseLibIsListValid (FirstEntry)); > + > + ASSERT (SecondEntry !=3D NULL); > + > + Count =3D 0; > + Ptr =3D FirstEntry; > + > + // > + // Check to see if SecondEntry is a member of FirstEntry. > + // Exit early if the number of nodes in List >=3D PcdMaximumLinkedList= Length > + // > + do { > + Ptr =3D Ptr->ForwardLink; > + if (PcdGet32 (PcdMaximumLinkedListLength) > 0) { > + Count++; > + > + // > + // Return if the linked list is too long > + // > + if (Count =3D=3D PcdGet32 (PcdMaximumLinkedListLength)) { > + return (BOOLEAN)(Ptr =3D=3D SecondEntry); > + } > + } > + > + if (Ptr =3D=3D SecondEntry) { > + return TRUE; > + } > + } while (Ptr !=3D FirstEntry); > + > + return FALSE; > +} > + > +/** > Initializes the head node of a doubly-linked list, and returns the poi= nter to > the head node of the doubly-linked list. >=20 > diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Ba= seLib.h > index 791849b80406..40b96b761a85 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -2869,6 +2869,33 @@ PathCleanUpDirectories( >=20 >=20 > /** > + Checks whether FirstEntry and SecondEntry are part of the same doubly-= linked > + list. > + > + If FirstEntry is NULL, then ASSERT(). > + If FirstEntry->ForwardLink is NULL, then ASSERT(). > + If FirstEntry->BackLink is NULL, then ASSERT(). > + If SecondEntry is NULL, then ASSERT(); > + If PcdMaximumLinkedListLength is not zero, and List contains more than > + PcdMaximumLinkedListLength nodes, then ASSERT(). > + > + @param FirstEntry A pointer to a node in a linked list. > + @param SecondEntry A pointer to the node to locate. > + > + @retval TRUE SecondEntry is in the same doubly-linked list as FirstE= ntry. > + @retval FALSE SecondEntry isn't in the same doubly-linked list as Fir= stEntry, > + or FirstEntry is invalid. > + > +**/ > +BOOLEAN > +EFIAPI > +IsNodeInList ( > + IN CONST LIST_ENTRY *FirstEntry, > + IN CONST LIST_ENTRY *SecondEntry > + ); > + > + > +/** > Initializes the head node of a doubly linked list, and returns the poi= nter to > the head node of the doubly linked list. >=20 > diff --git a/MdePkg/Library/BaseLib/BaseLibInternals.h b/MdePkg/Library/B= aseLib/BaseLibInternals.h > index ea387ce37d27..9dca97a0dcc9 100644 > --- a/MdePkg/Library/BaseLib/BaseLibInternals.h > +++ b/MdePkg/Library/BaseLib/BaseLibInternals.h > @@ -340,34 +340,6 @@ InternalSwitchStack ( >=20 >=20 > /** > - Worker function that locates the Node in the List. > - > - By searching the List, finds the location of the Node in List. At the = same time, > - verifies the validity of this list. > - > - If List is NULL, then ASSERT(). > - If List->ForwardLink is NULL, then ASSERT(). > - If List->backLink is NULL, then ASSERT(). > - If Node is NULL, then ASSERT(); > - If PcdMaximumLinkedListLength is not zero, and prior to insertion the = number > - of nodes in ListHead, including the ListHead node, is greater than or > - equal to PcdMaximumLinkedListLength, then ASSERT(). > - > - @param List A pointer to a node in a linked list. > - @param Node A pointer to one nod. > - > - @retval TRUE Node is in List. > - @retval FALSE Node isn't in List, or List is invalid. > - > -**/ > -BOOLEAN > -EFIAPI > -IsNodeInList ( > - IN CONST LIST_ENTRY *List, > - IN CONST LIST_ENTRY *Node > - ); > - > -/** > Worker function that returns a bit field from Operand. >=20 > Returns the bitfield specified by the StartBit and the EndBit from Ope= rand. > -- > 2.12.2.windows.2