Skip to content
This repository was archived by the owner on Mar 28, 2025. It is now read-only.

Commit fb5a2de

Browse files
committed
CppCheck: Fix some errors and warning reported by CppCheck
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 <tinhn@amperecomputing.com>
1 parent c8eb585 commit fb5a2de

File tree

8 files changed

+32
-19
lines changed

8 files changed

+32
-19
lines changed

Platform/Ampere/AmperePlatformPkg/Drivers/PlatformBootManagerDxe/PlatformBootManagerDxe.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,18 @@ GetUsbDescription (
339339
&gEfiDevicePathProtocolGuid,
340340
(VOID **)&UsbDevicePath
341341
);
342+
if (EFI_ERROR (Status)) {
343+
return NULL;
344+
}
342345

343346
Status = gBS->LocateDevicePath (
344347
&gEfiUsbIoProtocolGuid,
345348
&UsbDevicePath,
346349
&UsbHandle
347350
);
351+
if (EFI_ERROR (Status)) {
352+
return NULL;
353+
}
348354

349355
Status = gBS->HandleProtocol (
350356
UsbHandle,
@@ -598,6 +604,9 @@ CreateNewBootOption (
598604
Handle,
599605
OsDescription.OSLoaderPath
600606
);
607+
if (BootOptionDevicePath == NULL) {
608+
return EFI_OUT_OF_RESOURCES;
609+
}
601610
//
602611
// Skip if Boot Option already exists
603612
//
@@ -758,11 +767,9 @@ CacheLegacyBootOptions (
758767
UINTN NVBootOptionCount;
759768
UINTN CacheBootOptionCount;
760769
EFI_BOOT_MANAGER_LOAD_OPTION *NVBootOptions;
761-
BOOLEAN AlreadyExistsInBootOptionsList;
762770

763771
NVBootOptionCount = 0;
764772
NVBootOptions = NULL;
765-
AlreadyExistsInBootOptionsList = FALSE;
766773
CacheBootOptionCount = *BootOptionListCount;
767774

768775
//

Platform/Ampere/AmperePlatformPkg/Drivers/UsbCdcEthernetDxe/DriverBinding.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,13 +681,21 @@ UsbCdcEthernetDriverStop (
681681
This->DriverBindingHandle,
682682
ControllerHandle
683683
);
684+
if (EFI_ERROR (Status)) {
685+
DEBUG ((DEBUG_ERROR, "%d: Failed to close the bus driver - %r",__LINE__, Status));
686+
return Status;
687+
}
684688

685689
Status = gBS->CloseProtocol (
686690
ControllerHandle,
687691
&gEfiUsbIoProtocolGuid,
688692
This->DriverBindingHandle,
689693
ControllerHandle
690694
);
695+
if (EFI_ERROR (Status)) {
696+
DEBUG ((DEBUG_ERROR, "%d: Failed to close the bus driver - %r",__LINE__, Status));
697+
return Status;
698+
}
691699

692700
return EFI_SUCCESS;
693701
}

Platform/Ampere/AmperePlatformPkg/Drivers/UsbCdcEthernetDxe/SimpleNetwork.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,13 @@ SnpReceiveFilters (
426426
UINT8 Temp;
427427
UINT16 CdcFilterMask;
428428

429-
Mode = This->Mode;
430-
CdcFilterMask = USB_CDC_ECM_PACKET_TYPE_DIRECTED | USB_CDC_ECM_PACKET_TYPE_BROADCAST;
431-
432429
if (This == NULL) {
433430
return EFI_INVALID_PARAMETER;
434431
}
435432

433+
Mode = This->Mode;
434+
CdcFilterMask = USB_CDC_ECM_PACKET_TYPE_DIRECTED | USB_CDC_ECM_PACKET_TYPE_BROADCAST;
435+
436436
//
437437
// Check that driver was started and initialised
438438
//

Platform/Ampere/JadePkg/Drivers/SmbiosCpuDxe/SmbiosCpuDxe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ GetCacheConfig (
308308
BOOLEAN SupportWT;
309309

310310
Val = ReadCCSIDR (Level);
311-
SupportWT = (Val & (1 << 31)) ? TRUE : FALSE;
312-
SupportWB = (Val & (1 << 30)) ? TRUE : FALSE;
311+
SupportWT = (Val & (1U << 31)) ? TRUE : FALSE;
312+
SupportWB = (Val & (1U << 30)) ? TRUE : FALSE;
313313
if (SupportWT && SupportWB) {
314314
return 2; /* Varies with Memory Address */
315315
}

Platform/Ampere/JadePkg/Library/IOExpanderLib/IOExpanderLib.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ IOExpanderI2cRead (
7777
EFI_STATUS Status;
7878
UINT32 NumberOfRegisterAddress;
7979

80-
Status = EFI_SUCCESS;
81-
8280
Status = I2cProbe (I2cBus, IO_EXPANDER_I2C_BUS_SPEED);
8381
if (EFI_ERROR (Status)) {
8482
return Status;
@@ -90,17 +88,17 @@ IOExpanderI2cRead (
9088
return Status;
9189
}
9290

93-
return Status;
91+
return EFI_SUCCESS;
9492
}
9593

9694
STATIC
9795
EFI_STATUS
9896
IOExpanderI2cWrite (
99-
IN UINT32 I2cBus,
100-
IN UINT32 I2cAddress,
101-
IN UINT8 *RegisterAddress,
102-
IN UINT32 *NumberOfRegister,
103-
IN UINT8 *Data
97+
IN UINT32 I2cBus,
98+
IN UINT32 I2cAddress,
99+
IN CONST UINT8 *RegisterAddress,
100+
IN CONST UINT32 *NumberOfRegister,
101+
IN UINT8 *Data
104102
)
105103
{
106104
EFI_STATUS Status;
@@ -120,7 +118,7 @@ IOExpanderI2cWrite (
120118
return Status;
121119
}
122120

123-
return Status;
121+
return EFI_SUCCESS;
124122
}
125123

126124
/**

Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieDeviceConfigDxe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ DriverCallback (
922922
switch (Action) {
923923
case EFI_BROWSER_ACTION_CHANGING:
924924
if ((QuestionId >= DEVICE_KEY)
925-
& (QuestionId <= (DEVICE_KEY + MAX_DEVICE)))
925+
& (QuestionId < (DEVICE_KEY + MAX_DEVICE)))
926926
{
927927
Status = UpdateDeviceForm (QuestionId - DEVICE_KEY, PrivateData);
928928
if (EFI_ERROR (Status)) {

Silicon/Ampere/AmpereAltraPkg/Drivers/Tcg2Dxe/Tcg2Dxe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ TcgDxeHashLogExtendEvent (
11161116
{
11171117
EFI_STATUS Status;
11181118
TPML_DIGEST_VALUES DigestList;
1119-
TCG_PCR_EVENT2_HDR NoActionEvent;
1119+
TCG_PCR_EVENT2_HDR NoActionEvent = {0};
11201120

11211121
if (!mTcgDxeData.BsCap.TPMPresentFlag) {
11221122
return EFI_DEVICE_ERROR;

Silicon/Ampere/AmpereAltraPkg/Library/ArmSpciLib/ArmSpciSvcLib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
#define OEN_SPCI_END 0x3F
9393

9494
#define SPCI_SMC(spci_fid) ((OEN_SPCI_START << FUNCID_OEN_SHIFT) | \
95-
(1 << 31) | (spci_fid))
95+
(1U << 31) | (spci_fid))
9696
#define SPCI_MISC_32(misc_fid) ((SMC_32 << FUNCID_CC_SHIFT) | \
9797
SPCI_FID_MISC_FLAG | \
9898
SPCI_SMC ((misc_fid) << SPCI_FID_MISC_SHIFT))

0 commit comments

Comments
 (0)