fix: 内源代码检视问题

【背景】内源代码检视问题

【修改方案】
1,按检视意见,进行资源泄露等问题的修改

【影响】
对现有的产品编译不会有影响。

re #I4WV56
Signed-off-by: wangchen <wangchen64@huawei.com>
This commit is contained in:
wangchen 2022-03-08 08:36:59 +00:00
parent 7e284239b3
commit 43baa4fdc4
13 changed files with 61 additions and 89 deletions

View File

@ -179,7 +179,6 @@ exc_entry:
csrr a0, mcause csrr a0, mcause
mv a1, sp mv a1, sp
/* /*
* TODO: Call the exception handler function
* By default, the function template is provided in * By default, the function template is provided in
* system_Device.c, you can adjust it as you want * system_Device.c, you can adjust it as you want
*/ */

View File

@ -336,19 +336,19 @@ int LfsMount(const char *source, const char *target, const char *fileSystemType,
if (target == NULL || fileSystemType == NULL || data == NULL) { if (target == NULL || fileSystemType == NULL || data == NULL) {
errno = EFAULT; errno = EFAULT;
ret = VFS_ERROR; ret = VFS_ERROR;
goto errout; goto ERROUT;
} }
if (strcmp(fileSystemType, "littlefs") != 0) { if (strcmp(fileSystemType, "littlefs") != 0) {
errno = ENODEV; errno = ENODEV;
ret = VFS_ERROR; ret = VFS_ERROR;
goto errout; goto ERROUT;
} }
if (CheckPathIsMounted(target, &fileOpInfo)) { if (CheckPathIsMounted(target, &fileOpInfo)) {
errno = EBUSY; errno = EBUSY;
ret = VFS_ERROR; ret = VFS_ERROR;
goto errout; goto ERROUT;
} }
// select free mount resource // select free mount resource
@ -356,7 +356,7 @@ int LfsMount(const char *source, const char *target, const char *fileSystemType,
if (fileOpInfo == NULL) { if (fileOpInfo == NULL) {
errno = ENODEV; errno = ENODEV;
ret = VFS_ERROR; ret = VFS_ERROR;
goto errout; goto ERROUT;
} }
ret = lfs_mount(&(fileOpInfo->lfsInfo), (struct lfs_config*)data); ret = lfs_mount(&(fileOpInfo->lfsInfo), (struct lfs_config*)data);
@ -372,7 +372,7 @@ int LfsMount(const char *source, const char *target, const char *fileSystemType,
ret = VFS_ERROR; ret = VFS_ERROR;
} }
errout: ERROUT:
return ret; return ret;
} }
@ -483,23 +483,23 @@ DIR *LfsOpendir(const char *dirName)
if (dirName == NULL) { if (dirName == NULL) {
errno = EFAULT; errno = EFAULT;
goto errout; goto ERROUT;
} }
if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) { if (CheckPathIsMounted(dirName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
errno = ENOENT; errno = ENOENT;
goto errout; goto ERROUT;
} }
if (CheckDirIsOpen(dirName)) { if (CheckDirIsOpen(dirName)) {
errno = EBUSY; errno = EBUSY;
goto errout; goto ERROUT;
} }
FileDirInfo *dirInfo = GetFreeDir(dirName); FileDirInfo *dirInfo = GetFreeDir(dirName);
if (dirInfo == NULL) { if (dirInfo == NULL) {
errno = ENFILE; errno = ENFILE;
goto errout; goto ERROUT;
} }
ret = lfs_dir_open(&(fileOpInfo->lfsInfo), (lfs_dir_t *)(&(dirInfo->dir)), dirName); ret = lfs_dir_open(&(fileOpInfo->lfsInfo), (lfs_dir_t *)(&(dirInfo->dir)), dirName);
@ -507,14 +507,14 @@ DIR *LfsOpendir(const char *dirName)
if (ret != 0) { if (ret != 0) {
FreeDirInfo(dirName); FreeDirInfo(dirName);
errno = LittlefsErrno(ret); errno = LittlefsErrno(ret);
goto errout; goto ERROUT;
} }
dirInfo->lfsHandle = &(fileOpInfo->lfsInfo); dirInfo->lfsHandle = &(fileOpInfo->lfsInfo);
return (DIR *)dirInfo; return (DIR *)dirInfo;
errout: ERROUT:
return NULL; return NULL;
} }
@ -584,23 +584,23 @@ int LfsOpen(const char *pathName, int openFlag, ...)
if (pathName == NULL) { if (pathName == NULL) {
errno = EFAULT; errno = EFAULT;
goto errout; goto ERROUT;
} }
if (CheckPathIsMounted(pathName, &fileOpInfo) == FALSE || fileOpInfo == NULL) { if (CheckPathIsMounted(pathName, &fileOpInfo) == FALSE || fileOpInfo == NULL) {
errno = ENOENT; errno = ENOENT;
goto errout; goto ERROUT;
} }
// if file is already open, return invalid fd // if file is already open, return invalid fd
if (CheckFileIsOpen(pathName)) { if (CheckFileIsOpen(pathName)) {
errno = EBUSY; errno = EBUSY;
goto errout; goto ERROUT;
} }
LittleFsHandleStruct *fsHandle = LfsAllocFd(pathName, &fd); LittleFsHandleStruct *fsHandle = LfsAllocFd(pathName, &fd);
if (fd == INVALID_FD) { if (fd == INVALID_FD) {
errno = ENFILE; errno = ENFILE;
goto errout; goto ERROUT;
} }
int lfsOpenFlag = ConvertFlagToLfsOpenFlag(openFlag); int lfsOpenFlag = ConvertFlagToLfsOpenFlag(openFlag);
@ -608,13 +608,13 @@ int LfsOpen(const char *pathName, int openFlag, ...)
if (err != 0) { if (err != 0) {
LfsFreeFd(fd); LfsFreeFd(fd);
errno = LittlefsErrno(err); errno = LittlefsErrno(err);
goto errout; goto ERROUT;
} }
g_handle[fd].lfsHandle = &(fileOpInfo->lfsInfo); g_handle[fd].lfsHandle = &(fileOpInfo->lfsInfo);
return fd; return fd;
errout: ERROUT:
return INVALID_FD; return INVALID_FD;
} }

