From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by mx.groups.io with SMTP id smtpd.web10.5392.1624006980800222285 for ; Fri, 18 Jun 2021 02:03:00 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GVuE4Rxj; spf=pass (domain: gmail.com, ip: 209.85.214.181, mailfrom: kuqin12@gmail.com) Received: by mail-pl1-f181.google.com with SMTP id o21so4347129pll.6 for ; Fri, 18 Jun 2021 02:03:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z6tCZ3a4WF7HPPufQNNrDNPm60gV46j5iubHMNGTqt0=; b=GVuE4Rxj9T0gQMN07NJluEJ83YrgTHiRJXc4bIL9i+gaWwkM+DFnfULljtrHAB+agQ 4e0y3VaqfcJuGvBFSFT4ClHyhU1ewvw2NDG18YU177ATVl61IVjffbXEhMNn9CkTUXY2 LKZHl8J8GDYu+61EvhcDwfe1KhDtQg5Lx8u8babbIM2N1ZABJpwqyBgdclJOEbPTl5Z+ qsHlEYZo+//oanq0rGET33HrzfX3AK9+G6I+nJNe4jBm4A3bfY7+gyhFBrYG+oYrUppQ wodF4tV1pXGK3++d0WprVwTbvvDhGHDG/bYQyRjm+oQkucfNA0dmQlRHQHz7IGjO+ZvX 1raw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z6tCZ3a4WF7HPPufQNNrDNPm60gV46j5iubHMNGTqt0=; b=JwzyeQVm8J019wtgB7yXrwF+80y0JQ7Px1q/IrcwU+T5R7Potd8WsI5EzL9b2fa2v0 3mL9VLOxMktsvjlsDSrMbLqJVXWmJBA24CcHLX0ptbS0gAN8z2ywNtdcyxueATdw3/ro QMUApYoIXwRAFpOoBDg2Xaqk0sv8xRN+kp1rS14Xa1CstHf/RE9+bn3a6L+Qoi4mgJSw vvgZBXD0uSuLUkHxwa4akmkqrWWK0mlt2KCd5v7rkxL0htlZ+P2++PAeuQl1/85YAHRH X1RFF/fUmhe/R7bQGSEnGVPcCjr+KYyDxecx+MMfnoh/QUqncyqGYUgDpOVtFtMJ/02Y ZU0w== X-Gm-Message-State: AOAM532dNgsMOaXBbkFqF1edOWmVlh10TSKyjzrtdRugxHKuu5A//odc rXsL7nsCZQYo6HKcP8IDlV9lYv8YWDCZ1A== X-Google-Smtp-Source: ABdhPJza9rWiEmC3dqu0Rx0vWY3ysEe4MtXQXBlvq6ctMlMpxbJReTyFkygAuA3v8/hy7UWv4kkrvA== X-Received: by 2002:a17:90a:3801:: with SMTP id w1mr21048945pjb.138.1624006980145; Fri, 18 Jun 2021 02:03:00 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([50.35.88.161]) by smtp.gmail.com with ESMTPSA id b1sm7702512pgb.91.2021.06.18.02.02.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 02:02:59 -0700 (PDT) From: "Kun Qin" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Eric Dong , Ray Ni Subject: [PATCH v2 5/6] MdeModulePkg: SmmLockBoxDxeLib: Updated MessageLength calculation Date: Fri, 18 Jun 2021 02:02:42 -0700 Message-Id: <20210618090243.2517-6-kuqin12@gmail.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20210618090243.2517-1-kuqin12@gmail.com> References: <20210618090243.2517-1-kuqin12@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3398 This change replaced the calculation of communication buffer size from explicitly adding the size of each member with the OFFSET macro function. This will make the structure field defition change transparent to consumers. Cc: Jian J Wang Cc: Hao A Wu Cc: Eric Dong Cc: Ray Ni Signed-off-by: Kun Qin --- Notes: v2: - Newly added in v2 MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c index 2cbffe889e1f..66fbe4dd961c 100644 --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c +++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.c @@ -79,8 +79,7 @@ LockBoxGetSmmCommBuffer ( return mLockBoxSmmCommBuffer; } - MinimalSizeNeeded = sizeof (EFI_GUID) + - sizeof (UINTN) + + MinimalSizeNeeded = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SAVE), MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES), MAX (sizeof (EFI_SMM_LOCK_BOX_PARAMETER_UPDATE), @@ -142,7 +141,7 @@ SaveLockBox ( EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; EFI_SMM_LOCK_BOX_PARAMETER_SAVE *LockBoxParameterSave; EFI_SMM_COMMUNICATE_HEADER *CommHeader; - UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)]; + UINT8 TempCommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE)]; UINT8 *CommBuffer; UINTN CommSize; @@ -182,7 +181,7 @@ SaveLockBox ( // // Send command // - CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE); + CommSize = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SAVE); Status = SmmCommunication->Communicate ( SmmCommunication, &CommBuffer[0], @@ -224,7 +223,7 @@ SetLockBoxAttributes ( EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES *LockBoxParameterSetAttributes; EFI_SMM_COMMUNICATE_HEADER *CommHeader; - UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES)]; + UINT8 TempCommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES)]; UINT8 *CommBuffer; UINTN CommSize; @@ -264,7 +263,7 @@ SetLockBoxAttributes ( // // Send command // - CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES); + CommSize = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_SET_ATTRIBUTES); Status = SmmCommunication->Communicate ( SmmCommunication, &CommBuffer[0], @@ -314,7 +313,7 @@ UpdateLockBox ( EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; EFI_SMM_LOCK_BOX_PARAMETER_UPDATE *LockBoxParameterUpdate; EFI_SMM_COMMUNICATE_HEADER *CommHeader; - UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE)]; + UINT8 TempCommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE)]; UINT8 *CommBuffer; UINTN CommSize; @@ -355,7 +354,7 @@ UpdateLockBox ( // // Send command // - CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE); + CommSize = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_UPDATE); Status = SmmCommunication->Communicate ( SmmCommunication, &CommBuffer[0], @@ -403,7 +402,7 @@ RestoreLockBox ( EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; EFI_SMM_LOCK_BOX_PARAMETER_RESTORE *LockBoxParameterRestore; EFI_SMM_COMMUNICATE_HEADER *CommHeader; - UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE)]; + UINT8 TempCommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE)]; UINT8 *CommBuffer; UINTN CommSize; @@ -449,7 +448,7 @@ RestoreLockBox ( // // Send command // - CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE); + CommSize = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE); Status = SmmCommunication->Communicate ( SmmCommunication, &CommBuffer[0], @@ -488,7 +487,7 @@ RestoreAllLockBoxInPlace ( EFI_SMM_COMMUNICATION_PROTOCOL *SmmCommunication; EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE *LockBoxParameterRestoreAllInPlace; EFI_SMM_COMMUNICATE_HEADER *CommHeader; - UINT8 TempCommBuffer[sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)]; + UINT8 TempCommBuffer[OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE)]; UINT8 *CommBuffer; UINTN CommSize; @@ -518,7 +517,7 @@ RestoreAllLockBoxInPlace ( // // Send command // - CommSize = sizeof(EFI_GUID) + sizeof(UINTN) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE); + CommSize = OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(EFI_SMM_LOCK_BOX_PARAMETER_RESTORE_ALL_IN_PLACE); Status = SmmCommunication->Communicate ( SmmCommunication, &CommBuffer[0], -- 2.31.1.windows.1