Skip to content

Commit

Permalink
CppCheck: Fix some errors and warning reported by CppCheck
Browse files Browse the repository at this point in the history
This fix uses CppCheck version 2.7
Command options:
  --cppcheck-build-dir=build
  --enable=warning,performance,portability
  --verbose
  --language=c
  --force
  --std=c11

The errors and warnings:
  - Null pointer redundant check.
  - Integer overflow.
  - Array index out of bounds conditions.
  - Use uninitialized variables.
  - Some parameters can be declared as a constant.

Signed-off-by: Tinh Nguyen <[email protected]>
  • Loading branch information
tinhnampere committed Mar 15, 2022
1 parent c8eb585 commit fb5a2de
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,18 @@ GetUsbDescription (
&gEfiDevicePathProtocolGuid,
(VOID **)&UsbDevicePath
);
if (EFI_ERROR (Status)) {
return NULL;
}

Status = gBS->LocateDevicePath (
&gEfiUsbIoProtocolGuid,
&UsbDevicePath,
&UsbHandle
);
if (EFI_ERROR (Status)) {
return NULL;
}

Status = gBS->HandleProtocol (
UsbHandle,
Expand Down Expand Up @@ -598,6 +604,9 @@ CreateNewBootOption (
Handle,
OsDescription.OSLoaderPath
);
if (BootOptionDevicePath == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Skip if Boot Option already exists
//
Expand Down Expand Up @@ -758,11 +767,9 @@ CacheLegacyBootOptions (
UINTN NVBootOptionCount;
UINTN CacheBootOptionCount;
EFI_BOOT_MANAGER_LOAD_OPTION *NVBootOptions;
BOOLEAN AlreadyExistsInBootOptionsList;

NVBootOptionCount = 0;
NVBootOptions = NULL;
AlreadyExistsInBootOptionsList = FALSE;
CacheBootOptionCount = *BootOptionListCount;

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,13 +681,21 @@ UsbCdcEthernetDriverStop (
This->DriverBindingHandle,
ControllerHandle
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%d: Failed to close the bus driver - %r",__LINE__, Status));
return Status;
}

Status = gBS->CloseProtocol (
ControllerHandle,
&gEfiUsbIoProtocolGuid,
This->DriverBindingHandle,
ControllerHandle
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%d: Failed to close the bus driver - %r",__LINE__, Status));
return Status;
}

return EFI_SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,13 @@ SnpReceiveFilters (
UINT8 Temp;
UINT16 CdcFilterMask;

Mode = This->Mode;
CdcFilterMask = USB_CDC_ECM_PACKET_TYPE_DIRECTED | USB_CDC_ECM_PACKET_TYPE_BROADCAST;

if (This == NULL) {
return EFI_INVALID_PARAMETER;
}

Mode = This->Mode;
CdcFilterMask = USB_CDC_ECM_PACKET_TYPE_DIRECTED | USB_CDC_ECM_PACKET_TYPE_BROADCAST;

//
// Check that driver was started and initialised
//
Expand Down
4 changes: 2 additions & 2 deletions Platform/Ampere/JadePkg/Drivers/SmbiosCpuDxe/SmbiosCpuDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ GetCacheConfig (
BOOLEAN SupportWT;

Val = ReadCCSIDR (Level);
SupportWT = (Val & (1 << 31)) ? TRUE : FALSE;
SupportWB = (Val & (1 << 30)) ? TRUE : FALSE;
SupportWT = (Val & (1U << 31)) ? TRUE : FALSE;
SupportWB = (Val & (1U << 30)) ? TRUE : FALSE;
if (SupportWT && SupportWB) {
return 2; /* Varies with Memory Address */
}
Expand Down
16 changes: 7 additions & 9 deletions Platform/Ampere/JadePkg/Library/IOExpanderLib/IOExpanderLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ IOExpanderI2cRead (
EFI_STATUS Status;
UINT32 NumberOfRegisterAddress;

Status = EFI_SUCCESS;

Status = I2cProbe (I2cBus, IO_EXPANDER_I2C_BUS_SPEED);
if (EFI_ERROR (Status)) {
return Status;
Expand All @@ -90,17 +88,17 @@ IOExpanderI2cRead (
return Status;
}

return Status;
return EFI_SUCCESS;
}

STATIC
EFI_STATUS
IOExpanderI2cWrite (
IN UINT32 I2cBus,
IN UINT32 I2cAddress,
IN UINT8 *RegisterAddress,
IN UINT32 *NumberOfRegister,
IN UINT8 *Data
IN UINT32 I2cBus,
IN UINT32 I2cAddress,
IN CONST UINT8 *RegisterAddress,
IN CONST UINT32 *NumberOfRegister,
IN UINT8 *Data
)
{
EFI_STATUS Status;
Expand All @@ -120,7 +118,7 @@ IOExpanderI2cWrite (
return Status;
}

return Status;
return EFI_SUCCESS;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ DriverCallback (
switch (Action) {
case EFI_BROWSER_ACTION_CHANGING:
if ((QuestionId >= DEVICE_KEY)
& (QuestionId <= (DEVICE_KEY + MAX_DEVICE)))
& (QuestionId < (DEVICE_KEY + MAX_DEVICE)))
{
Status = UpdateDeviceForm (QuestionId - DEVICE_KEY, PrivateData);
if (EFI_ERROR (Status)) {
Expand Down
2 changes: 1 addition & 1 deletion Silicon/Ampere/AmpereAltraPkg/Drivers/Tcg2Dxe/Tcg2Dxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ TcgDxeHashLogExtendEvent (
{
EFI_STATUS Status;
TPML_DIGEST_VALUES DigestList;
TCG_PCR_EVENT2_HDR NoActionEvent;
TCG_PCR_EVENT2_HDR NoActionEvent = {0};

if (!mTcgDxeData.BsCap.TPMPresentFlag) {
return EFI_DEVICE_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
#define OEN_SPCI_END 0x3F

#define SPCI_SMC(spci_fid) ((OEN_SPCI_START << FUNCID_OEN_SHIFT) | \
(1 << 31) | (spci_fid))
(1U << 31) | (spci_fid))
#define SPCI_MISC_32(misc_fid) ((SMC_32 << FUNCID_CC_SHIFT) | \
SPCI_FID_MISC_FLAG | \
SPCI_SMC ((misc_fid) << SPCI_FID_MISC_SHIFT))
Expand Down

0 comments on commit fb5a2de

Please sign in to comment.