From 1382ea5447c7b725f540e2ff97d31b705f73a91f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Feb 2020 07:58:07 -0600 Subject: [PATCH] mm/: Coding style clean-up Run tools/nxstyle against all C files under mm/ and correct coding standard violations. --- mm/iob/iob_alloc_qentry.c | 6 +++--- mm/iob/iob_clone.c | 2 +- mm/iob/iob_copyin.c | 3 ++- mm/iob/iob_free.c | 3 ++- mm/iob/iob_navail.c | 1 + mm/iob/iob_pack.c | 14 +++++++------- mm/iob/iob_statistics.c | 1 - mm/iob/iob_test.c | 1 + mm/mm_gran/mm_granalloc.c | 3 ++- mm/mm_gran/mm_grancritical.c | 1 - mm/mm_gran/mm_granfree.c | 4 ++-- mm/mm_gran/mm_graninfo.c | 14 +++++++------- mm/mm_gran/mm_granmark.c | 4 ++-- mm/mm_gran/mm_pgalloc.c | 2 ++ mm/mm_heap/mm_extend.c | 3 ++- mm/mm_heap/mm_initialize.c | 18 ++++++++++-------- mm/mm_heap/mm_malloc.c | 4 ++-- mm/mm_heap/mm_memalign.c | 6 ++++-- mm/mm_heap/mm_realloc.c | 27 ++++++++++++++++++--------- mm/mm_heap/mm_sem.c | 8 ++++---- mm/mm_heap/mm_shrinkchunk.c | 3 ++- mm/mm_heap/mm_size2ndx.c | 2 +- mm/umm_heap/umm_globals.c | 4 ++++ 23 files changed, 79 insertions(+), 55 deletions(-) diff --git a/mm/iob/iob_alloc_qentry.c b/mm/iob/iob_alloc_qentry.c index 699040eaf1..588a6d29b0 100644 --- a/mm/iob/iob_alloc_qentry.c +++ b/mm/iob/iob_alloc_qentry.c @@ -132,9 +132,9 @@ static FAR struct iob_qentry_s *iob_allocwait_qentry(void) ret = nxsem_wait_uninterruptible(&g_qentry_sem); if (ret >= 0) { - /* When we wake up from wait successfully, an I/O buffer chain container was - * freed and we hold a count for one IOB. Unless somehting - * failed, we should have an IOB waiting for us in the + /* When we wake up from wait successfully, an I/O buffer chain + * container was freed and we hold a count for one IOB. Unless + * something failed, we should have an IOB waiting for us in the * committed list. */ diff --git a/mm/iob/iob_clone.c b/mm/iob/iob_clone.c index c5e0563ad7..fcb361dfb5 100644 --- a/mm/iob/iob_clone.c +++ b/mm/iob/iob_clone.c @@ -151,7 +151,7 @@ int iob_clone(FAR struct iob_s *iob1, FAR struct iob_s *iob2, bool throttled, * transferred? */ - if (offset2 >= CONFIG_IOB_BUFSIZE && iob1 != NULL) + if (offset2 >= CONFIG_IOB_BUFSIZE && iob1 != NULL) { FAR struct iob_s *next; diff --git a/mm/iob/iob_copyin.c b/mm/iob/iob_copyin.c index f4187274eb..c90ee46356 100644 --- a/mm/iob/iob_copyin.c +++ b/mm/iob/iob_copyin.c @@ -250,5 +250,6 @@ int iob_trycopyin(FAR struct iob_s *iob, FAR const uint8_t *src, unsigned int len, unsigned int offset, bool throttled, enum iob_user_e consumerid) { - return iob_copyin_internal(iob, src, len, offset, throttled, false, consumerid); + return iob_copyin_internal(iob, src, len, offset, throttled, false, + consumerid); } diff --git a/mm/iob/iob_free.c b/mm/iob/iob_free.c index 6e78392843..9729a4db05 100644 --- a/mm/iob/iob_free.c +++ b/mm/iob/iob_free.c @@ -169,7 +169,8 @@ FAR struct iob_s *iob_free(FAR struct iob_s *iob, #if CONFIG_IOB_THROTTLE > 0 nxsem_post(&g_throttle_sem); - DEBUGASSERT(g_throttle_sem.semcount <= (CONFIG_IOB_NBUFFERS - CONFIG_IOB_THROTTLE)); + DEBUGASSERT(g_throttle_sem.semcount <= + (CONFIG_IOB_NBUFFERS - CONFIG_IOB_THROTTLE)); #endif #ifdef CONFIG_IOB_NOTIFIER diff --git a/mm/iob/iob_navail.c b/mm/iob/iob_navail.c index e6104840b3..9ac0fe742e 100644 --- a/mm/iob/iob_navail.c +++ b/mm/iob/iob_navail.c @@ -78,6 +78,7 @@ int iob_navail(bool throttled) ret -= CONFIG_IOB_THROTTLE; } #endif + if (ret < 0) { ret = 0; diff --git a/mm/iob/iob_pack.c b/mm/iob/iob_pack.c index b14dcb2e51..27d1d18fe8 100644 --- a/mm/iob/iob_pack.c +++ b/mm/iob/iob_pack.c @@ -127,15 +127,15 @@ FAR struct iob_s *iob_pack(FAR struct iob_s *iob, next->io_offset += ncopy; } - /* Have we consumed all of the data in the next entry? */ + /* Have we consumed all of the data in the next entry? */ - if (next->io_len <= 0) - { - /* Yes.. free the next entry in I/O buffer chain */ + if (next->io_len <= 0) + { + /* Yes.. free the next entry in I/O buffer chain */ - next = iob_free(next, producerid); - iob->io_flink = next; - } + next = iob_free(next, producerid); + iob->io_flink = next; + } } /* Set up to pack the next entry in the chain */ diff --git a/mm/iob/iob_statistics.c b/mm/iob/iob_statistics.c index bd849dc580..e01c0d4314 100644 --- a/mm/iob/iob_statistics.c +++ b/mm/iob/iob_statistics.c @@ -107,7 +107,6 @@ void iob_stats_onfree(enum iob_user_e producerid) /* Increment the global statistic as well */ g_iobuserstats[IOBUSER_GLOBAL].totalproduced++; - } /**************************************************************************** diff --git a/mm/iob/iob_test.c b/mm/iob/iob_test.c index 87396307ab..78a4f387db 100644 --- a/mm/iob/iob_test.c +++ b/mm/iob/iob_test.c @@ -115,6 +115,7 @@ int main(int argc, char **argv) { buffer1[i] = (uint8_t)(i & 0xff); } + memset(buffer2, 0xff, 4096); iob_copyin(iob, buffer2, 47, 0, false, IOBUSER_UNITTEST); diff --git a/mm/mm_gran/mm_granalloc.c b/mm/mm_gran/mm_granalloc.c index be11d0f7af..9cc8f10009 100644 --- a/mm/mm_gran/mm_granalloc.c +++ b/mm/mm_gran/mm_granalloc.c @@ -213,7 +213,8 @@ FAR void *gran_alloc(GRAN_HANDLE handle, size_t size) } /* We know that the first free bit is now within the lower 4 bits - * of 'curr'. Check if we have the allocation at this bit position. + * of 'curr'. Check if we have the allocation at this bit + * position. */ else if ((curr & mask) == 0) diff --git a/mm/mm_gran/mm_grancritical.c b/mm/mm_gran/mm_grancritical.c index 0f5a4b7b0e..4d3da33699 100644 --- a/mm/mm_gran/mm_grancritical.c +++ b/mm/mm_gran/mm_grancritical.c @@ -86,5 +86,4 @@ void gran_leave_critical(FAR struct gran_s *priv) #endif } - #endif /* CONFIG_GRAN */ diff --git a/mm/mm_gran/mm_granfree.c b/mm/mm_gran/mm_granfree.c index 3b35a50881..1ed5e208e2 100644 --- a/mm/mm_gran/mm_granfree.c +++ b/mm/mm_gran/mm_granfree.c @@ -115,9 +115,9 @@ void gran_free(GRAN_HANDLE handle, FAR void *memory, size_t size) /* Clear bits in the second GAT entry */ gatmask = 0xffffffff >> (32 - ngranules); - DEBUGASSERT((priv->gat[gatidx+1] & gatmask) == gatmask); + DEBUGASSERT((priv->gat[gatidx + 1] & gatmask) == gatmask); - priv->gat[gatidx+1] &= ~gatmask; + priv->gat[gatidx + 1] &= ~gatmask; } /* Handle the case where where all of the granules came from one entry */ diff --git a/mm/mm_gran/mm_graninfo.c b/mm/mm_gran/mm_graninfo.c index a50597e80a..b2f00873d9 100644 --- a/mm/mm_gran/mm_graninfo.c +++ b/mm/mm_gran/mm_graninfo.c @@ -124,11 +124,11 @@ static const struct nibble_info_s g_4bit_info[16] = static const struct nibble_info_s *g_info_table[5] = { - g_0bit_info, - g_1bit_info, - g_2bit_info, - g_3bit_info, - g_4bit_info + g_0bit_info, + g_1bit_info, + g_2bit_info, + g_3bit_info, + g_4bit_info }; /**************************************************************************** @@ -312,7 +312,7 @@ static void gran_byte_info(uint8_t value, FAR struct valinfo_s *info, /* Handle special cases */ - if (value == 0) + if (value == 0) { /* All free */ @@ -379,7 +379,7 @@ static void gran_hword_info(uint16_t value, FAR struct valinfo_s *info, /* Handle special cases */ - if (value == 0) + if (value == 0) { /* All free */ diff --git a/mm/mm_gran/mm_granmark.c b/mm/mm_gran/mm_granmark.c index 7466d91c73..a26b47d985 100644 --- a/mm/mm_gran/mm_granmark.c +++ b/mm/mm_gran/mm_granmark.c @@ -101,9 +101,9 @@ void gran_mark_allocated(FAR struct gran_s *priv, uintptr_t alloc, /* Mark bits in the second GAT entry */ gatmask = 0xffffffff >> (32 - ngranules); - DEBUGASSERT((priv->gat[gatidx+1] & gatmask) == 0); + DEBUGASSERT((priv->gat[gatidx + 1] & gatmask) == 0); - priv->gat[gatidx+1] |= gatmask; + priv->gat[gatidx + 1] |= gatmask; } /* Handle the case where where all of the granules come from one entry */ diff --git a/mm/mm_gran/mm_pgalloc.c b/mm/mm_gran/mm_pgalloc.c index b0a939b109..bb60c37a77 100644 --- a/mm/mm_gran/mm_pgalloc.c +++ b/mm/mm_gran/mm_pgalloc.c @@ -51,7 +51,9 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ + /* Configuration ************************************************************/ + /* CONFIG_MM_PGALLOC - Enable page allocator support * CONFIG_MM_PGSIZE - The page size. Must be one of {1024, 2048, * 4096, 8192, or 16384}. This is easily extensible, but only those diff --git a/mm/mm_heap/mm_extend.c b/mm/mm_heap/mm_extend.c index b10eea5a44..3eb0605258 100644 --- a/mm/mm_heap/mm_extend.c +++ b/mm/mm_heap/mm_extend.c @@ -112,7 +112,8 @@ void mm_extend(FAR struct mm_heap_s *heap, FAR void *mem, size_t size, /* Get and initialize the new terminal node in the heap */ - newnode = (FAR struct mm_allocnode_s *)(blockend - SIZEOF_MM_ALLOCNODE); + newnode = (FAR struct mm_allocnode_s *) + (blockend - SIZEOF_MM_ALLOCNODE); newnode->size = SIZEOF_MM_ALLOCNODE; newnode->preceding = oldnode->size | MM_ALLOC_BIT; diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c index 2331f64827..9382224d07 100644 --- a/mm/mm_heap/mm_initialize.c +++ b/mm/mm_heap/mm_initialize.c @@ -85,7 +85,7 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart, * crazy. */ - DEBUGASSERT(heapsize <= MMSIZE_MAX+1); + DEBUGASSERT(heapsize <= MMSIZE_MAX + 1); #endif /* Adjust the provide heap start and size so that they are both aligned @@ -96,7 +96,7 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart, heapend = MM_ALIGN_DOWN((uintptr_t)heapstart + (uintptr_t)heapsize); heapsize = heapend - heapbase; - minfo("Region %d: base=%p size=%u\n", IDX+1, heapstart, heapsize); + minfo("Region %d: base=%p size=%u\n", IDX + 1, heapstart, heapsize); /* Add the size of this region to the total size of the heap */ @@ -114,11 +114,13 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart, heap->mm_heapstart[IDX]->size = SIZEOF_MM_ALLOCNODE; heap->mm_heapstart[IDX]->preceding = MM_ALLOC_BIT; - node = (FAR struct mm_freenode_s *)(heapbase + SIZEOF_MM_ALLOCNODE); - node->size = heapsize - 2*SIZEOF_MM_ALLOCNODE; - node->preceding = SIZEOF_MM_ALLOCNODE; + node = (FAR struct mm_freenode_s *) + (heapbase + SIZEOF_MM_ALLOCNODE); + node->size = heapsize - 2*SIZEOF_MM_ALLOCNODE; + node->preceding = SIZEOF_MM_ALLOCNODE; - heap->mm_heapend[IDX] = (FAR struct mm_allocnode_s *)(heapend - SIZEOF_MM_ALLOCNODE); + heap->mm_heapend[IDX] = (FAR struct mm_allocnode_s *) + (heapend - SIZEOF_MM_ALLOCNODE); heap->mm_heapend[IDX]->size = SIZEOF_MM_ALLOCNODE; heap->mm_heapend[IDX]->preceding = node->size | MM_ALLOC_BIT; @@ -182,8 +184,8 @@ void mm_initialize(FAR struct mm_heap_s *heap, FAR void *heapstart, memset(heap->mm_nodelist, 0, sizeof(struct mm_freenode_s) * MM_NNODES); for (i = 1; i < MM_NNODES; i++) { - heap->mm_nodelist[i-1].flink = &heap->mm_nodelist[i]; - heap->mm_nodelist[i].blink = &heap->mm_nodelist[i-1]; + heap->mm_nodelist[i - 1].flink = &heap->mm_nodelist[i]; + heap->mm_nodelist[i].blink = &heap->mm_nodelist[i - 1]; } /* Initialize the malloc semaphore to one (to support one-at- diff --git a/mm/mm_heap/mm_malloc.c b/mm/mm_heap/mm_malloc.c index ef3630626a..5d72eb74a2 100644 --- a/mm/mm_heap/mm_malloc.c +++ b/mm/mm_heap/mm_malloc.c @@ -100,7 +100,7 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size) if (alignsize >= MM_MAX_CHUNK) { - ndx = MM_NNODES-1; + ndx = MM_NNODES - 1; } else { @@ -188,7 +188,7 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size) #ifdef CONFIG_MM_FILL_ALLOCATIONS if (ret) { - memset(ret, 0xAA, alignsize - SIZEOF_MM_ALLOCNODE); + memset(ret, 0xaa, alignsize - SIZEOF_MM_ALLOCNODE); } #endif diff --git a/mm/mm_heap/mm_memalign.c b/mm/mm_heap/mm_memalign.c index dd87e6c954..5f7b1e3f2f 100644 --- a/mm/mm_heap/mm_memalign.c +++ b/mm/mm_heap/mm_memalign.c @@ -135,7 +135,8 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, DEBUGASSERT(alignedchunk >= rawchunk + 8); - newnode = (FAR struct mm_allocnode_s *)(alignedchunk - SIZEOF_MM_ALLOCNODE); + newnode = (FAR struct mm_allocnode_s *) + (alignedchunk - SIZEOF_MM_ALLOCNODE); /* Preceding size is full size of the new 'node,' including * SIZEOF_MM_ALLOCNODE @@ -154,7 +155,8 @@ FAR void *mm_memalign(FAR struct mm_heap_s *heap, size_t alignment, if (precedingsize < SIZEOF_MM_FREENODE) { alignedchunk += alignment; - newnode = (FAR struct mm_allocnode_s *)(alignedchunk - SIZEOF_MM_ALLOCNODE); + newnode = (FAR struct mm_allocnode_s *) + (alignedchunk - SIZEOF_MM_ALLOCNODE); precedingsize = (size_t)newnode - (size_t)node; } diff --git a/mm/mm_heap/mm_realloc.c b/mm/mm_heap/mm_realloc.c index f5976fad55..54c4aab8a7 100644 --- a/mm/mm_heap/mm_realloc.c +++ b/mm/mm_heap/mm_realloc.c @@ -108,7 +108,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, /* Map the memory chunk into an allocated node structure */ - oldnode = (FAR struct mm_allocnode_s *)((FAR char *)oldmem - SIZEOF_MM_ALLOCNODE); + oldnode = (FAR struct mm_allocnode_s *) + ((FAR char *)oldmem - SIZEOF_MM_ALLOCNODE); /* We need to hold the MM semaphore while we muck with the nodelist. */ @@ -139,13 +140,15 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, * best decision */ - next = (FAR struct mm_freenode_s *)((FAR char *)oldnode + oldnode->size); + next = (FAR struct mm_freenode_s *) + ((FAR char *)oldnode + oldnode->size); if ((next->preceding & MM_ALLOC_BIT) == 0) { nextsize = next->size; } - prev = (FAR struct mm_freenode_s *)((FAR char *)oldnode - (oldnode->preceding & ~MM_ALLOC_BIT)); + prev = (FAR struct mm_freenode_s *) + ((FAR char *)oldnode - (oldnode->preceding & ~MM_ALLOC_BIT)); if ((prev->preceding & MM_ALLOC_BIT) == 0) { prevsize = prev->size; @@ -233,7 +236,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, /* Extend the node into the previous free chunk */ - newnode = (FAR struct mm_allocnode_s *)((FAR char *)oldnode - takeprev); + newnode = (FAR struct mm_allocnode_s *) + ((FAR char *)oldnode - takeprev); /* Did we consume the entire preceding chunk? */ @@ -246,7 +250,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, prev->size -= takeprev; newnode->size = oldsize + takeprev; newnode->preceding = prev->size | MM_ALLOC_BIT; - next->preceding = newnode->size | (next->preceding & MM_ALLOC_BIT); + next->preceding = newnode->size | + (next->preceding & MM_ALLOC_BIT); /* Return the previous free node to the nodelist (with the new size) */ @@ -258,7 +263,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, newnode->size += oldsize; newnode->preceding |= MM_ALLOC_BIT; - next->preceding = newnode->size | (next->preceding & MM_ALLOC_BIT); + next->preceding = newnode->size | + (next->preceding & MM_ALLOC_BIT); } /* Now we want to return newnode */ @@ -301,7 +307,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, /* Extend the node into the next chunk */ oldnode->size = oldsize + takenext; - newnode = (FAR struct mm_freenode_s *)((FAR char *)oldnode + oldnode->size); + newnode = (FAR struct mm_freenode_s *) + ((FAR char *)oldnode + oldnode->size); /* Did we consume the entire preceding chunk? */ @@ -313,7 +320,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, newnode->size = nextsize - takenext; newnode->preceding = oldnode->size; - andbeyond->preceding = newnode->size | (andbeyond->preceding & MM_ALLOC_BIT); + andbeyond->preceding = newnode->size | + (andbeyond->preceding & MM_ALLOC_BIT); /* Add the new free node to the nodelist (with the new size) */ @@ -323,7 +331,8 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem, { /* Yes, just update some pointers. */ - andbeyond->preceding = oldnode->size | (andbeyond->preceding & MM_ALLOC_BIT); + andbeyond->preceding = oldnode->size | + (andbeyond->preceding & MM_ALLOC_BIT); } } diff --git a/mm/mm_heap/mm_sem.c b/mm/mm_heap/mm_sem.c index 1b8f77289c..2a32446650 100644 --- a/mm/mm_heap/mm_sem.c +++ b/mm/mm_heap/mm_sem.c @@ -193,10 +193,10 @@ int mm_trysemaphore(FAR struct mm_heap_s *heap) ret = _SEM_TRYWAIT(&heap->mm_semaphore); if (ret < 0) - { - _SEM_GETERROR(ret); - goto errout; - } + { + _SEM_GETERROR(ret); + goto errout; + } /* We have it. Claim the heap for the current task and return */ diff --git a/mm/mm_heap/mm_shrinkchunk.c b/mm/mm_heap/mm_shrinkchunk.c index 6eac849b3e..9b786fc6d7 100644 --- a/mm/mm_heap/mm_shrinkchunk.c +++ b/mm/mm_heap/mm_shrinkchunk.c @@ -106,7 +106,8 @@ void mm_shrinkchunk(FAR struct mm_heap_s *heap, newnode->size = next->size + node->size - size; newnode->preceding = size; node->size = size; - andbeyond->preceding = newnode->size | (andbeyond->preceding & MM_ALLOC_BIT); + andbeyond->preceding = newnode->size | + (andbeyond->preceding & MM_ALLOC_BIT); /* Add the new node to the freenodelist */ diff --git a/mm/mm_heap/mm_size2ndx.c b/mm/mm_heap/mm_size2ndx.c index 841dea3687..e5f3f399c1 100644 --- a/mm/mm_heap/mm_size2ndx.c +++ b/mm/mm_heap/mm_size2ndx.c @@ -59,7 +59,7 @@ int mm_size2ndx(size_t size) if (size >= MM_MAX_CHUNK) { - return MM_NNODES-1; + return MM_NNODES - 1; } size >>= MM_MIN_SHIFT; diff --git a/mm/umm_heap/umm_globals.c b/mm/umm_heap/umm_globals.c index 012aac7631..2052e98102 100644 --- a/mm/umm_heap/umm_globals.c +++ b/mm/umm_heap/umm_globals.c @@ -66,3 +66,7 @@ struct mm_heap_s g_mmheap; #endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/