sched/sched/sched_get_stackinfo.c: coverity HIS_metric_violation: RETURN

Consolidate multiple return statements in sched_get_stackinfo() to comply
with MISRA HIS coding standards for safety-critical systems. This refactoring
maintains functional equivalence while improving code verifiability and
reducing cyclomatic complexity for better maintainability.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5
2026-01-27 21:02:45 +08:00
committed by Xiang Xiao
parent e2aec529cb
commit 7443a13bf9
+45 -35
View File
@@ -60,54 +60,64 @@ int nxsched_get_stackinfo(pid_t pid, FAR struct stackinfo_s *stackinfo)
{
FAR struct tcb_s *rtcb = this_task(); /* TCB of running task */
FAR struct tcb_s *qtcb; /* TCB of queried task */
int ret = OK;
DEBUGASSERT(stackinfo != NULL);
if (rtcb == NULL)
if (rtcb != NULL)
{
return -ENOENT;
}
/* Pid of 0 means that we are querying ourself */
/* Pid of 0 means that we are querying ourself */
if (pid == 0)
{
/* We can always query ourself */
qtcb = rtcb;
}
else
{
/* Get the task to be queried */
qtcb = nxsched_get_tcb(pid);
if (qtcb == NULL)
if (pid == 0)
{
return -ENOENT;
/* We can always query ourself */
qtcb = rtcb;
}
/* A kernel thread can query any other thread. Application threads
* can only query application threads in the same task group.
*/
if ((rtcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL)
else
{
/* It is an application thread. It is permitted to query
* only threads within the same task group. It is not permitted
* to peek into the stacks of either kernel threads or other
* applications tasks.
*/
/* Get the task to be queried */
if (rtcb->group != qtcb->group)
qtcb = nxsched_get_tcb(pid);
if (qtcb != NULL)
{
return -EACCES;
/* A kernel thread can query any other thread.
* Application threads can only query application
* threads in the same task group.
*/
if ((rtcb->flags & TCB_FLAG_TTYPE_MASK) !=
TCB_FLAG_TTYPE_KERNEL)
{
/* It is an application thread. It is permitted to query
* only threads within the same task group. It is not
* permitted to peek into the stacks of either kernel
* threads or other applications tasks.
*/
if (rtcb->group != qtcb->group)
{
ret = -EACCES;
}
}
}
else
{
ret = -ENOENT;
}
}
}
else
{
ret = -ENOENT;
}
stackinfo->adj_stack_size = qtcb->adj_stack_size;
stackinfo->stack_alloc_ptr = qtcb->stack_alloc_ptr;
stackinfo->stack_base_ptr = qtcb->stack_base_ptr;
if (ret >= 0)
{
stackinfo->adj_stack_size = qtcb->adj_stack_size;
stackinfo->stack_alloc_ptr = qtcb->stack_alloc_ptr;
stackinfo->stack_base_ptr = qtcb->stack_base_ptr;
}
return OK;
return ret;
}