From a6ab40dba745bbb7488ca5edfd1901d4e31dc14e Mon Sep 17 00:00:00 2001 From: zhang Date: Sat, 19 Feb 2022 16:54:06 +0800 Subject: [PATCH] fix: repair codex warning of osal Signed-off-by: zhang --- support/posix/src/osal_mutex.c | 4 ++-- support/posix/src/osal_sem.c | 4 ++-- support/posix/src/osal_time.c | 12 ++++++------ .../utils/hcs_parser/unittest/hcs_config_test.c | 10 +++++----- utils/src/hcs_parser/hcs_blob_if.c | 6 +++--- utils/src/hcs_parser/hcs_generate_tree.c | 4 ++-- utils/src/hdf_cstring.c | 2 +- utils/src/osal_msg_queue.c | 4 ++-- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/support/posix/src/osal_mutex.c b/support/posix/src/osal_mutex.c index 6769c921..2d7f363e 100644 --- a/support/posix/src/osal_mutex.c +++ b/support/posix/src/osal_mutex.c @@ -95,8 +95,8 @@ int32_t OsalMutexTimedLock(struct OsalMutex *mutex, uint32_t ms) struct timespec time; (void)memset_s(&time, sizeof(time), 0, sizeof(time)); clock_gettime(CLOCK_REALTIME, &time); - time.tv_sec += ms / HDF_KILO_UNIT; - time.tv_nsec += (ms % HDF_KILO_UNIT) * HDF_KILO_UNIT * HDF_KILO_UNIT; + time.tv_sec += (time_t)ms / HDF_KILO_UNIT; + time.tv_nsec += (time_t)(ms % HDF_KILO_UNIT) * HDF_KILO_UNIT * HDF_KILO_UNIT; if (time.tv_nsec >= HDF_NANO_UNITS) { time.tv_nsec -= HDF_NANO_UNITS; time.tv_sec += 1; diff --git a/support/posix/src/osal_sem.c b/support/posix/src/osal_sem.c index f1747818..47457bfc 100644 --- a/support/posix/src/osal_sem.c +++ b/support/posix/src/osal_sem.c @@ -61,8 +61,8 @@ int32_t OsalSemWait(struct OsalSem *sem, uint32_t ms) struct timespec time; (void)memset_s(&time, sizeof(time), 0, sizeof(time)); clock_gettime(CLOCK_REALTIME, &time); - time.tv_sec += ms / HDF_KILO_UNIT; - time.tv_nsec += (ms % HDF_KILO_UNIT) * HDF_KILO_UNIT * HDF_KILO_UNIT; + time.tv_sec += (time_t)ms / HDF_KILO_UNIT; + time.tv_nsec += (time_t)(ms % HDF_KILO_UNIT) * HDF_KILO_UNIT * HDF_KILO_UNIT; if (time.tv_nsec >= HDF_NANO_UNITS) { time.tv_nsec -= HDF_NANO_UNITS; time.tv_sec += 1; diff --git a/support/posix/src/osal_time.c b/support/posix/src/osal_time.c index 841dcd9e..c91ba2a6 100644 --- a/support/posix/src/osal_time.c +++ b/support/posix/src/osal_time.c @@ -27,8 +27,8 @@ int32_t OsalGetTime(OsalTimespec *time) (void)memset_s(&ts, sizeof(ts), 0, sizeof(ts)); clock_gettime(CLOCK_MONOTONIC, &ts); - time->sec = ts.tv_sec; - time->usec = ts.tv_nsec / HDF_KILO_UNIT; + time->sec = (uint64_t)ts.tv_sec; + time->usec = (uint64_t)ts.tv_nsec / HDF_KILO_UNIT; return HDF_SUCCESS; } @@ -67,8 +67,8 @@ void OsalMSleep(uint32_t ms) int result; struct timespec ts; - ts.tv_sec = ms / HDF_KILO_UNIT; - ts.tv_nsec = HDF_KILO_UNIT * HDF_KILO_UNIT * ((long)(ms % HDF_KILO_UNIT)); + ts.tv_sec = (time_t)ms / HDF_KILO_UNIT; + ts.tv_nsec = (time_t)HDF_KILO_UNIT * HDF_KILO_UNIT * ((long)(ms % HDF_KILO_UNIT)); result = nanosleep(&ts, &ts); if (result != 0) { HDF_LOGE("%s OsalMSleep failed %d", __func__, errno); @@ -80,8 +80,8 @@ void OsalUSleep(uint32_t us) int result; struct timespec ts; - ts.tv_sec = us / ((long)HDF_KILO_UNIT * HDF_KILO_UNIT); - ts.tv_nsec = HDF_KILO_UNIT * ((long)(us % HDF_KILO_UNIT)); + ts.tv_sec = (time_t)us / ((long)HDF_KILO_UNIT * HDF_KILO_UNIT); + ts.tv_nsec = (time_t)HDF_KILO_UNIT * ((long)(us % HDF_KILO_UNIT)); result = nanosleep(&ts, &ts); if (result != 0) { HDF_LOGE("%s OsalUSleep failed %d", __func__, errno); diff --git a/test/unittest/utils/hcs_parser/unittest/hcs_config_test.c b/test/unittest/utils/hcs_parser/unittest/hcs_config_test.c index 71baeee7..d942cda2 100644 --- a/test/unittest/utils/hcs_parser/unittest/hcs_config_test.c +++ b/test/unittest/utils/hcs_parser/unittest/hcs_config_test.c @@ -268,7 +268,7 @@ int HcsTestGetUint8ArrayElemSuccess(void) uint8_t data[DATA_TEST_ARRAY_LENGTH] = { 0 }; // the test data is 0, 1, 2, 3, 4, 5, 6, 7. uint8_t testData[DATA_TEST_ARRAY_LENGTH] = { 0, 1, 2, 3, 4, 5, 6, 7 }; - uint32_t i; + int32_t i; int32_t count; if (!TestGetRootNode()) { return HDF_FAILURE; @@ -294,7 +294,7 @@ int HcsTestGetUint8ArrayElemFail(void) const struct DeviceResourceNode *dataType = NULL; uint8_t data1[DATA_TYPE_NUM_U64] = { 0 }; uint8_t data; - uint32_t i; + int32_t i; int32_t ret; int32_t count; if (!TestGetRootNode()) { @@ -423,7 +423,7 @@ int HcsTestGetUint16ArrayElemSuccess(void) uint16_t data[DATA_TEST_ARRAY_LENGTH] = { 0 }; // the test data is 0, 1, 2, 3, 4, 5, 256, 257. uint16_t testData[DATA_TEST_ARRAY_LENGTH] = { 0, 1, 2, 3, 4, 5, 256, 257 }; - uint32_t i; + int32_t i; int32_t count; if (!TestGetRootNode()) { return HDF_FAILURE; @@ -448,7 +448,7 @@ int HcsTestGetUint16ArrayElemFail(void) const struct DeviceResourceNode *dataType = NULL; uint16_t data1[DATA_TYPE_NUM_U64] = { 0 }; uint16_t data; - uint32_t i; + int32_t i; int32_t ret; int32_t count; if (!TestGetRootNode()) { @@ -699,7 +699,7 @@ int HcsTestGetUint64ArrayElemSuccess(void) const struct DeviceResourceNode *dataType = NULL; uint64_t data[DATA_TYPE_NUM_U64] = { 0 }; uint64_t testData[DATA_TYPE_NUM_U64] = { U8_DATA, U16_DATA, U32_DATA, U64_DATA }; - uint32_t i; + int32_t i; int32_t count; if (!TestGetRootNode()) { return HDF_FAILURE; diff --git a/utils/src/hcs_parser/hcs_blob_if.c b/utils/src/hcs_parser/hcs_blob_if.c index dfb023d8..1601ba79 100644 --- a/utils/src/hcs_parser/hcs_blob_if.c +++ b/utils/src/hcs_parser/hcs_blob_if.c @@ -111,7 +111,7 @@ int32_t HcsGetNodeLength(const char *blob) HDF_LOGE("%s failed, the rootLen is %d", __func__, rootLen); return HDF_FAILURE; } - rootLen += HcsByteCodeToUint32(blob + HCS_PREFIX_LENGTH + HCS_STRING_LENGTH(blob + HCS_PREFIX_LENGTH)); + rootLen += (int32_t)HcsByteCodeToUint32(blob + HCS_PREFIX_LENGTH + HCS_STRING_LENGTH(blob + HCS_PREFIX_LENGTH)); return rootLen; } @@ -176,11 +176,11 @@ static bool CheckHcsBlobLength(uint32_t length, struct HbcHeader *header) uint32_t minLength = rootNodeLen + HBC_HEADER_LENGTH; uint32_t blobLength; if (header->totalSize >= 0) { - blobLength = HBC_HEADER_LENGTH + header->totalSize; + blobLength = (uint32_t)(HBC_HEADER_LENGTH + header->totalSize); g_byteAlign = false; HDF_LOGI("%s: the blobLength: %u, byteAlign: %d", __func__, blobLength, g_byteAlign); } else { - blobLength = HBC_HEADER_LENGTH - header->totalSize; + blobLength = (uint32_t)(HBC_HEADER_LENGTH - header->totalSize); g_byteAlign = true; HDF_LOGI("%s: the blobLength: %u, byteAlign: %d", __func__, blobLength, g_byteAlign); } diff --git a/utils/src/hcs_parser/hcs_generate_tree.c b/utils/src/hcs_parser/hcs_generate_tree.c index 672c29db..0b0aeb6d 100644 --- a/utils/src/hcs_parser/hcs_generate_tree.c +++ b/utils/src/hcs_parser/hcs_generate_tree.c @@ -34,7 +34,7 @@ static struct DeviceResourceNode *CreateTreeNode(const char *start, int32_t offs struct DeviceResourceNode *curNode = NULL; *treeMem += sizeof(struct DeviceResourceNode); newNode->name = start + offset + HCS_PREFIX_LENGTH; - newNode->hashValue = offset + sizeof(struct HbcHeader); + newNode->hashValue = (uint32_t)offset + sizeof(struct HbcHeader); if (parentNode != NULL) { newNode->parent = parentNode; curNode = parentNode->child; @@ -103,7 +103,7 @@ static int32_t ParseByteCode(const char *treeStart, int32_t offset, char **treeM newNode = CreateTreeNode(treeStart, offset, parentOrCurNode, treeMem); (void)HcsSwapToUint32(&newNodeOffset, treeStart + offset + HCS_STRING_LENGTH(newNode->name) + HCS_PREFIX_LENGTH, CONFIG_DWORD); - newNodeOffset += offset + termOffset; + newNodeOffset += (uint32_t)(offset + termOffset); if (!UpdateTreeStack(treeStack, treeLayerOrMemLen, newNode, newNodeOffset)) { return HDF_FAILURE; } diff --git a/utils/src/hdf_cstring.c b/utils/src/hdf_cstring.c index a5d503fd..924d10a6 100644 --- a/utils/src/hdf_cstring.c +++ b/utils/src/hdf_cstring.c @@ -43,7 +43,7 @@ struct HdfCString *HdfCStringObtain(const char *str) OsalMemFree(instance); return NULL; } - instance->size = strLen; + instance->size = (int)strLen; } return instance; } diff --git a/utils/src/osal_msg_queue.c b/utils/src/osal_msg_queue.c index 46445455..5f67f64a 100644 --- a/utils/src/osal_msg_queue.c +++ b/utils/src/osal_msg_queue.c @@ -59,7 +59,7 @@ struct HdfMessage* HdfMessageQueueNext(struct HdfMessageQueue *queue) struct HdfSListIterator it; struct HdfMessage *message = NULL; uint64_t currentTime = OsalGetSysTimeMs(); - long miniTimeoutMs = OSAL_WAIT_FOREVER; + OsalMutexLock(&queue->mutex); HdfSListIteratorInit(&it, &queue->list); while (HdfSListIteratorHasNext(&it)) { @@ -72,7 +72,7 @@ struct HdfMessage* HdfMessageQueueNext(struct HdfMessageQueue *queue) } OsalMutexUnlock(&queue->mutex); - OsalSemWait(&queue->semaphore, miniTimeoutMs); + OsalSemWait(&queue->semaphore, OSAL_WAIT_FOREVER); return NULL; }