View File

@ -182,11 +182,12 @@ VOID LOS_LmsCheckPoolDel(const VOID *pool)
LmsMemListNode *delNode = OsLmsGetPoolNode(pool); LmsMemListNode *delNode = OsLmsGetPoolNode(pool);
if (delNode == NULL) { if (delNode == NULL) {
PRINT_ERR("[LMS]pool %p is not on lms checklist !\n", pool); PRINT_ERR("[LMS]pool %p is not on lms checklist !\n", pool);
goto Release; goto REALEASE;
} }
delNode->used = LMS_POOL_UNUSED; delNode->used = LMS_POOL_UNUSED;
LOS_ListDelete(&(delNode->node)); LOS_ListDelete(&(delNode->node));
Release:
REALEASE:
LMS_UNLOCK(intSave); LMS_UNLOCK(intSave);
} }

View File

@ -605,6 +605,8 @@ u32_t OsShellPing(int argc, const char **argv)
PRINTK("Ping cmd failed due some errors\n"); PRINTK("Ping cmd failed due some errors\n");
} }
free(parg);
return LOS_OK; return LOS_OK;
ping_error: ping_error:
lwip_ping_usage(); lwip_ping_usage();

View File

@ -1634,7 +1634,7 @@ uint32_t osMemoryPoolGetSpace(osMemoryPoolId_t mp_id)
if ((mp->status & MEM_POOL_VALID) != MEM_POOL_VALID) { if ((mp->status & MEM_POOL_VALID) != MEM_POOL_VALID) {
space = 0; space = 0;
} else { } else {
space = mp->poolInfo.uwBlkCnt - mp->poolInfo.uwBlkCnt; space = mp->poolInfo.uwBlkNum - mp->poolInfo.uwBlkCnt;
} }
LOS_IntRestore(intSave); LOS_IntRestore(intSave);

View File

@ -169,7 +169,6 @@ exc_entry:
csrr a0, mcause csrr a0, mcause
mv a1, sp mv a1, sp
/* /*
* TODO: Call the exception handler function
* By default, the function template is provided in * By default, the function template is provided in
* system_Device.c, you can adjust it as you want * system_Device.c, you can adjust it as you want
*/ */

View File

