sem_rw.c: coverity HIS_metric_violation: RETURN

This change consolidates multiple return statements in down_write_trylock()
into a single exit point to reduce cyclomatic complexity and comply with MISRA
HIS coding standards for safety-critical embedded systems.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5
2025-08-13 20:15:02 +08:00
committed by Xiang Xiao
parent c63b0510fb
commit ceb23153c3
+12 -9
View File
@@ -205,23 +205,26 @@ out:
int down_write_trylock(FAR rw_semaphore_t *rwsem)
{
pid_t tid = _SCHED_GETTID();
int ret = 1;
nxmutex_lock(&rwsem->protected);
if (rwsem->reader > 0 || (rwsem->writer > 0 && tid != rwsem->holder))
{
nxmutex_unlock(&rwsem->protected);
return 0;
ret = 0;
}
else
{
/* The check passes, then we just need the writer reference + 1 */
rwsem->writer++;
rwsem->holder = tid;
nxmutex_unlock(&rwsem->protected);
}
/* The check passes, then we just need the writer reference + 1 */
rwsem->writer++;
rwsem->holder = tid;
nxmutex_unlock(&rwsem->protected);
return 1;
return ret;
}
/****************************************************************************