[HUST CSE IoTS&P Lab] [fix] check rt_mutex_create return value (#7169)

This commit is contained in:
Sparks-Pion 2023-04-04 12:33:10 +08:00 committed by GitHub
parent 3bee170d52
commit accab17fa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 3 deletions

View File

@ -664,6 +664,11 @@ int cmd_aduplex(int argc, char ** argv)
} }
duplex_priv.xMutex = rt_mutex_create("sound_mtx", RT_IPC_FLAG_PRIO); duplex_priv.xMutex = rt_mutex_create("sound_mtx", RT_IPC_FLAG_PRIO);
if(duplex_priv.xMutex == RT_NULL) {
printf("mutex create failed.\n");
goto err_create_mutex;
}
// ret = xTaskCreate(arecord_entry, (signed portCHAR *) "arecord-thread", // ret = xTaskCreate(arecord_entry, (signed portCHAR *) "arecord-thread",
// thread_size, &duplex_priv, priority, &pxCreatedTask); // thread_size, &duplex_priv, priority, &pxCreatedTask);
// if (!ret) { // if (!ret) {
@ -694,6 +699,7 @@ err_arecord_timeout:
// vTaskDelete(pxCreatedTask); // vTaskDelete(pxCreatedTask);
err_create_arecord: err_create_arecord:
err_format: err_format:
err_create_mutex:
err_in_filename_null: err_in_filename_null:
err_out_filename_null: err_out_filename_null:
err_cmd: err_cmd:

View File

@ -318,6 +318,7 @@ static int nu_fmc_init(void)
SYS_LockReg(); SYS_LockReg();
g_mutex_fmc = rt_mutex_create("nu_fmc_lock", RT_IPC_FLAG_PRIO); g_mutex_fmc = rt_mutex_create("nu_fmc_lock", RT_IPC_FLAG_PRIO);
RT_ASSERT(g_mutex_fmc != RT_NULL);
/* RT_USING_FAL */ /* RT_USING_FAL */
#if defined(RT_USING_FAL) #if defined(RT_USING_FAL)

View File

@ -315,6 +315,7 @@ static int nu_fmc_init(void)
SYS_LockReg(); SYS_LockReg();
g_mutex_fmc = rt_mutex_create("nu_fmc_lock", RT_IPC_FLAG_PRIO); g_mutex_fmc = rt_mutex_create("nu_fmc_lock", RT_IPC_FLAG_PRIO);
RT_ASSERT(g_mutex_fmc != RT_NULL);
/* RT_USING_FAL */ /* RT_USING_FAL */
#if defined(RT_USING_FAL) #if defined(RT_USING_FAL)

View File

@ -151,6 +151,12 @@ static int go_happy_mutex(void)
rt_thread_t thread; rt_thread_t thread;
rt_mutex_t sem = rt_mutex_create("mutexsem", RT_IPC_FLAG_PRIO); rt_mutex_t sem = rt_mutex_create("mutexsem", RT_IPC_FLAG_PRIO);
if(sem == RT_NULL)
{
rt_kprintf("create mutex failed");
return (int)-RT_ERROR;
}
thread = rt_thread_create("mutex0", happy_mutex, (void *)sem, 2048, 25, 20); thread = rt_thread_create("mutex0", happy_mutex, (void *)sem, 2048, 25, 20);
if (thread != RT_NULL) if (thread != RT_NULL)
{ {

View File

@ -1126,7 +1126,19 @@ static int n_tty_open(struct dfs_fd *fd)
} }
ldata->atomic_read_lock = rt_mutex_create("atomic_read_lock",RT_IPC_FLAG_FIFO); ldata->atomic_read_lock = rt_mutex_create("atomic_read_lock",RT_IPC_FLAG_FIFO);
if(ldata->atomic_read_lock == RT_NULL)
{
LOG_E("n_tty_open atomic_read_lock create fail");
return -1;
}
ldata->output_lock = rt_mutex_create("output_lock",RT_IPC_FLAG_FIFO); ldata->output_lock = rt_mutex_create("output_lock",RT_IPC_FLAG_FIFO);
if(ldata->output_lock == RT_NULL)
{
LOG_E("n_tty_open output_lock create fail");
return -1;
}
tty->disc_data = ldata; tty->disc_data = ldata;
reset_buffer_flags(ldata); reset_buffer_flags(ldata);
ldata->column = 0; ldata->column = 0;

View File

@ -1016,6 +1016,8 @@ rt_err_t sys_sem_release(rt_sem_t sem)
rt_mutex_t sys_mutex_create(const char *name, rt_uint8_t flag) rt_mutex_t sys_mutex_create(const char *name, rt_uint8_t flag)
{ {
rt_mutex_t mutex = rt_mutex_create(name, flag); rt_mutex_t mutex = rt_mutex_create(name, flag);
if(mutex == NULL)
return NULL;
if (lwp_user_object_add(lwp_self(), (rt_object_t)mutex) != 0) if (lwp_user_object_add(lwp_self(), (rt_object_t)mutex) != 0)
{ {
rt_mutex_delete(mutex); rt_mutex_delete(mutex);