public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch v2] MdeModulePkg: Initialize local variable value before they are used
@ 2021-03-18  4:50 gaoliming
  2021-03-18 14:38 ` [edk2-devel] " Laszlo Ersek
  0 siblings, 1 reply; 2+ messages in thread
From: gaoliming @ 2021-03-18  4:50 UTC (permalink / raw)
  To: devel; +Cc: Jian J Wang, Hao A Wu

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3228
This change is to fix the false compiler error on GCC49 release build.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Signed-off-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
---
 In V2, add the comments for the false compiler warning

 MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c             | 5 +++++
 .../VariablePolicyHelperLib/VariablePolicyHelperLib.c        | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
index e99a812a44..1053695b3b 100644
--- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
+++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
@@ -1127,6 +1127,11 @@ AhciDmaTransfer (
     return EFI_INVALID_PARAMETER;
   }
 
+  //
+  // Set Status to suppress incorrect compiler/analyzer warnings
+  //
+  Status = EFI_SUCCESS;
+
   //
   // DMA buffer allocation. Needs to be done only once for both sync and async
   // DMA transfers irrespective of number of retries.
diff --git a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c
index 0c9299c8b0..6bcb95247f 100644
--- a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c
+++ b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c
@@ -115,6 +115,11 @@ CreateBasicVariablePolicy (
     return EFI_INVALID_PARAMETER;
   }
 
+  //
+  // Set NameSize to suppress incorrect compiler/analyzer warnings
+  //
+  NameSize  = 0;
+
   // Now we've gotta determine the total size of the buffer required for
   // the VariablePolicy structure.
   TotalSize = sizeof( VARIABLE_POLICY_ENTRY );
-- 
2.27.0.windows.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [edk2-devel] [Patch v2] MdeModulePkg: Initialize local variable value before they are used
  2021-03-18  4:50 [Patch v2] MdeModulePkg: Initialize local variable value before they are used gaoliming
@ 2021-03-18 14:38 ` Laszlo Ersek
  0 siblings, 0 replies; 2+ messages in thread
From: Laszlo Ersek @ 2021-03-18 14:38 UTC (permalink / raw)
  To: devel, gaoliming; +Cc: Jian J Wang, Hao A Wu

On 03/18/21 05:50, gaoliming wrote:
> BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3228
> This change is to fix the false compiler error on GCC49 release build.
> 
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Signed-off-by: Liming Gao <gaoliming@byosoft.com.cn>
> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
> ---
>  In V2, add the comments for the false compiler warning
> 
>  MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c             | 5 +++++
>  .../VariablePolicyHelperLib/VariablePolicyHelperLib.c        | 5 +++++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
> index e99a812a44..1053695b3b 100644
> --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
> +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AhciMode.c
> @@ -1127,6 +1127,11 @@ AhciDmaTransfer (
>      return EFI_INVALID_PARAMETER;
>    }
>  
> +  //
> +  // Set Status to suppress incorrect compiler/analyzer warnings
> +  //
> +  Status = EFI_SUCCESS;
> +
>    //
>    // DMA buffer allocation. Needs to be done only once for both sync and async
>    // DMA transfers irrespective of number of retries.

Yes, it's indeed a compiler problem. In the middle of the function, we
have control flow like this:

  if (Task == NULL) {
    for (Retry = 0; Retry < AHCI_COMMAND_RETRIES; Retry++) {
      Status = AhciStartCommand (...);
    }
  } else {
    if (!Task->IsStart) {
      Status = AhciStartCommand (...);
    }
    if (Task->IsStart) {
      Status = AhciCheckFisReceived (...);
    }
  }

There is no path through this without setting "Status", so the
subsequent warning is indeed unjustified.


> diff --git a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c
> index 0c9299c8b0..6bcb95247f 100644
> --- a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c
> +++ b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c
> @@ -115,6 +115,11 @@ CreateBasicVariablePolicy (
>      return EFI_INVALID_PARAMETER;
>    }
>  
> +  //
> +  // Set NameSize to suppress incorrect compiler/analyzer warnings
> +  //
> +  NameSize  = 0;
> +
>    // Now we've gotta determine the total size of the buffer required for
>    // the VariablePolicy structure.
>    TotalSize = sizeof( VARIABLE_POLICY_ENTRY );
> 

Also correct: NameSize is only read if (Name != NULL), but in that case,
NameSize is also set. And Name does not change between the two checks.

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks
Laszlo


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-18 14:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-18  4:50 [Patch v2] MdeModulePkg: Initialize local variable value before they are used gaoliming
2021-03-18 14:38 ` [edk2-devel] " Laszlo Ersek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox