sem_waitirq.c: coverity HIS_metric_violation: RETURN

Refactor nxsem_wait_irq() to consolidate multiple return statements into a single
exit point by inverting the mutex condition check. This improves code maintainability
and resolves Coverity HIS_metric_violation defect for better compliance with MISRA HIS standards.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5
2026-01-28 15:37:26 +08:00
committed by GUIDINGLI
parent afaaa7b8cb
commit 3a214b5808
+28 -30
View File
@@ -84,47 +84,45 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
/* Mutex is never interrupted by a signal or canceled */
if (mutex && (errcode == EINTR || errcode == ECANCELED))
if (!(mutex && (errcode == EINTR || errcode == ECANCELED)))
{
return;
}
/* Restore the correct priority of all threads that hold references
* to this semaphore.
*/
/* Restore the correct priority of all threads that hold references
* to this semaphore.
*/
nxsem_canceled(wtcb, sem);
nxsem_canceled(wtcb, sem);
/* Remove task from waiting list */
/* Remove task from waiting list */
dq_rem((FAR dq_entry_t *)wtcb, SEM_WAITLIST(sem));
dq_rem((FAR dq_entry_t *)wtcb, SEM_WAITLIST(sem));
/* This restores the value to what it was before the previous sem_wait.
* This caused the thread to be blocked in the first place.
*
* For mutexes, the holder is updated by the thread itself
* when it exits nxsem_wait
*/
/* This restores the value to what it was before the previous sem_wait.
* This caused the thread to be blocked in the first place.
*
* For mutexes, the holder is updated by the thread itself
* when it exits nxsem_wait
*/
if (!mutex)
{
atomic_fetch_add(NXSEM_COUNT(sem), 1);
}
if (!mutex)
{
atomic_fetch_add(NXSEM_COUNT(sem), 1);
}
/* Indicate that the wait is over. */
/* Indicate that the wait is over. */
wtcb->waitobj = NULL;
wtcb->waitobj = NULL;
/* Mark the errno value for the thread. */
/* Mark the errno value for the thread. */
wtcb->errcode = errcode;
wtcb->errcode = errcode;
/* Add the task to ready-to-run task list and
* perform the context switch if one is needed
*/
/* Add the task to ready-to-run task list and
* perform the context switch if one is needed
*/
if (nxsched_add_readytorun(wtcb))
{
up_switch_context(this_task(), rtcb);
if (nxsched_add_readytorun(wtcb))
{
up_switch_context(this_task(), rtcb);
}
}
}