From 539d09b56999fec005018e51ebfb435809c394cf Mon Sep 17 00:00:00 2001 From: "Jason M. Bills" Date: Tue, 15 Oct 2019 16:40:47 -0700 Subject: Enable build flags and fix warnings This enables warnings during the build and fixes some warnings so it builds successfully. Tested: Confirmed that it builds and peci_cmds still works as expected. Change-Id: I768f2bc78050d001f6500b7349cceb40086def07 Signed-off-by: Jason M. Bills --- libpeci/CMakeLists.txt | 20 +++++++ libpeci/peci.c | 9 ++-- libpeci/peci.h | 9 ++-- libpeci/peci_cmds.c | 139 ++++++++++++++++++++++++++----------------------- 4 files changed, 104 insertions(+), 73 deletions(-) diff --git a/libpeci/CMakeLists.txt b/libpeci/CMakeLists.txt index 227ed1d..441b320 100644 --- a/libpeci/CMakeLists.txt +++ b/libpeci/CMakeLists.txt @@ -7,6 +7,26 @@ set_property(TARGET peci PROPERTY C_STANDARD 99) target_include_directories(peci PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(peci PROPERTIES VERSION "1.0" SOVERSION "1") +set( + CMAKE_C_FLAGS + "${CMAKE_C_FLAGS} \ +-Wall \ +-Wextra \ +-Wcast-align \ +-Wunused \ +-Wconversion \ +-Wsign-conversion \ +-Wnull-dereference \ +-Wdouble-promotion \ +-Wformat=2 \ +-Wno-unused-parameter \ +-Werror \ +-Wduplicated-cond \ +-Wduplicated-branches \ +-Wlogical-op \ +" + ) + install(TARGETS peci DESTINATION lib) install(FILES peci.h DESTINATION include) diff --git a/libpeci/peci.c b/libpeci/peci.c index fee87f2..7e3f5e3 100644 --- a/libpeci/peci.c +++ b/libpeci/peci.c @@ -39,12 +39,12 @@ void peci_Unlock(int peci_fd) * This function attempts to lock the peci interface with the specified * timeout and returns a file descriptor if successful. *------------------------------------------------------------------------*/ -EPECIStatus peci_Lock(int* peci_fd, uint32_t timeout_ms) +EPECIStatus peci_Lock(int* peci_fd, int timeout_ms) { struct timespec sRequest; sRequest.tv_sec = 0; sRequest.tv_nsec = PECI_TIMEOUT_RESOLUTION_MS * 1000 * 1000; - uint32_t timeout_count = 0; + int timeout_count = 0; if (NULL == peci_fd) { @@ -73,8 +73,7 @@ EPECIStatus peci_Lock(int* peci_fd, uint32_t timeout_ms) } if (-1 == *peci_fd) { - syslog(LOG_ERR, "%s(%d): >>> PECI Device Busy <<< \n", __FUNCTION__, - __LINE__); + syslog(LOG_ERR, " >>> PECI Device Busy <<< \n"); return PECI_CC_DRIVER_ERR; } return PECI_CC_SUCCESS; @@ -1116,7 +1115,7 @@ EPECIStatus peci_raw(uint8_t target, uint8_t u8ReadLen, const uint8_t* pRawCmd, } cmd.addr = target; - cmd.tx_len = cmdSize; + cmd.tx_len = (uint8_t)cmdSize; cmd.rx_len = u8ReadLen; memcpy(u8TxBuf, pRawCmd, cmdSize); diff --git a/libpeci/peci.h b/libpeci/peci.h index ba24d02..bfaa912 100644 --- a/libpeci/peci.h +++ b/libpeci/peci.h @@ -17,9 +17,12 @@ #ifdef __cplusplus extern "C" { #endif - -#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcpp" +#pragma GCC diagnostic ignored "-Wvariadic-macros" #include +#pragma GCC diagnostic pop +#include #include // PECI Client Address List @@ -226,7 +229,7 @@ EPECIStatus peci_raw(uint8_t target, uint8_t u8ReadLen, const uint8_t* pRawCmd, const uint32_t cmdSize, uint8_t* pRawResp, uint32_t respSize); -EPECIStatus peci_Lock(int* peci_fd, uint32_t timeout_ms); +EPECIStatus peci_Lock(int* peci_fd, int timeout_ms); void peci_Unlock(int peci_fd); EPECIStatus peci_Ping(uint8_t target); EPECIStatus peci_Ping_seq(uint8_t target, int peci_fd); diff --git a/libpeci/peci_cmds.c b/libpeci/peci_cmds.c index dac0fa6..91e7eb9 100644 --- a/libpeci/peci_cmds.c +++ b/libpeci/peci_cmds.c @@ -94,7 +94,7 @@ int main(int argc, char* argv[]) uint64_t u64MsrVal = 0; short temperature; uint64_t dib; - uint8_t u8Index = 0; + int index = 0; uint8_t cc = 0; bool verbose = false; @@ -116,7 +116,7 @@ int main(int argc, char* argv[]) case 'a': if (optarg != NULL) - address = strtoul(optarg, NULL, 0); + address = (uint8_t)strtoul(optarg, NULL, 0); if (address < MIN_CLIENT_ADDR || address > MAX_CLIENT_ADDR) { printf("ERROR: Invalid address \"0x%x\"\n", address); @@ -127,7 +127,7 @@ int main(int argc, char* argv[]) case 's': if (optarg != NULL) - u8Size = strtoul(optarg, NULL, 0); + u8Size = (uint8_t)strtoul(optarg, NULL, 0); if (u8Size != 1 && u8Size != 2 && u8Size != 4 && u8Size != 8 && u8Size != 16) { @@ -154,7 +154,7 @@ int main(int argc, char* argv[]) // Allow any case while (cmd[i]) { - cmd[i] = tolower(cmd[i]); + cmd[i] = (char)tolower((int)cmd[i]); i++; } @@ -209,12 +209,12 @@ int main(int argc, char* argv[]) else if (strcmp(cmd, "rdpkgconfig") == 0) { - u8Index = argc; + index = argc; switch (argc - optind) { case 2: - u16PkgParam = strtoul(argv[--u8Index], NULL, 16); - u8PkgIndex = strtoul(argv[--u8Index], NULL, 16); + u16PkgParam = (uint16_t)strtoul(argv[--index], NULL, 16); + u8PkgIndex = (uint8_t)strtoul(argv[--index], NULL, 16); break; default: printf("ERROR: Unsupported arguments for Pkg Read\n"); @@ -237,13 +237,13 @@ int main(int argc, char* argv[]) } else if (strcmp(cmd, "wrpkgconfig") == 0) { - u8Index = argc; + index = argc; switch (argc - optind) { case 3: - u32PkgValue = strtoul(argv[--u8Index], NULL, 16); - u16PkgParam = strtoul(argv[--u8Index], NULL, 16); - u8PkgIndex = strtoul(argv[--u8Index], NULL, 16); + u32PkgValue = strtoul(argv[--index], NULL, 16); + u16PkgParam = (uint16_t)strtoul(argv[--index], NULL, 16); + u8PkgIndex = (uint8_t)strtoul(argv[--index], NULL, 16); break; default: printf("ERROR: Unsupported arguments for Pkg Write\n"); @@ -266,12 +266,12 @@ int main(int argc, char* argv[]) } else if (strcmp(cmd, "rdiamsr") == 0) { - u8Index = argc; + index = argc; switch (argc - optind) { case 2: - u16MsrAddr = strtoul(argv[--u8Index], NULL, 16); - u8MsrThread = strtoul(argv[--u8Index], NULL, 16); + u16MsrAddr = (uint16_t)strtoul(argv[--index], NULL, 16); + u8MsrThread = (uint8_t)strtoul(argv[--index], NULL, 16); break; default: printf("ERROR: Unsupported arguments for MSR Read\n"); @@ -289,21 +289,24 @@ int main(int argc, char* argv[]) printf("ERROR %d: command failed\n", ret); return 1; } - printf(" cc:0x%02x 0x%0*x\n", cc, u8Size * 2, u64MsrVal); + printf(" cc:0x%02x 0x%0*llx\n", cc, u8Size * 2, u64MsrVal); } else if (strcmp(cmd, "rdpciconfig") == 0) { - u8Index = argc; + index = argc; switch (argc - optind) { case 4: - u16PciReg = strtoul(argv[--u8Index], NULL, 16); + u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 16); + /* FALLTHROUGH */ case 3: - u8PciFunc = strtoul(argv[--u8Index], NULL, 16); + u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 16); + /* FALLTHROUGH */ case 2: - u8PciDev = strtoul(argv[--u8Index], NULL, 16); + u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 16); + /* FALLTHROUGH */ case 1: - u8PciBus = strtoul(argv[--u8Index], NULL, 16); + u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 16); break; default: printf("ERROR: Unsupported arguments for PCI Read\n"); @@ -326,17 +329,20 @@ int main(int argc, char* argv[]) } else if (strcmp(cmd, "rdpciconfiglocal") == 0) { - u8Index = argc; + index = argc; switch (argc - optind) { case 4: - u16PciReg = strtoul(argv[--u8Index], NULL, 16); + u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 16); + /* FALLTHROUGH */ case 3: - u8PciFunc = strtoul(argv[--u8Index], NULL, 16); + u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 16); + /* FALLTHROUGH */ case 2: - u8PciDev = strtoul(argv[--u8Index], NULL, 16); + u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 16); + /* FALLTHROUGH */ case 1: - u8PciBus = strtoul(argv[--u8Index], NULL, 16); + u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 16); break; default: printf("ERROR: Unsupported arguments for Local PCI Read\n"); @@ -360,18 +366,21 @@ int main(int argc, char* argv[]) } else if (strcmp(cmd, "wrpciconfiglocal") == 0) { - u8Index = argc; - u32PciWriteVal = strtoul(argv[--u8Index], NULL, 16); + index = argc; + u32PciWriteVal = strtoul(argv[--index], NULL, 16); switch (argc - optind) { case 5: - u16PciReg = strtoul(argv[--u8Index], NULL, 16); + u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 16); + /* FALLTHROUGH */ case 4: - u8PciFunc = strtoul(argv[--u8Index], NULL, 16); + u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 16); + /* FALLTHROUGH */ case 3: - u8PciDev = strtoul(argv[--u8Index], NULL, 16); + u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 16); + /* FALLTHROUGH */ case 2: - u8PciBus = strtoul(argv[--u8Index], NULL, 16); + u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 16); break; default: printf("ERROR: Unsupported arguments for Local PCI Write\n"); @@ -395,15 +404,15 @@ int main(int argc, char* argv[]) } else if (strcmp(cmd, "rdendpointconfigpcilocal") == 0) { - u8Index = argc; + index = argc; switch (argc - optind) { case 5: - u16PciReg = strtoul(argv[--u8Index], NULL, 16); - u8PciFunc = strtoul(argv[--u8Index], NULL, 16); - u8PciDev = strtoul(argv[--u8Index], NULL, 16); - u8PciBus = strtoul(argv[--u8Index], NULL, 16); - u8Seg = strtoul(argv[--u8Index], NULL, 16); + u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 16); + u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 16); + u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 16); + u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 16); + u8Seg = (uint8_t)strtoul(argv[--index], NULL, 16); break; default: @@ -429,16 +438,16 @@ int main(int argc, char* argv[]) } else if (strcmp(cmd, "wrendpointconfigpcilocal") == 0) { - u8Index = argc; + index = argc; switch (argc - optind) { case 6: - u32PciWriteVal = strtoul(argv[--u8Index], NULL, 16); - u16PciReg = strtoul(argv[--u8Index], NULL, 16); - u8PciFunc = strtoul(argv[--u8Index], NULL, 16); - u8PciDev = strtoul(argv[--u8Index], NULL, 16); - u8PciBus = strtoul(argv[--u8Index], NULL, 16); - u8Seg = strtoul(argv[--u8Index], NULL, 16); + u32PciWriteVal = strtoul(argv[--index], NULL, 16); + u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 16); + u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 16); + u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 16); + u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 16); + u8Seg = (uint8_t)strtoul(argv[--index], NULL, 16); break; default: @@ -465,15 +474,15 @@ int main(int argc, char* argv[]) } else if (strcmp(cmd, "rdendpointconfigpci") == 0) { - u8Index = argc; + index = argc; switch (argc - optind) { case 5: - u16PciReg = strtoul(argv[--u8Index], NULL, 16); - u8PciFunc = strtoul(argv[--u8Index], NULL, 16); - u8PciDev = strtoul(argv[--u8Index], NULL, 16); - u8PciBus = strtoul(argv[--u8Index], NULL, 16); - u8Seg = strtoul(argv[--u8Index], NULL, 16); + u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 16); + u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 16); + u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 16); + u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 16); + u8Seg = (uint8_t)strtoul(argv[--index], NULL, 16); break; default: @@ -497,16 +506,16 @@ int main(int argc, char* argv[]) } else if (strcmp(cmd, "wrendpointconfigpci") == 0) { - u8Index = argc; + index = argc; switch (argc - optind) { case 6: - u32PciWriteVal = strtoul(argv[--u8Index], NULL, 16); - u16PciReg = strtoul(argv[--u8Index], NULL, 16); - u8PciFunc = strtoul(argv[--u8Index], NULL, 16); - u8PciDev = strtoul(argv[--u8Index], NULL, 16); - u8PciBus = strtoul(argv[--u8Index], NULL, 16); - u8Seg = strtoul(argv[--u8Index], NULL, 16); + u32PciWriteVal = strtoul(argv[--index], NULL, 16); + u16PciReg = (uint16_t)strtoul(argv[--index], NULL, 16); + u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 16); + u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 16); + u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 16); + u8Seg = (uint8_t)strtoul(argv[--index], NULL, 16); break; default: @@ -532,17 +541,17 @@ int main(int argc, char* argv[]) } else if (strcmp(cmd, "rdendpointconfigmmio") == 0) { - u8Index = argc; + index = argc; switch (argc - optind) { case 7: - u64Offset = strtoul(argv[--u8Index], NULL, 16); - u8PciFunc = strtoul(argv[--u8Index], NULL, 16); - u8PciDev = strtoul(argv[--u8Index], NULL, 16); - u8PciBus = strtoul(argv[--u8Index], NULL, 16); - u8Seg = strtoul(argv[--u8Index], NULL, 16); - u8Bar = strtoul(argv[--u8Index], NULL, 16); - u8AddrType = strtoul(argv[--u8Index], NULL, 16); + u64Offset = strtoull(argv[--index], NULL, 16); + u8PciFunc = (uint8_t)strtoul(argv[--index], NULL, 16); + u8PciDev = (uint8_t)strtoul(argv[--index], NULL, 16); + u8PciBus = (uint8_t)strtoul(argv[--index], NULL, 16); + u8Seg = (uint8_t)strtoul(argv[--index], NULL, 16); + u8Bar = (uint8_t)strtoul(argv[--index], NULL, 16); + u8AddrType = (uint8_t)strtoul(argv[--index], NULL, 16); break; default: -- cgit v1.2.3