public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Zhang, Shenglei" <shenglei.zhang@intel.com>
To: devel@edk2.groups.io
Cc: Michael Kubacki <michael.a.kubacki@intel.com>,
	Chasel Chiu <chasel.chiu@intel.com>,
	Nate DeSimone <nathaniel.l.desimone@intel.com>,
	Liming Gao <liming.gao@intel.com>
Subject: [PATCH v2 1/2] MinPlatformPkg/AcpiTables: Initialize variables before used
Date: Thu, 12 Sep 2019 11:27:18 +0800	[thread overview]
Message-ID: <20190912032720.38132-2-shenglei.zhang@intel.com> (raw)
In-Reply-To: <20190912032720.38132-1-shenglei.zhang@intel.com>

MadtStructs, NewMadtTable and MaxMadtStructCount are not initialized
before used or at the proper place. So assign values to them at the
beginning and change the logic when freeing MadtStructs and
NewMadtTable.

Cc: Michael Kubacki <michael.a.kubacki@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
---
 .../Acpi/AcpiTables/AcpiPlatform.c            | 21 +++++++++++--------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
index 5eb72792..2cc55ee8 100644
--- a/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
+++ b/Platform/Intel/MinPlatformPkg/Acpi/AcpiTables/AcpiPlatform.c
@@ -1,7 +1,7 @@
 /** @file
   ACPI Platform Driver
 
-Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2017-2019, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -867,13 +867,15 @@ InstallMadtFromScratch (
   UINT32                                              PcIoApicMask;
   UINTN                                               PcIoApicIndex;
 
+  MadtStructs = NULL;
+  NewMadtTable = NULL;
+  MaxMadtStructCount = 0;
+
   DetectApicIdMap();
 
   // Call for Local APIC ID Reorder
   SortCpuLocalApicInTable ();
 
-  NewMadtTable = NULL;
-
   MaxMadtStructCount = (UINT32) (
     MAX_CPU_NUM +    // processor local APIC structures
     MAX_CPU_NUM +    // processor local x2APIC structures
@@ -1115,14 +1117,15 @@ Done:
   //
   // Free memory
   //
-  for (MadtStructsIndex = 0; MadtStructsIndex < MaxMadtStructCount; MadtStructsIndex++) {
-    if (MadtStructs[MadtStructsIndex] != NULL) {
-      FreePool (MadtStructs[MadtStructsIndex]);
+  if (MadtStructs != NULL){
+    for (MadtStructsIndex = 0; MadtStructsIndex < MaxMadtStructCount; MadtStructsIndex++) {
+      if (MadtStructs[MadtStructsIndex] != NULL) {
+        FreePool (MadtStructs[MadtStructsIndex]);
+      }
     }
+    FreePool (MadtStructs);
   }
-
-  FreePool (MadtStructs);
-
+  
   if (NewMadtTable != NULL) {
     FreePool (NewMadtTable);
   }
-- 
2.18.0.windows.1


  reply	other threads:[~2019-09-12  3:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-12  3:27 [PATCH v2 0/2] Add error handling and initialize variables Zhang, Shenglei
2019-09-12  3:27 ` Zhang, Shenglei [this message]
2019-09-12  4:05   ` [PATCH v2 1/2] MinPlatformPkg/AcpiTables: Initialize variables before used Chiu, Chasel
2019-09-12  6:15   ` Kubacki, Michael A
2019-09-12 18:35   ` [edk2-devel] " Nate DeSimone
2019-09-12  3:27 ` [PATCH v2 2/2] MinPlatformPkg/AcpiTables: Add error handling to SortCpuLocalApicInTable Zhang, Shenglei
2019-09-12  4:06   ` Chiu, Chasel
2019-09-12  6:17   ` [edk2-devel] " Kubacki, Michael A
2019-09-12 18:36   ` Nate DeSimone
2019-09-12 21:03 ` [edk2-devel] [PATCH v2 0/2] Add error handling and initialize variables Nate DeSimone

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190912032720.38132-2-shenglei.zhang@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox