From effdb88710d46d3d4f0b812efabcf8678b147c35 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Wed, 28 Jan 2026 17:07:34 +0800 Subject: [PATCH] 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 --- sched/sched/sched_getscheduler.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sched/sched/sched_getscheduler.c b/sched/sched/sched_getscheduler.c index c1fcd918012..379aaa4eaaf 100644 --- a/sched/sched/sched_getscheduler.c +++ b/sched/sched/sched_getscheduler.c @@ -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; } /****************************************************************************