From 6d1d5db1a9bb581b166b7181e35f35cc2ec0d256 Mon Sep 17 00:00:00 2001 From: zhang Date: Sat, 18 Sep 2021 15:35:34 +0800 Subject: [PATCH 1/3] modify reviewbot of utils Signed-off-by: zhang --- utils/include/hdf_block_buffer.h | 3 +-- utils/include/hdf_blocking_queue.h | 6 ++---- utils/include/hdf_ordered_list.h | 4 ++-- utils/src/hdf_block_buffer.c | 16 ++++++---------- utils/src/hdf_blocking_queue.c | 4 ++-- utils/src/hdf_object_alloc.c | 14 +++----------- utils/src/hdf_ordered_list.c | 3 +-- 7 files changed, 17 insertions(+), 33 deletions(-) diff --git a/utils/include/hdf_block_buffer.h b/utils/include/hdf_block_buffer.h index 205897e25..6e6b2f573 100644 --- a/utils/include/hdf_block_buffer.h +++ b/utils/include/hdf_block_buffer.h @@ -96,8 +96,7 @@ bool HdfBlockBufferWriteShort(struct BlockBuffer *buffer, uint16_t shortValue); * * @return the new instance of buff which contain specific packet. */ -struct HdfBlockBuffer *HdfBlockBufferDuplicate( - struct HdfBlockBuffer *buffer, uint16_t start, uint16_t end); +struct HdfBlockBuffer *HdfBlockBufferDuplicate(struct HdfBlockBuffer *buffer, uint16_t start, uint16_t end); /* * @brief append an byte array packet into buffer. diff --git a/utils/include/hdf_blocking_queue.h b/utils/include/hdf_blocking_queue.h index 5cfda6ecd..7b51f3a8d 100644 --- a/utils/include/hdf_blocking_queue.h +++ b/utils/include/hdf_blocking_queue.h @@ -17,15 +17,13 @@ extern "C" { #endif -struct HdfBlockingQueue -{ +struct HdfBlockingQueue { struct HdfSList list; struct OsalSem sem; struct OsalMutex mutex; }; -struct HdfSListEntry -{ +struct HdfSListEntry { struct HdfSListNode node; void *data; }; diff --git a/utils/include/hdf_ordered_list.h b/utils/include/hdf_ordered_list.h index ffb4ad02d..6f9aa2ba6 100644 --- a/utils/include/hdf_ordered_list.h +++ b/utils/include/hdf_ordered_list.h @@ -28,9 +28,9 @@ struct HdfOrderedListEntity { long key; }; -typedef void(*HdfOrderedListEntityDeleter)(struct HdfOrderedListEntity *); +typedef void (*HdfOrderedListEntityDeleter)(struct HdfOrderedListEntity *); -typedef bool (*HdfOrderedListComparer)(long , void *); +typedef bool (*HdfOrderedListComparer)(long, void *); void HdfOrderedListInit(struct HdfOrderedList *list); diff --git a/utils/src/hdf_block_buffer.c b/utils/src/hdf_block_buffer.c index 7816114ed..c5361fe88 100644 --- a/utils/src/hdf_block_buffer.c +++ b/utils/src/hdf_block_buffer.c @@ -6,11 +6,8 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include -#include #include "hdf_block_buffer.h" #include "osal_mem.h" -#include "utils.h" struct HdfHdfBlockBuffer *HdfHdfBlockBufferNew(const uint8_t *data, uint16_t size) { @@ -25,10 +22,10 @@ struct HdfHdfBlockBuffer *HdfHdfBlockBufferNew(const uint8_t *data, uint16_t siz return NULL; } buffer->dataSize = size; - buffer->position = 0; - if (data != NULL) { - memcpy(buffer->data, data, size); - } + buffer->position = 0; + if (data != NULL) { + memcpy(buffer->data, data, size); + } return buffer; } @@ -46,7 +43,7 @@ uint16_t HdfBlockBufferGetDataSize(struct HdfBlockBuffer *buffer) uint16_t HdfBlockBufferGetAvailableSize(struct HdfBlockBuffer *buffer) { - return (buffer == NULL) ? 0 : buffer->dataSize - buffer->position; + return (buffer == NULL) ? 0 : (buffer->dataSize - buffer->position); } uint8_t *HdfBlockBufferRead(struct HdfBlockBuffer *buffer, uint16_t size) @@ -181,8 +178,7 @@ bool HdfBlockBufferWriteData(struct HdfBlockBuffer *buffer, uint8_t *data, size_ return true; } -struct HdfBlockBuffer *HdfBlockBufferDuplicate( - struct HdfBlockBuffer *buffer, uint16_t start, uint16_t end) +struct HdfBlockBuffer *HdfBlockBufferDuplicate(struct HdfBlockBuffer *buffer, uint16_t start, uint16_t end) { uint16_t bufferSize = HdfBlockBufferGetDataSize(buffer); uint16_t newBufferSize; diff --git a/utils/src/hdf_blocking_queue.c b/utils/src/hdf_blocking_queue.c index 613849e9e..ed419b58c 100644 --- a/utils/src/hdf_blocking_queue.c +++ b/utils/src/hdf_blocking_queue.c @@ -110,7 +110,7 @@ void *HdfBlockingQueuePoll(struct HdfBlockingQueue *queue, long timeout) int HdfBlockingQueueOffer(struct HdfBlockingQueue *queue, void *val, long timeout) { - struct HdfSListEntry *entry = NULL; + struct HdfSListEntry *entry = NULL; if (OsalSemWait(&queue->sem, timeout) != 0) { return -1; } @@ -120,6 +120,6 @@ int HdfBlockingQueueOffer(struct HdfBlockingQueue *queue, void *val, long timeou HdfSListAddTail(&queue->list, &entry->node); OsalMutexUnlock(&queue->mutex); } - OsalSemPost(&queue->sem); + OsalSemPost(&queue->sem); } diff --git a/utils/src/hdf_object_alloc.c b/utils/src/hdf_object_alloc.c index ba4774c75..c923d4936 100644 --- a/utils/src/hdf_object_alloc.c +++ b/utils/src/hdf_object_alloc.c @@ -6,14 +6,10 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include -#include - +#include "hdf_base.h" +#include "hdf_object_alloc.h" #include "hdf_slist.h" -#include "object_alloc.h" -#include "osal_mem.h" #include "osal_mutex.h" -#include "utils.h" struct HdfChunkLink { uint32_t buffSize; @@ -66,7 +62,6 @@ struct HdfObjectNode *HdfObjectAllocFindSuitableChunk( while (HdfSListIteratorHasNext(&it)) { objectNode = (struct HdfObjectNode *)HdfSListIteratorNext(&it); - if (size == objectNode->chunkSize) { bestFitNode = objectNode; break; @@ -87,7 +82,6 @@ static void HdfObjectAllocPushObjectNode( while (HdfSListIteratorHasNext(&it)) { objectNode = (struct HdfObjectNode *)HdfSListIteratorNext(&it); - if (node->chunkSize >= objectNode->chunkSize) { break; } @@ -128,7 +122,7 @@ static void HdfObjectAllocPreloadChunk( void HdfObjectAllocLoadConfigs(const struct HdfObjectPoolConfig *configs) { - uint32_t idx = 0; + uint32_t idx; char *chunkBuffBegin = configs->buffer; char *chunkBuffEnd = configs->buffer + configs->bufferSize; @@ -161,7 +155,6 @@ void *HdfObjectAllocAlloc(size_t size) struct HdfObjectAlloc *allocator = HdfObjectAllocGetInstance(); OsalMutexLock(&allocator->mutex); objectNode = HdfObjectAllocFindSuitableChunk(allocator, size); - if ((objectNode != NULL) && (objectNode->freeCount == 0)) { goto finished; } @@ -184,7 +177,6 @@ void HdfObjectAllocFree(void *object) struct HdfObjectAlloc *allocator = HdfObjectAllocGetInstance(); OsalMutexLock(&allocator->mutex); objectNode = HdfObjectAllocFindSuitableChunk(allocator, chunkLink->buffSize); - if (objectNode != NULL) { objectNode->chunkStack[objectNode->freeCount++] = chunkLink; diff --git a/utils/src/hdf_ordered_list.c b/utils/src/hdf_ordered_list.c index a3cc2e2b9..3f45ac33b 100644 --- a/utils/src/hdf_ordered_list.c +++ b/utils/src/hdf_ordered_list.c @@ -6,7 +6,6 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include "osal_mem.h" #include "hdf_ordered_list.h" void HdfOrderedListInit(struct HdfOrderedList *list) @@ -86,7 +85,7 @@ long HdfOrderedListPeekKey(struct HdfOrderedList *list) } struct HdfOrderedListEntity *HdfOrderedListFetch( - struct HdfOrderedList *list, long matchKey, HdfOrderedListComparer comparer) + struct HdfOrderedList *list, long matchKey, HdfOrderedListComparer comparer) { struct HdfSListIterator it; struct HdfOrderedListEntity *matchEntity = NULL; -- Gitee From 57ea257ce092ffd2fa1a356b6b2d3afddf36cad6 Mon Sep 17 00:00:00 2001 From: zhang Date: Sat, 18 Sep 2021 15:46:37 +0800 Subject: [PATCH 2/3] modify reviewbot warning Signed-off-by: zhang --- utils/src/hdf_block_buffer.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/src/hdf_block_buffer.c b/utils/src/hdf_block_buffer.c index c5361fe88..6ca8b728e 100644 --- a/utils/src/hdf_block_buffer.c +++ b/utils/src/hdf_block_buffer.c @@ -9,6 +9,8 @@ #include "hdf_block_buffer.h" #include "osal_mem.h" +static const unsigned int OFFSET = 8; + struct HdfHdfBlockBuffer *HdfHdfBlockBufferNew(const uint8_t *data, uint16_t size) { uint16_t wantedSize; @@ -150,14 +152,14 @@ bool HdfBlockBufferWriteUint8(struct HdfBlockBuffer *buffer, uint8_t value) return false; } -bool HdfBlockBufferWriteUint16(struct HdfBlockBuffer *buffer, uint16_t in_value) +bool HdfBlockBufferWriteUint16(struct HdfBlockBuffer *buffer, uint16_t inValue) { if (buffer == NULL) { return false; } if (buffer->position + BYTES_UINT16 <= buffer->dataSize) { - buffer->data[buffer->position++] = (uint8_t) (in_value >> 8); - buffer->data[buffer->position++] = (uint8_t) (in_value & 0xFF); + buffer->data[buffer->position++] = (uint8_t) (inValue >> OFFSET); + buffer->data[buffer->position++] = (uint8_t) (inValue & 0xFF); return true; } return false; -- Gitee From 6458eb69edaaa873fef61d2692ae8319ac22096b Mon Sep 17 00:00:00 2001 From: zhang Date: Sat, 18 Sep 2021 16:30:39 +0800 Subject: [PATCH 3/3] modify reviewbot warning Signed-off-by: zhang --- utils/include/hdf_block_buffer.h | 4 ++-- utils/src/hdf_block_buffer.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/utils/include/hdf_block_buffer.h b/utils/include/hdf_block_buffer.h index 6e6b2f573..43a6837de 100644 --- a/utils/include/hdf_block_buffer.h +++ b/utils/include/hdf_block_buffer.h @@ -25,7 +25,7 @@ struct HdfBlockBuffer { struct HdfBlockBuffer *HdfBlockBufferNew(uint16_t size); -void HdfBlockBufferFree(struct BlockBuffer *buffer); +void HdfBlockBufferFree(const struct BlockBuffer *buffer); uint16_t HdfBlockBufferGetDataSize(struct BlockBuffer *buffer); @@ -96,7 +96,7 @@ bool HdfBlockBufferWriteShort(struct BlockBuffer *buffer, uint16_t shortValue); * * @return the new instance of buff which contain specific packet. */ -struct HdfBlockBuffer *HdfBlockBufferDuplicate(struct HdfBlockBuffer *buffer, uint16_t start, uint16_t end); +struct HdfBlockBuffer *HdfBlockBufferDuplicate(const struct HdfBlockBuffer *buffer, uint16_t start, uint16_t end); /* * @brief append an byte array packet into buffer. diff --git a/utils/src/hdf_block_buffer.c b/utils/src/hdf_block_buffer.c index 6ca8b728e..1c61c57b4 100644 --- a/utils/src/hdf_block_buffer.c +++ b/utils/src/hdf_block_buffer.c @@ -31,10 +31,10 @@ struct HdfHdfBlockBuffer *HdfHdfBlockBufferNew(const uint8_t *data, uint16_t siz return buffer; } -void HdfBlockBufferFree(struct HdfBlockBuffer *buffer) +void HdfBlockBufferFree(const struct HdfBlockBuffer *buffer) { if (buffer != NULL) { - free(buffer); + OsalMemFree(buffer); } } @@ -180,7 +180,7 @@ bool HdfBlockBufferWriteData(struct HdfBlockBuffer *buffer, uint8_t *data, size_ return true; } -struct HdfBlockBuffer *HdfBlockBufferDuplicate(struct HdfBlockBuffer *buffer, uint16_t start, uint16_t end) +struct HdfBlockBuffer *HdfBlockBufferDuplicate(const struct HdfBlockBuffer *buffer, uint16_t start, uint16_t end) { uint16_t bufferSize = HdfBlockBufferGetDataSize(buffer); uint16_t newBufferSize; -- Gitee