From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A39801A20B7 for ; Fri, 23 Sep 2016 01:25:27 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP; 23 Sep 2016 01:25:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,381,1470726000"; d="scan'208";a="172311829" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by fmsmga004.fm.intel.com with ESMTP; 23 Sep 2016 01:25:26 -0700 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Liming Gao , Eric Dong , Dandan Bi Date: Fri, 23 Sep 2016 16:25:10 +0800 Message-Id: <20160923082521.99872-3-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20160923082521.99872-1-ruiyu.ni@intel.com> References: <20160923082521.99872-1-ruiyu.ni@intel.com> Subject: [PATCH 02/13] MdeModulePkg/HiiDatabase: Move common code to LocatePackageList() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Sep 2016 08:25:27 -0000 Contributed-under: TianoCore Contribution Agreement 1.0 Cc: Liming Gao Cc: Eric Dong Cc: Dandan Bi Signed-off-by: Ruiyu Ni --- MdeModulePkg/Universal/HiiDatabaseDxe/Image.c | 88 +++++++++++---------------- 1 file changed, 34 insertions(+), 54 deletions(-) diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c index 5bdeacc..b72d556 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c @@ -569,6 +569,37 @@ ImageToBlt ( return EFI_SUCCESS; } +/** + Return the HII package list identified by PackageList HII handle. + + @param Database Pointer to HII database list header. + @param PackageList HII handle of the package list to locate. + + @retval The HII package list instance. +**/ +HII_DATABASE_PACKAGE_LIST_INSTANCE * +LocatePackageList ( + IN LIST_ENTRY *Database, + IN EFI_HII_HANDLE PackageList + ) +{ + LIST_ENTRY *Link; + HII_DATABASE_RECORD *Record; + + // + // Get the specified package list and image package. + // + for (Link = GetFirstNode (Database); + !IsNull (Database, Link); + Link = GetNextNode (Database, Link) + ) { + Record = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE); + if (Record->Handle == PackageList) { + return Record->PackageList; + } + } + return NULL; +} /** This function adds the image Image to the group of images owned by PackageList, and returns @@ -598,8 +629,6 @@ HiiNewImage ( ) { HII_DATABASE_PRIVATE_DATA *Private; - LIST_ENTRY *Link; - HII_DATABASE_RECORD *DatabaseRecord; HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode; HII_IMAGE_PACKAGE_INSTANCE *ImagePackage; UINT8 *ImageBlock; @@ -618,24 +647,7 @@ HiiNewImage ( } Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This); - - // - // Get the specified package list - // - - PackageListNode = NULL; - - for (Link = Private->DatabaseList.ForwardLink; - Link != &Private->DatabaseList; - Link = Link->ForwardLink - ) { - DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE); - if (DatabaseRecord->Handle == PackageList) { - PackageListNode = DatabaseRecord->PackageList; - break; - } - } - + PackageListNode = LocatePackageList (&Private->DatabaseList, PackageList); if (PackageListNode == NULL) { return EFI_NOT_FOUND; } @@ -820,8 +832,6 @@ HiiGetImage ( ) { HII_DATABASE_PRIVATE_DATA *Private; - LIST_ENTRY *Link; - HII_DATABASE_RECORD *DatabaseRecord; HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode; HII_IMAGE_PACKAGE_INSTANCE *ImagePackage; UINT8 *ImageBlock; @@ -845,21 +855,7 @@ HiiGetImage ( } Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This); - - // - // Get the specified package list and image package. - // - PackageListNode = NULL; - for (Link = Private->DatabaseList.ForwardLink; - Link != &Private->DatabaseList; - Link = Link->ForwardLink - ) { - DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE); - if (DatabaseRecord->Handle == PackageList) { - PackageListNode = DatabaseRecord->PackageList; - break; - } - } + PackageListNode = LocatePackageList (&Private->DatabaseList, PackageList); if (PackageListNode == NULL) { return EFI_NOT_FOUND; } @@ -1011,8 +1007,6 @@ HiiSetImage ( ) { HII_DATABASE_PRIVATE_DATA *Private; - LIST_ENTRY *Link; - HII_DATABASE_RECORD *DatabaseRecord; HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode; HII_IMAGE_PACKAGE_INSTANCE *ImagePackage; UINT8 *ImageBlock; @@ -1043,21 +1037,7 @@ HiiSetImage ( } Private = HII_IMAGE_DATABASE_PRIVATE_DATA_FROM_THIS (This); - - // - // Get the specified package list and image package. - // - PackageListNode = NULL; - for (Link = Private->DatabaseList.ForwardLink; - Link != &Private->DatabaseList; - Link = Link->ForwardLink - ) { - DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE); - if (DatabaseRecord->Handle == PackageList) { - PackageListNode = DatabaseRecord->PackageList; - break; - } - } + PackageListNode = LocatePackageList (&Private->DatabaseList, PackageList); if (PackageListNode == NULL) { return EFI_NOT_FOUND; } -- 2.9.0.windows.1