sched_getscheduler.c: coverity HIS_metric_violation: RETURN

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

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2026-01-28 17:07:34 +08:00 committed by Alan C. Assis
parent a4d09a4e25
commit effdb88710

View file

@ -71,6 +71,7 @@
int nxsched_get_scheduler(pid_t pid)
{
FAR struct tcb_s *tcb;
int ret = -ESRCH;
int policy;
/* Verify that the PID corresponds to a real task */
@ -84,17 +85,18 @@ int nxsched_get_scheduler(pid_t pid)
tcb = nxsched_get_tcb(pid);
}
if (tcb == NULL)
if (tcb != NULL)
{
return -ESRCH;
/* Return the scheduling policy from the TCB. NOTE that the user-
* interpretable values are 1 based; the TCB values are zero-based.
*/
policy = (tcb->flags & TCB_FLAG_POLICY_MASK) >> TCB_FLAG_POLICY_SHIFT;
ret = policy + 1;
}
/* Return the scheduling policy from the TCB. NOTE that the user-
* interpretable values are 1 based; the TCB values are zero-based.
*/
policy = (tcb->flags & TCB_FLAG_POLICY_MASK) >> TCB_FLAG_POLICY_SHIFT;
return policy + 1;
return ret;
}
/****************************************************************************