From d6d3323e96aa2d66e4344bb89217aac448d2af59 Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Tue, 22 Apr 2025 04:54:51 +0000 Subject: [PATCH 1/5] Fix MISRA deviations * Suppress MISRA dir 4.6 to return int to comply with search function prototype * Fix MISRA rule 15.4 to use single break in loop * Fix MISRA rule 17.12 to use & to obtain the functoin address * Update coverity README.md to add compile option --- MISRA.md | 8 ++++++++ source/cellular_3gpp_api.c | 28 ++++++++++++++-------------- source/cellular_3gpp_urc_handler.c | 22 +++++++++------------- source/cellular_common.c | 4 ++-- source/cellular_pkthandler.c | 14 ++++++++++---- source/cellular_pktio.c | 4 ++-- tools/coverity/README.md | 4 ++-- 7 files changed, 47 insertions(+), 37 deletions(-) diff --git a/MISRA.md b/MISRA.md index 56096d09..23b3785a 100644 --- a/MISRA.md +++ b/MISRA.md @@ -29,6 +29,14 @@ _Ref 4.6.1_ We do not have control over these functions so we are suppressing these violations. +_Ref 4.6.2_ + +- MISRA C-2012 Directive 4.6 warns against using types that do not contain size + and sign information. However, in this case, the search function requires a + comparison function pointer that returns a value of type int. To maintain + compatibility with the search function's expected prototype, the comparison + function must return an int type value despite the MISRA guidance. + #### Directive 4.7 _Ref 4.7.1_ diff --git a/source/cellular_3gpp_api.c b/source/cellular_3gpp_api.c index 51406ee3..530019f2 100644 --- a/source/cellular_3gpp_api.c +++ b/source/cellular_3gpp_api.c @@ -867,7 +867,7 @@ static CellularError_t queryNetworkStatus( CellularContext_t * pContext, atReqGetResult.pAtCmd = pCommand; atReqGetResult.atCmdType = CELLULAR_AT_MULTI_WITH_PREFIX; atReqGetResult.pAtRspPrefix = pPrefix; - atReqGetResult.respCallback = _Cellular_RecvFuncGetNetworkReg; + atReqGetResult.respCallback = &_Cellular_RecvFuncGetNetworkReg; atReqGetResult.pData = &recvRegType; atReqGetResult.dataLen = ( uint16_t ) sizeof( CellularNetworkRegType_t ); @@ -1429,7 +1429,7 @@ static CellularError_t atcmdUpdateMccMnc( CellularContext_t * pContext, atCopsRequest.pAtCmd = "AT+COPS?"; atCopsRequest.atCmdType = CELLULAR_AT_WITH_PREFIX; atCopsRequest.pAtRspPrefix = "+COPS"; - atCopsRequest.respCallback = _Cellular_RecvFuncUpdateMccMnc; + atCopsRequest.respCallback = &_Cellular_RecvFuncUpdateMccMnc; atCopsRequest.pData = pOperatorInfo; atCopsRequest.dataLen = ( uint16_t ) sizeof( cellularOperatorInfo_t ); pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atCopsRequest ); @@ -1638,7 +1638,7 @@ CellularError_t Cellular_CommonGetEidrxSettings( CellularHandle_t cellularHandle atReqGetEidrx.pAtCmd = "AT+CEDRXS?"; atReqGetEidrx.atCmdType = CELLULAR_AT_MULTI_WITH_PREFIX; atReqGetEidrx.pAtRspPrefix = "+CEDRXS"; - atReqGetEidrx.respCallback = _Cellular_RecvFuncGetEidrxSettings; + atReqGetEidrx.respCallback = &_Cellular_RecvFuncGetEidrxSettings; atReqGetEidrx.pData = pEidrxSettingsList; atReqGetEidrx.dataLen = CELLULAR_EDRX_LIST_MAX_SIZE; @@ -1898,7 +1898,7 @@ CellularError_t Cellular_CommonGetNetworkTime( CellularHandle_t cellularHandle, atReqGetNetworkTime.pAtCmd = "AT+CCLK?"; atReqGetNetworkTime.atCmdType = CELLULAR_AT_WITH_PREFIX; atReqGetNetworkTime.pAtRspPrefix = "+CCLK"; - atReqGetNetworkTime.respCallback = _Cellular_RecvFuncGetNetworkTime; + atReqGetNetworkTime.respCallback = &_Cellular_RecvFuncGetNetworkTime; atReqGetNetworkTime.pData = pNetworkTime; atReqGetNetworkTime.dataLen = ( uint16_t ) sizeof( CellularTime_t ); @@ -1943,28 +1943,28 @@ CellularError_t Cellular_CommonGetModemInfo( CellularHandle_t cellularHandle, atReqGetFirmwareVersion.pAtCmd = "AT+CGMR"; atReqGetFirmwareVersion.atCmdType = CELLULAR_AT_WO_PREFIX; atReqGetFirmwareVersion.pAtRspPrefix = NULL; - atReqGetFirmwareVersion.respCallback = _Cellular_RecvFuncGetFirmwareVersion; + atReqGetFirmwareVersion.respCallback = &_Cellular_RecvFuncGetFirmwareVersion; atReqGetFirmwareVersion.pData = pModemInfo->firmwareVersion; atReqGetFirmwareVersion.dataLen = CELLULAR_FW_VERSION_MAX_SIZE + 1U; atReqGetImei.pAtCmd = "AT+CGSN"; atReqGetImei.atCmdType = CELLULAR_AT_WO_PREFIX; atReqGetImei.pAtRspPrefix = NULL; - atReqGetImei.respCallback = _Cellular_RecvFuncGetImei; + atReqGetImei.respCallback = &_Cellular_RecvFuncGetImei; atReqGetImei.pData = pModemInfo->imei; atReqGetImei.dataLen = CELLULAR_IMEI_MAX_SIZE + 1U; atReqGetModelId.pAtCmd = "AT+CGMM"; atReqGetModelId.atCmdType = CELLULAR_AT_WO_PREFIX; atReqGetModelId.pAtRspPrefix = NULL; - atReqGetModelId.respCallback = _Cellular_RecvFuncGetModelId; + atReqGetModelId.respCallback = &_Cellular_RecvFuncGetModelId; atReqGetModelId.pData = pModemInfo->modelId; atReqGetModelId.dataLen = CELLULAR_MODEL_ID_MAX_SIZE + 1U; atReqGetManufactureId.pAtCmd = "AT+CGMI"; atReqGetManufactureId.atCmdType = CELLULAR_AT_WO_PREFIX; atReqGetManufactureId.pAtRspPrefix = NULL; - atReqGetManufactureId.respCallback = _Cellular_RecvFuncGetManufactureId; + atReqGetManufactureId.respCallback = &_Cellular_RecvFuncGetManufactureId; atReqGetManufactureId.pData = pModemInfo->manufactureId; atReqGetManufactureId.dataLen = CELLULAR_MANUFACTURE_ID_MAX_SIZE + 1U; @@ -2031,7 +2031,7 @@ CellularError_t Cellular_CommonGetIPAddress( CellularHandle_t cellularHandle, atReqGetIp.pAtCmd = cmdBuf; atReqGetIp.atCmdType = CELLULAR_AT_WITH_PREFIX; atReqGetIp.pAtRspPrefix = "+CGPADDR"; - atReqGetIp.respCallback = _Cellular_RecvFuncIpAddress; + atReqGetIp.respCallback = &_Cellular_RecvFuncIpAddress; atReqGetIp.pData = pBuffer; atReqGetIp.dataLen = ( uint16_t ) bufferLength; @@ -2689,7 +2689,7 @@ CellularError_t Cellular_CommonGetSimCardLockStatus( CellularHandle_t cellularHa atReqGetSimLockStatus.pAtCmd = "AT+CPIN?"; atReqGetSimLockStatus.atCmdType = CELLULAR_AT_WITH_PREFIX; atReqGetSimLockStatus.pAtRspPrefix = "+CPIN"; - atReqGetSimLockStatus.respCallback = _Cellular_RecvFuncGetSimLockStatus; + atReqGetSimLockStatus.respCallback = &_Cellular_RecvFuncGetSimLockStatus; atReqGetSimLockStatus.pData = &( pSimCardStatus->simCardLockState ); atReqGetSimLockStatus.dataLen = ( uint16_t ) sizeof( CellularSimCardLockState_t ); @@ -2721,7 +2721,7 @@ CellularError_t Cellular_CommonGetSimCardInfo( CellularHandle_t cellularHandle, atReqGetIccid.pAtCmd = "AT+CCID"; atReqGetIccid.atCmdType = CELLULAR_AT_WITH_PREFIX; atReqGetIccid.pAtRspPrefix = "+CCID"; - atReqGetIccid.respCallback = _Cellular_RecvFuncGetIccid; + atReqGetIccid.respCallback = &_Cellular_RecvFuncGetIccid; atReqGetIccid.pData = pSimCardInfo->iccid; atReqGetIccid.dataLen = CELLULAR_ICCID_MAX_SIZE + 1U; #endif @@ -2729,14 +2729,14 @@ CellularError_t Cellular_CommonGetSimCardInfo( CellularHandle_t cellularHandle, atReqGetImsi.pAtCmd = "AT+CIMI"; atReqGetImsi.atCmdType = CELLULAR_AT_WO_PREFIX; atReqGetImsi.pAtRspPrefix = NULL; - atReqGetImsi.respCallback = _Cellular_RecvFuncGetImsi; + atReqGetImsi.respCallback = &_Cellular_RecvFuncGetImsi; atReqGetImsi.pData = pSimCardInfo->imsi; atReqGetImsi.dataLen = CELLULAR_IMSI_MAX_SIZE + 1U; atReqGetHplmn.pAtCmd = "AT+CRSM=176,28514,0,0,0"; /* READ BINARY command. HPLMN Selector with Access Technology( 6F62 ). */ atReqGetHplmn.atCmdType = CELLULAR_AT_WITH_PREFIX; atReqGetHplmn.pAtRspPrefix = "+CRSM"; - atReqGetHplmn.respCallback = _Cellular_RecvFuncGetHplmn; + atReqGetHplmn.respCallback = &_Cellular_RecvFuncGetHplmn; atReqGetHplmn.pData = &( pSimCardInfo->plmn ); atReqGetHplmn.dataLen = ( uint16_t ) sizeof( CellularPlmnInfo_t ); @@ -3025,7 +3025,7 @@ CellularError_t Cellular_CommonGetPsmSettings( CellularHandle_t cellularHandle, atReqGetPsm.pAtCmd = "AT+CPSMS?"; atReqGetPsm.atCmdType = CELLULAR_AT_WITH_PREFIX; atReqGetPsm.pAtRspPrefix = "+CPSMS"; - atReqGetPsm.respCallback = _Cellular_RecvFuncGetPsmSettings; + atReqGetPsm.respCallback = &_Cellular_RecvFuncGetPsmSettings; atReqGetPsm.pData = pPsmSettings; atReqGetPsm.dataLen = ( uint16_t ) sizeof( CellularPsmSettings_t ); diff --git a/source/cellular_3gpp_urc_handler.c b/source/cellular_3gpp_urc_handler.c index c232de4f..25fffaaf 100644 --- a/source/cellular_3gpp_urc_handler.c +++ b/source/cellular_3gpp_urc_handler.c @@ -88,7 +88,7 @@ static CellularPktStatus_t _parseRejectCauseInRegStatus( CellularNetworkRegType_ static CellularPktStatus_t _parseRoutingAreaCodeInRegStatus( const char * pToken, cellularAtData_t * pLibAtData ); static CellularPktStatus_t _regStatusSwitchParsingFunc( CellularContext_t * pContext, - uint8_t i, + uint8_t regPos, CellularNetworkRegType_t regType, const char * pToken, cellularAtData_t * pLibAtData ); @@ -746,15 +746,15 @@ CellularPktStatus_t _Cellular_ParseRegStatus( CellularContext_t * pContext, switch( regType ) { case CELLULAR_REG_TYPE_CREG: - pRegStatusParsingFunc = _regStatusSwitchParsingFuncCreg; + pRegStatusParsingFunc = &_regStatusSwitchParsingFuncCreg; break; case CELLULAR_REG_TYPE_CGREG: - pRegStatusParsingFunc = _regStatusSwitchParsingFuncCgreg; + pRegStatusParsingFunc = &_regStatusSwitchParsingFuncCgreg; break; case CELLULAR_REG_TYPE_CEREG: - pRegStatusParsingFunc = _regStatusSwitchParsingFuncCereg; + pRegStatusParsingFunc = &_regStatusSwitchParsingFuncCereg; break; default: @@ -806,16 +806,12 @@ CellularPktStatus_t _Cellular_ParseRegStatus( CellularContext_t * pContext, while( pToken != NULL ) { i++; - + packetStatus = pRegStatusParsingFunc( pContext, i, pToken, pLibAtData ); - - if( packetStatus != CELLULAR_PKT_STATUS_OK ) - { - break; - } - - /* Getting next token to parse. */ - if( Cellular_ATGetNextTok( &pRegStr, &pToken ) != CELLULAR_AT_SUCCESS ) + + /* Continue only if status is OK and we can get the next token */ + if( (packetStatus != CELLULAR_PKT_STATUS_OK) || + (Cellular_ATGetNextTok( &pRegStr, &pToken ) != CELLULAR_AT_SUCCESS) ) { break; } diff --git a/source/cellular_common.c b/source/cellular_common.c index fed822cf..53e2d061 100644 --- a/source/cellular_common.c +++ b/source/cellular_common.c @@ -188,12 +188,12 @@ static CellularError_t libOpen( CellularContext_t * pContext ) _Cellular_LockAtDataMutex( pContext ); _Cellular_InitAtData( pContext, 0 ); _Cellular_UnlockAtDataMutex( pContext ); - _Cellular_SetShutdownCallback( pContext, _shutdownCallback ); + _Cellular_SetShutdownCallback( pContext, &_shutdownCallback ); pktStatus = _Cellular_PktHandlerInit( pContext ); if( pktStatus == CELLULAR_PKT_STATUS_OK ) { - pktStatus = _Cellular_PktioInit( pContext, _Cellular_HandlePacket ); + pktStatus = _Cellular_PktioInit( pContext, &_Cellular_HandlePacket ); if( pktStatus != CELLULAR_PKT_STATUS_OK ) { diff --git a/source/cellular_pkthandler.c b/source/cellular_pkthandler.c index 942ea139..90f93ee1 100644 --- a/source/cellular_pkthandler.c +++ b/source/cellular_pkthandler.c @@ -71,7 +71,7 @@ static CellularPktStatus_t _Cellular_DataSendWithTimeoutDelayRaw( CellularContex uint32_t timeoutMs ); static void _Cellular_PktHandlerAcquirePktRequestMutex( CellularContext_t * pContext ); static void _Cellular_PktHandlerReleasePktRequestMutex( CellularContext_t * pContext ); -static int32_t _searchCompareFunc( const void * pInputToken, +static int _searchCompareFunc( const void * pInputToken, const void * pBase ); static int32_t _sortCompareFunc( const void * pElem1Ptr, const void * pElem2Ptr ); @@ -360,10 +360,16 @@ static void _Cellular_PktHandlerReleasePktRequestMutex( CellularContext_t * pCon /*-----------------------------------------------------------*/ -static int32_t _searchCompareFunc( const void * pInputToken, +/* MISRA Ref 4.6. [Basic numerical type] */ +/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#directive-46 */ +/* coverity[misra_c_2012_directive_4_6_violation] */ +static int _searchCompareFunc( const void * pInputToken, const void * pBase ) { - int32_t compareValue = 0; + /* MISRA Ref 4.6. [Basic numerical type] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#directive-46 */ + /* coverity[misra_c_2012_directive_4_6_violation] */ + int compareValue = 0; const char * pToken = ( const char * ) pInputToken; const CellularAtParseTokenMap_t * pBasePtr = ( const CellularAtParseTokenMap_t * ) pBase; uint32_t tokenLen = ( uint32_t ) strlen( pInputToken ); @@ -441,7 +447,7 @@ static CellularPktStatus_t _atParseGetHandler( CellularContext_t * pContext, ( const void * ) pTokenMap, tokenMapSize, sizeof( CellularAtParseTokenMap_t ), - _searchCompareFunc ); + &_searchCompareFunc ); if( pElementPtr != NULL ) { diff --git a/source/cellular_pktio.c b/source/cellular_pktio.c index b47fe43d..19c3c4f8 100644 --- a/source/cellular_pktio.c +++ b/source/cellular_pktio.c @@ -1206,7 +1206,7 @@ static void _pktioReadThread( void * pUserData ) /* Open main communication port. */ if( ( pContext->pCommIntf != NULL ) && - ( pContext->pCommIntf->open( _Cellular_PktRxCallBack, ( void * ) pContext, + ( pContext->pCommIntf->open( &_Cellular_PktRxCallBack, ( void * ) pContext, &( pContext->hPktioCommIntf ) ) == IOT_COMM_INTERFACE_SUCCESS ) ) { /* Send thread started event. */ @@ -1370,7 +1370,7 @@ CellularPktStatus_t _Cellular_PktioInit( CellularContext_t * pContext, ( ( PlatformEventBits_t ) PKTIO_EVT_MASK_ALL_EVENTS ) ); /* Create the Read thread. */ - status = Platform_CreateDetachedThread( _pktioReadThread, + status = Platform_CreateDetachedThread( &_pktioReadThread, ( void * ) pContext, PLATFORM_THREAD_DEFAULT_PRIORITY, PLATFORM_THREAD_DEFAULT_STACK_SIZE ); diff --git a/tools/coverity/README.md b/tools/coverity/README.md index 0d2f964e..233f9403 100644 --- a/tools/coverity/README.md +++ b/tools/coverity/README.md @@ -31,7 +31,7 @@ Go to the root directory of the library and run the following commands in termin ~~~ 2. Create the build files using CMake in a `build` directory ~~~ - cmake -B build -S test + cmake -B build -S test -DCOV_ANALYSIS=ON ~~~ 3. Go to the build directory and copy the coverity configuration file ~~~ @@ -62,7 +62,7 @@ Go to the root directory of the library and run the following commands in termin For your convenience the commands above are below to be copy/pasted into a UNIX command friendly terminal. ~~~ cov-configure --force --compiler cc --comptype gcc; - cmake -B build -S test; + cmake -B build -S test -DCOV_ANALYSIS=ON; cd build/; cov-build --emit-complementary-info --dir cov-out make coverity_analysis; cd cov-out/ From ee1f2c28d837075f3afbff758d8a96b9c08a2f89 Mon Sep 17 00:00:00 2001 From: "Ching-Hsin,Lee" Date: Tue, 22 Apr 2025 05:34:37 +0000 Subject: [PATCH 2/5] Fix spelling --- .github/.cSpellWords.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/.cSpellWords.txt b/.github/.cSpellWords.txt index 6bf2f126..3d26c8c5 100644 --- a/.github/.cSpellWords.txt +++ b/.github/.cSpellWords.txt @@ -40,6 +40,7 @@ CRSM CSDK ctest DCMOCK +DCOV decihours Decihours DECIHOURS From 0b10fae406e931c0449cd69d3f0387cd0553a1f6 Mon Sep 17 00:00:00 2001 From: "Ching-Hsin,Lee" Date: Tue, 22 Apr 2025 05:43:51 +0000 Subject: [PATCH 3/5] Use latest ubuntu for formating --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7276fc4a..1a49b46a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,7 +89,7 @@ jobs: path: ./ formatting: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Check formatting From 575307cf4ab34dd5684e1438e8d58324f2c24380 Mon Sep 17 00:00:00 2001 From: "Ching-Hsin,Lee" Date: Tue, 22 Apr 2025 05:49:06 +0000 Subject: [PATCH 4/5] Fix formating --- source/cellular_3gpp_urc_handler.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/cellular_3gpp_urc_handler.c b/source/cellular_3gpp_urc_handler.c index 25fffaaf..50205faa 100644 --- a/source/cellular_3gpp_urc_handler.c +++ b/source/cellular_3gpp_urc_handler.c @@ -806,12 +806,12 @@ CellularPktStatus_t _Cellular_ParseRegStatus( CellularContext_t * pContext, while( pToken != NULL ) { i++; - + packetStatus = pRegStatusParsingFunc( pContext, i, pToken, pLibAtData ); - + /* Continue only if status is OK and we can get the next token */ - if( (packetStatus != CELLULAR_PKT_STATUS_OK) || - (Cellular_ATGetNextTok( &pRegStr, &pToken ) != CELLULAR_AT_SUCCESS) ) + if( ( packetStatus != CELLULAR_PKT_STATUS_OK ) || + ( Cellular_ATGetNextTok( &pRegStr, &pToken ) != CELLULAR_AT_SUCCESS ) ) { break; } From 4f3d6bdf3a29cf75b7b9d3c1e33868a4e39b9e7a Mon Sep 17 00:00:00 2001 From: "Ching-Hsin,Lee" Date: Tue, 22 Apr 2025 05:54:28 +0000 Subject: [PATCH 5/5] Fix formatting --- source/cellular_pkthandler.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/cellular_pkthandler.c b/source/cellular_pkthandler.c index 90f93ee1..00242edd 100644 --- a/source/cellular_pkthandler.c +++ b/source/cellular_pkthandler.c @@ -72,7 +72,7 @@ static CellularPktStatus_t _Cellular_DataSendWithTimeoutDelayRaw( CellularContex static void _Cellular_PktHandlerAcquirePktRequestMutex( CellularContext_t * pContext ); static void _Cellular_PktHandlerReleasePktRequestMutex( CellularContext_t * pContext ); static int _searchCompareFunc( const void * pInputToken, - const void * pBase ); + const void * pBase ); static int32_t _sortCompareFunc( const void * pElem1Ptr, const void * pElem2Ptr ); static CellularPktStatus_t _atParseGetHandler( CellularContext_t * pContext, @@ -364,7 +364,7 @@ static void _Cellular_PktHandlerReleasePktRequestMutex( CellularContext_t * pCon /* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#directive-46 */ /* coverity[misra_c_2012_directive_4_6_violation] */ static int _searchCompareFunc( const void * pInputToken, - const void * pBase ) + const void * pBase ) { /* MISRA Ref 4.6. [Basic numerical type] */ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#directive-46 */