@ -30,8 +30,6 @@
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
Define clocks Define clocks
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
/* ToDo: add here your necessary defines for device initialization
following is an example for different system frequencies */
#ifndef SYSTEM_CLOCK #ifndef SYSTEM_CLOCK
#define SYSTEM_CLOCK (80000000UL) #define SYSTEM_CLOCK (80000000UL)
#endif #endif
@ -71,9 +69,6 @@
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
System Core Clock Variable System Core Clock Variable
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
/* ToDo: initialize SystemCoreClock with the system core clock frequency value
achieved after system intitialization.
This means system core clock frequency after call to SystemInit() */
/** /**
* \brief Variable to hold the system core clock value * \brief Variable to hold the system core clock value
* \details * \details
@ -101,9 +96,7 @@ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Clock Frequency (Core Clock)
*/ */
void SystemCoreClockUpdate(void) /* Get Core Clock Frequency */ void SystemCoreClockUpdate(void) /* Get Core Clock Frequency */
{ {
/* ToDo: add code to calculate the system frequency based upon the current /* Note: This function can be used to retrieve the system core clock frequeny
* register settings.
* Note: This function can be used to retrieve the system core clock frequeny
* after user changed register settings. * after user changed register settings.
*/ */
SystemCoreClock = SYSTEM_CLOCK; SystemCoreClock = SYSTEM_CLOCK;
@ -119,8 +112,7 @@ void SystemCoreClockUpdate(void) /* Get Core Clock Frequency */
*/ */
void SystemInit(void) void SystemInit(void)
{ {
/* ToDo: add code to initialize the system /* Warn: do not use global variables because this function is called before
* Warn: do not use global variables because this function is called before
* reaching pre-main. RW section maybe overwritten afterwards. * reaching pre-main. RW section maybe overwritten afterwards.
*/ */
SystemCoreClock = SYSTEM_CLOCK; SystemCoreClock = SYSTEM_CLOCK;
@ -164,7 +156,6 @@ typedef void (*EXC_HANDLER)(unsigned long mcause, unsigned long sp);
*/ */
static void system_default_exception_handler(unsigned long mcause, unsigned long sp) static void system_default_exception_handler(unsigned long mcause, unsigned long sp)
{ {
/* TODO: Uncomment this if you have implement printf function */
printf("MCAUSE : 0x%lx\r\n", mcause); printf("MCAUSE : 0x%lx\r\n", mcause);
printf("MDCAUSE: 0x%lx\r\n", __RV_CSR_READ(CSR_MDCAUSE)); printf("MDCAUSE: 0x%lx\r\n", __RV_CSR_READ(CSR_MDCAUSE));
printf("MEPC : 0x%lx\r\n", __RV_CSR_READ(CSR_MEPC)); printf("MEPC : 0x%lx\r\n", __RV_CSR_READ(CSR_MEPC));
@ -276,7 +267,6 @@ void SystemBannerPrint(void)
void ECLIC_Init(void) void ECLIC_Init(void)
{ {
/* Global Configuration about MTH and NLBits. /* Global Configuration about MTH and NLBits.
* TODO: Please adapt it according to your system requirement.
* This function is called in _init function */ * This function is called in _init function */
ECLIC_SetMth(0); ECLIC_SetMth(0);
ECLIC_SetCfgNlbits(__ECLIC_INTCTLBITS); ECLIC_SetCfgNlbits(__ECLIC_INTCTLBITS);
@ -333,7 +323,6 @@ int32_t ECLIC_Register_IRQ(IRQn_Type IRQn, uint8_t shv, ECLIC_TRIGGER_Type trig_
*/ */
void _premain_init(void) void _premain_init(void)
{ {
/* TODO: Add your own initialization code here, called before main */
/* __ICACHE_PRESENT and __DCACHE_PRESENT are defined in demosoc.h */ /* __ICACHE_PRESENT and __DCACHE_PRESENT are defined in demosoc.h */
#if defined(__ICACHE_PRESENT) && __ICACHE_PRESENT == 1 #if defined(__ICACHE_PRESENT) && __ICACHE_PRESENT == 1
EnableICache(); EnableICache();
@ -363,7 +352,6 @@ void _premain_init(void)
*/ */
void _postmain_fini(int status) void _postmain_fini(int status)
{ {
/* TODO: Add your own finishing code here, called after main */
#ifdef SIMULATION_XLSPIKE #ifdef SIMULATION_XLSPIKE
extern void xlspike_exit(int status); extern void xlspike_exit(int status);
xlspike_exit(status); xlspike_exit(status);

View File

@ -80,7 +80,6 @@ uint32_t USBD_OTG_EP1OUT_ISR_Handler (usb_core_driver *udev)
{ {
oeplen = udev->regs.er_out[1]->DOEPLEN; oeplen = udev->regs.er_out[1]->DOEPLEN;
/* ToDo : handle more than one single MPS size packet */
udev->dev.transc_out[1].xfer_count = udev->dev.transc_out[1].usb_transc - \ udev->dev.transc_out[1].xfer_count = udev->dev.transc_out[1].usb_transc - \
oeplen & DEPLEN_TLEN; oeplen & DEPLEN_TLEN;
} }

View File

@ -169,7 +169,6 @@ exc_entry:
csrr a0, mcause csrr a0, mcause
mv a1, sp mv a1, sp
/* /*
* TODO: Call the exception handler function
* By default, the function template is provided in * By default, the function template is provided in
* system_Device.c, you can adjust it as you want * system_Device.c, you can adjust it as you want
*/ */

View File

@ -31,8 +31,6 @@
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
Define clocks Define clocks
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
/* ToDo: add here your necessary defines for device initialization
following is an example for different system frequencies */
#ifndef SYSTEM_CLOCK #ifndef SYSTEM_CLOCK
#define SYSTEM_CLOCK __SYSTEM_CLOCK_108M_PLL_HXTAL #define SYSTEM_CLOCK __SYSTEM_CLOCK_108M_PLL_HXTAL
#endif #endif
@ -66,9 +64,6 @@
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
System Core Clock Variable System Core Clock Variable
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
/* ToDo: initialize SystemCoreClock with the system core clock frequency value
achieved after system intitialization.
This means system core clock frequency after call to SystemInit() */
/** /**
* \brief Variable to hold the system core clock value * \brief Variable to hold the system core clock value
* \details * \details
@ -200,9 +195,7 @@ static void system_clock_config(void)
*/ */
void SystemCoreClockUpdate (void) /* Get Core Clock Frequency */ void SystemCoreClockUpdate (void) /* Get Core Clock Frequency */
{ {
/* ToDo: add code to calculate the system frequency based upon the current /* Note: This function can be used to retrieve the system core clock
* register settings.
* Note: This function can be used to retrieve the system core clock
* frequeny after user changed register settings. * frequeny after user changed register settings.
*/ */
uint32_t scss; uint32_t scss;
@ -288,8 +281,7 @@ void SystemCoreClockUpdate (void) /* Get Core Clock Frequency */
*/ */
void SystemInit (void) void SystemInit (void)
{ {
/* ToDo: add code to initialize the system /* Warn: do not use global variables because this function is called before
* Warn: do not use global variables because this function is called before
* reaching pre-main. RW section maybe overwritten afterwards. * reaching pre-main. RW section maybe overwritten afterwards.
*/ */
/* reset the RCC clock configuration to the default reset state */ /* reset the RCC clock configuration to the default reset state */
@ -359,7 +351,6 @@ typedef void (*EXC_HANDLER) (unsigned long mcause, unsigned long sp);
*/ */
static void system_default_exception_handler(unsigned long mcause, unsigned long sp) static void system_default_exception_handler(unsigned long mcause, unsigned long sp)
{ {
/* TODO: Uncomment this if you have implement printf function */
printf("MCAUSE: 0x%lx\r\n", mcause); printf("MCAUSE: 0x%lx\r\n", mcause);
printf("MEPC : 0x%lx\r\n", __RV_CSR_READ(CSR_MEPC)); printf("MEPC : 0x%lx\r\n", __RV_CSR_READ(CSR_MEPC));
printf("MTVAL : 0x%lx\r\n", __RV_CSR_READ(CSR_MBADADDR)); printf("MTVAL : 0x%lx\r\n", __RV_CSR_READ(CSR_MBADADDR));
@ -471,7 +462,6 @@ void SystemBannerPrint(void)
*/ */
void ECLIC_Init(void) void ECLIC_Init(void)
{ {
/* TODO: Add your own initialization code here. This function will be called by main */
ECLIC_SetMth(0); ECLIC_SetMth(0);
ECLIC_SetCfgNlbits(__ECLIC_INTCTLBITS); ECLIC_SetCfgNlbits(__ECLIC_INTCTLBITS);
} }
@ -527,7 +517,6 @@ int32_t ECLIC_Register_IRQ(IRQn_Type IRQn, uint8_t shv, ECLIC_TRIGGER_Type trig_
*/ */
void _premain_init(void) void _premain_init(void)
{ {
/* TODO: Add your own initialization code here, called before main */
SystemCoreClock = get_cpu_freq(); SystemCoreClock = get_cpu_freq();
/* configure USART */ /* configure USART */
gd_com_init(SOC_DEBUG_UART); gd_com_init(SOC_DEBUG_UART);
@ -550,7 +539,6 @@ void _premain_init(void)
*/ */
void _postmain_fini(int status) void _postmain_fini(int status)
{ {
/* TODO: Add your own finishing code here, called after main */
} }
/** /**

View File

@ -52,7 +52,6 @@ static UINT32 TestCase(VOID)
ICUNIT_GOTO_EQUAL(1, 0, 0, EXIT); ICUNIT_GOTO_EQUAL(1, 0, 0, EXIT);
} }
size = size;
p0 = LOS_MemAlloc(g_memPool, size); p0 = LOS_MemAlloc(g_memPool, size);
ICUNIT_GOTO_EQUAL(p0, NULL, p0, EXIT); ICUNIT_GOTO_EQUAL(p0, NULL, p0, EXIT);

View File

@ -33,20 +33,22 @@
#include "It_los_mem.h" #include "It_los_mem.h"
#if (LOSCFG_MEM_MUL_REGIONS == 1) #if (LOSCFG_MEM_MUL_REGIONS == 1)
#define TC_POOL_SIZE_1 0x200
#define TC_POOL_SIZE_2 0x400
#define TC_GAP_SIZE 0x10
// simulate two non-continuous memory regions // simulate two non-continuous memory regions
STATIC UINT8 g_memPool_TC46_01[0x200]; STATIC UINT8 g_memPool_TC46_01[TC_POOL_SIZE_1];
STATIC UINT8 g_memGap_TC46[0x10]; STATIC UINT8 g_memGap_TC46[TC_GAP_SIZE];
STATIC UINT8 g_memPool_TC46_02[0x400]; STATIC UINT8 g_memPool_TC46_02[TC_POOL_SIZE_2];
static UINT32 TestCase(VOID) static UINT32 TestCase(VOID)
{ {
UINT32 ret; UINT32 ret;
void *p = NULL; void *p = NULL;
LosMemRegion memRegions[] = LosMemRegion memRegions[] = {
{ {g_memPool_TC46_01, TC_POOL_SIZE_1},
{g_memPool_TC46_01, 0x200}, {g_memPool_TC46_02, TC_POOL_SIZE_2}
{g_memPool_TC46_02, 0x400}
}; };
// Initialize the LOS_MemRegionsAdd // Initialize the LOS_MemRegionsAdd
@ -56,8 +58,8 @@ static UINT32 TestCase(VOID)
} }
// p points to the start address of the gap node between g_memPool_TC46_01 and g_memPool_TC46_02 // p points to the start address of the gap node between g_memPool_TC46_01 and g_memPool_TC46_02
p = g_memPool_TC46_01 + 0x200; p = g_memPool_TC46_01 + TC_POOL_SIZE_1;
(void)memset_s(g_memGap_TC46, 0x10, 1, 0x10); (void)memset_s(g_memGap_TC46, TC_GAP_SIZE, 1, TC_GAP_SIZE);
ret = LOS_MemFree(m_aucSysMem0, p); ret = LOS_MemFree(m_aucSysMem0, p);
ICUNIT_GOTO_EQUAL(ret, LOS_NOK, ret, EXIT); ICUNIT_GOTO_EQUAL(ret, LOS_NOK, ret, EXIT);
@ -76,6 +78,3 @@ VOID ItLosMem046(void)
{ {
TEST_ADD_CASE("ItLosMem046", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION); TEST_ADD_CASE("ItLosMem046", TestCase, TEST_LOS, TEST_MEM, TEST_LEVEL1, TEST_FUNCTION);
} }

View File

@ -965,8 +965,7 @@ LITE_TEST_CASE(PthreadFuncTestSuite, testPthread016, Function | MediumTest | Lev
int ret; int ret;
pthread_mutexattr_init(&mutex_attr); pthread_mutexattr_init(&mutex_attr);
ret = pthread_mutexattr_settype(NULL, PTHREAD_MUTEX_ERRORCHECK); ret = pthread_mutexattr_settype(NULL, PTHREAD_MUTEX_ERRORCHECK);
if (ret == 0) if (ret == 0) {
{
ICUNIT_ASSERT_EQUAL(ret, 0, ret); ICUNIT_ASSERT_EQUAL(ret, 0, ret);
} }
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK); pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK);