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

Commit b40b353

Browse files
kellycouchgldiviney
authored andcommitted
Enable warnings as error for linux/windows release builds Fix Windows and Linux build warnings Fix klocwork 4071
Signed-off-by: Kelly J Couch <kelly.j.couch@intel.com>
1 parent 2354bee commit b40b353

File tree

10 files changed

+65
-36
lines changed

10 files changed

+65
-36
lines changed

CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,18 @@ add_definitions(
123123

124124
# Promote warnings to errors only for release builds
125125
if(MSVC)
126-
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O2")
127-
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O2 /WX")
128-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
129-
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /WX")
126+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O2 /WX")
127+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /WX")
130128
set(CMAKE_C_FLAGS_DEBUG_ "${CMAKE_C_FLAGS_DEBUG} /Od")
131129
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od")
132130
else()
133131
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -fno-strict-aliasing -D_FORTIFY_SOURCE=2")
134-
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -Werror")
135132
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-strict-aliasing -D_FORTIFY_SOURCE=2")
136-
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -Werror")
133+
if(LNX_BUILD)
134+
#A few warnings yet to resolve under esx
135+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Werror")
136+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Werror")
137+
endif()
137138
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -ggdb")
138139
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -ggdb")
139140
endif()

DcpmPkg/cli/Common.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,8 +1304,16 @@ FileExists(
13041304
#ifdef OS_BUILD
13051305
pFileHandle = NULL;
13061306
ReturnCode = OpenFile(pDumpUserPath, &pFileHandle, NULL, FALSE);
1307-
*pExists = ReturnCode != EFI_NOT_FOUND;
1308-
ReturnCode = EFI_SUCCESS;
1307+
if (EFI_NOT_FOUND == ReturnCode)
1308+
{
1309+
*pExists = FALSE;
1310+
ReturnCode = EFI_SUCCESS;
1311+
}
1312+
else if (EFI_SUCCESS == ReturnCode)
1313+
{
1314+
*pExists = TRUE;
1315+
pFileHandle->Close(pFileHandle);
1316+
}
13091317
#else
13101318
EFI_DEVICE_PATH_PROTOCOL *pDevicePathProtocol = NULL;
13111319
CHAR16 *pDumpFilePath = NULL;
@@ -1327,11 +1335,11 @@ FileExists(
13271335
*pExists = TRUE;
13281336
pFileHandle->Close(pFileHandle);
13291337
}
1330-
#endif
1338+
13311339
Finish:
1332-
#ifndef OS_BUILD
13331340
FREE_POOL_SAFE(pDumpFilePath);
13341341
#endif
1342+
13351343
NVDIMM_EXIT_I64(ReturnCode);
13361344
return ReturnCode;
13371345
}

DcpmPkg/cli/NvmDimmCli.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include "ShowHostServerCommand.h"
5757
#include "ShowPerformanceCommand.h"
5858
#include "ShowCmdAccessPolicyCommand.h"
59+
#include "DeletePcdCommand.h"
5960

6061
#if _BullseyeCoverage
6162
#ifndef OS_BUILD

src/os/cli_cmds/DumpSupportCommand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ DumpSupportCommand(
216216
PrintHeaderInfo(pPrintDIMMHeaderInfo);
217217
FREE_POOL_SAFE(pPrintDIMMHeaderInfo);
218218
for (Index = 0; Index < MAX_DIMM_SPECIFIC_CMDS; ++Index) {
219-
pCmdInputWithDimmId = CatSPrint(NULL, &(DumpCmdsPerDimm[Index].cmd), pDimms[DimmIndex].DimmHandle);
219+
pCmdInputWithDimmId = CatSPrint(NULL, DumpCmdsPerDimm[Index].cmd, pDimms[DimmIndex].DimmHandle);
220220
PrintAndExecuteCommand(pCmdInputWithDimmId);
221221
}
222222
if (pDictUserPath != NULL) {

src/os/efi_shim/os_efi_api.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <conio.h>
2828
#include <time.h>
2929
#include <wchar.h>
30+
#include <string.h>
3031
#else
3132
#include <unistd.h>
3233
#include <wchar.h>
@@ -130,7 +131,7 @@ typedef struct _smbios_table_recording
130131
#define PASS_THRU_OFFSET (ACPI_PMTT_OFFSET + ACPI_PMTT_SIZE) //40k
131132

132133
int g_pass_thru_cnt = 0;
133-
size_t g_pass_thru_playback_offset = 0;
134+
long g_pass_thru_playback_offset = 0;
134135

135136
#define REC_FILE_PATH g_recording_fullpath
136137
#define PLAYBACK_ENABLED() g_playback_mode
@@ -206,7 +207,6 @@ EFI_STATUS init_record_file(char * recording_file_path)
206207
EFI_STATUS update_record_size(RecordType type, FILE * file_stream, UINT32 size, BOOLEAN increment)
207208
{
208209
recording_file rc;
209-
UINT32 offset;
210210

211211
//seek to the begining of the file
212212
if (0 != fseek(file_stream, 0, SEEK_SET))
@@ -305,13 +305,13 @@ EFI_STATUS seek_to_record_offset(RecordType type, FILE * file_stream, UINT32 *re
305305
if (0 != fseek(file_stream, 0, SEEK_SET))
306306
{
307307
NVDIMM_ERR("Failed seeking to the begining of the file\n");
308-
return -1;
308+
return EFI_DEVICE_ERROR;
309309
}
310310

311311
if (1 != fread(&rc, sizeof(recording_file), 1, file_stream))
312312
{
313313
NVDIMM_ERR("Failed to read the recording file header\n");
314-
return -1;
314+
return EFI_DEVICE_ERROR;
315315
}
316316

317317
switch (type)
@@ -338,14 +338,14 @@ EFI_STATUS seek_to_record_offset(RecordType type, FILE * file_stream, UINT32 *re
338338
break;
339339
default:
340340
NVDIMM_ERR("Unknown record type\n");
341-
return -1;
341+
return EFI_INVALID_PARAMETER;
342342
}
343343

344344
//seek to the begining of the record type partition
345345
if (0 != fseek(file_stream, offset, SEEK_SET))
346346
{
347347
NVDIMM_ERR("Failed seeking to the begining of the file\n");
348-
return -1;
348+
return EFI_DEVICE_ERROR;
349349
}
350350
return EFI_SUCCESS;
351351
}
@@ -539,7 +539,6 @@ passthru_record_finalize(
539539
EFI_STATUS PassthruReturnCode
540540
)
541541
{
542-
EFI_STATUS Rc = EFI_SUCCESS;
543542
UINT32 total_write_sz = 0;
544543
if (!RECORD_ENABLED())
545544
{
@@ -701,18 +700,21 @@ save_table_to_file(
701700
if (EFI_SUCCESS != (Rc = seek_to_record_offset(type, f_ptr, &record_size)))
702701
{
703702
NVDIMM_ERR("Failed seeking to the ACPI partition\n");
704-
return Rc;
703+
goto Finish;
705704
}
706705

707706
if (table && 1 != fwrite(table, table->Length, 1, f_ptr))
708707
{
709708
Rc = EFI_END_OF_FILE;
709+
goto Finish;
710710
}
711711

712712
if (table)
713713
{
714714
Rc = update_record_size(type, f_ptr, table->Length, FALSE);
715715
}
716+
717+
Finish:
716718
fclose(f_ptr);
717719
return Rc;
718720
}
@@ -741,7 +743,7 @@ load_table_from_file(
741743
if (EFI_SUCCESS != (Rc = seek_to_record_offset(type, f_ptr, &size)))
742744
{
743745
NVDIMM_ERR("Failed seeking to the ACPI partition\n");
744-
return Rc;
746+
goto Finish;
745747
}
746748

747749
if (!size)
@@ -763,6 +765,7 @@ load_table_from_file(
763765
}
764766
}
765767

768+
Finish:
766769
fclose(f_ptr);
767770
return Rc;
768771
}
@@ -883,8 +886,7 @@ GetFirstAndBoundSmBiosStructPointer(
883886
OUT SMBIOS_VERSION *pSmbiosVersion
884887
)
885888
{
886-
EFI_STATUS ReturnCode = EFI_SUCCESS;;
887-
int rc = 0;
889+
EFI_STATUS ReturnCode = EFI_SUCCESS;
888890
FILE *f_ptr;
889891
smbios_table_recording recording;
890892
UINT32 record_size = 0;
@@ -926,7 +928,7 @@ GetFirstAndBoundSmBiosStructPointer(
926928
NVDIMM_ERR("Failed to write to recording file: %s\n", REC_FILE_PATH);
927929
ReturnCode = EFI_END_OF_FILE;
928930
}
929-
update_record_size(RtSmbios, f_ptr, sizeof(smbios_table_recording) + gSmbiosTableSize, FALSE);
931+
update_record_size(RtSmbios, f_ptr, (UINT32)(sizeof(smbios_table_recording) + gSmbiosTableSize), FALSE);
930932
}
931933
fclose(f_ptr);
932934
}
@@ -938,7 +940,7 @@ GetFirstAndBoundSmBiosStructPointer(
938940
{
939941
if (NULL == gSmbiosTable) {
940942
//seek it to pass thru partition
941-
if (EFI_SUCCESS != (rc = seek_to_record_offset(RtSmbios, f_ptr, &record_size)))
943+
if (EFI_SUCCESS != seek_to_record_offset(RtSmbios, f_ptr, &record_size))
942944
{
943945
NVDIMM_ERR("Failed seeking to the SMBIOS partition\n");
944946
ReturnCode = EFI_END_OF_FILE;
@@ -950,9 +952,9 @@ GetFirstAndBoundSmBiosStructPointer(
950952
ReturnCode = EFI_END_OF_FILE;
951953
}
952954

953-
if (0 == recording.size)
955+
if (SMBIOS_SIZE < recording.size || 0 == recording.size)
954956
{
955-
NVDIMM_ERR("SMBIOS table in file %s reports size of 0.\n", REC_FILE_PATH);
957+
NVDIMM_ERR("SMBIOS table in file %s reports size of %d.\n", REC_FILE_PATH, recording.size);
956958
ReturnCode = EFI_END_OF_FILE;
957959
}
958960
else

src/os/efi_shim/os_efi_api.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <Dimm.h>
1212
#include <UefiBaseType.h>
1313
#include <FwUtility.h>
14+
#include <SmbiosUtility.h>
1415
#include <time.h>
1516

1617
typedef enum {
@@ -269,4 +270,19 @@ UnicodeSPrint(
269270
UINT32
270271
get_first_arg_from_va_list(VA_LIST args);
271272

273+
274+
/**
275+
Fill SmBios structures for first and bound entry
276+
277+
@param[out] pSmBiosStruct - pointer for first SmBios entry
278+
@param[out] pBoundSmBiosStruct - pointer for nonexistent (one after last) SmBios entry
279+
@param[out] pSmbiosVersion - pointer to the version of SMBIOS tables retrieved
280+
**/
281+
EFI_STATUS
282+
GetFirstAndBoundSmBiosStructPointer(
283+
OUT SMBIOS_STRUCTURE_POINTER *pSmBiosStruct,
284+
OUT SMBIOS_STRUCTURE_POINTER *pLastSmBiosStruct,
285+
OUT SMBIOS_VERSION *pSmbiosVersion
286+
);
287+
272288
#endif //OS_EFI_API_H_

src/os/efi_shim/os_efi_preferences.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ EFI_STATUS preferences_flush_the_file(void)
5353
EFI_STATUS preferences_get_var_ascii(IN CONST char *name,
5454
IN CONST EFI_GUID guid,
5555
OUT VOID *value,
56-
OUT UINT32 *size OPTIONAL)
56+
OUT UINTN *size OPTIONAL)
5757
{
5858
int val = nvm_ini_get_int_value(gIni, name, -1);
5959
if (-1 == val)
@@ -102,19 +102,19 @@ EFI_STATUS preferences_get_string_ascii(IN CONST char *name,
102102
}
103103

104104
EFI_STATUS preferences_get_var(IN CONST CHAR16 *name,
105-
IN CONST EFI_GUID guid,
106-
OUT VOID *value,
107-
OUT UINTN *size OPTIONAL)
105+
IN CONST EFI_GUID guid,
106+
OUT VOID *value,
107+
OUT UINTN *size OPTIONAL)
108108
{
109109
char tmp[256];
110110
UnicodeStrToAsciiStr(name, tmp);
111111
return preferences_get_var_ascii(tmp, guid, value, size);
112112
}
113113

114114
EFI_STATUS preferences_get_var_string_wide(IN CONST CHAR16 *name,
115-
IN CONST EFI_GUID guid,
116-
OUT CHAR16 *value,
117-
OUT UINTN *size OPTIONAL)
115+
IN CONST EFI_GUID guid,
116+
OUT CHAR16 *value,
117+
OUT UINTN *size OPTIONAL)
118118
{
119119
char key[256];
120120
const char * ascii_str;

src/os/efi_shim/os_efi_preferences.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ EFI_STATUS preferences_get_var_ascii(
1717
IN CONST char *name,
1818
IN CONST EFI_GUID guid,
1919
OUT VOID *value,
20-
OUT UINT32 *size OPTIONAL);
20+
OUT UINTN *size OPTIONAL);
2121

2222
EFI_STATUS preferences_get_string_ascii(
2323
IN CONST char *name,

src/os/eventlog/event.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <PrintLib.h>
2121
#include "s_str.h"
2222
#include "os.h"
23+
#include <os_efi_api.h>
2324

2425
#if defined(__LINUX__)
2526
#include <safe_str_lib.h>

src/os/nvm_api/nvm_management.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,15 +3222,15 @@ NVM_API int nvm_get_fw_error_log_entry_cmd(
32223222
NVM_API int nvm_get_config_int(const char *param_name, int default_val)
32233223
{
32243224
int val = default_val;
3225-
int size = sizeof(val);
3225+
unsigned long long size = sizeof(val);
32263226
EFI_GUID g = { 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } };
32273227
int rc = NVM_SUCCESS;
32283228

32293229
if (NVM_SUCCESS != (rc = nvm_init())) {
32303230
NVDIMM_ERR("Failed to intialize nvm library %d\n", rc);
32313231
return rc;
32323232
}
3233-
preferences_get_var_ascii(param_name, g, (void *)&val, (UINT32 *)&size);
3233+
preferences_get_var_ascii(param_name, g, (void *)&val, &size);
32343234
return val;
32353235
}
32363236

0 commit comments

Comments
 (0)