This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 7443a13bf9b sched/sched/sched_get_stackinfo.c: coverity
HIS_metric_violation: RETURN
7443a13bf9b is described below
commit 7443a13bf9ba7c14dd494b3bf0758ee1d71fc9a5
Author: hujun5 <[email protected]>
AuthorDate: Tue Jan 27 21:02:45 2026 +0800
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 <[email protected]>
---
sched/sched/sched_get_stackinfo.c | 80 ++++++++++++++++++++++-----------------
1 file changed, 45 insertions(+), 35 deletions(-)
diff --git a/sched/sched/sched_get_stackinfo.c
b/sched/sched/sched_get_stackinfo.c
index 00d8b9e37d2..a22698a6d83 100644
--- a/sched/sched/sched_get_stackinfo.c
+++ b/sched/sched/sched_get_stackinfo.c
@@ -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 */
- /* 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)
+ qtcb = rtcb;
+ }
+ 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;
}