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
commit 31901573bafe4f4235ed18447528f6188c4e51aa Author: fangxinyong <[email protected]> AuthorDate: Fri Aug 15 11:19:56 2025 +0800 sched/task: task_spawnparms return path cleanup Initialize ret and propagate scheduler/param errors via a single return. Make spawn_file_is_duplicateable() decision explicit using a dup state. Addresses Coverity HIS_metric_violation: RETURN. Signed-off-by: fangxinyong <[email protected]> --- sched/task/task_spawnparms.c | 56 +++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/sched/task/task_spawnparms.c b/sched/task/task_spawnparms.c index b79fc460198..cc0cb5a2154 100644 --- a/sched/task/task_spawnparms.c +++ b/sched/task/task_spawnparms.c @@ -146,7 +146,7 @@ static inline int nxspawn_open(FAR struct tcb_s *tcb, int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr) { struct sched_param param; - int ret; + int ret = OK; DEBUGASSERT(attr); @@ -180,29 +180,24 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr) */ ret = nxsched_get_param(pid, ¶m); - if (ret < 0) - { - return ret; - } #endif - /* Get the priority from the attributes */ + if (ret == OK) + { + /* Get the priority from the attributes */ - param.sched_priority = attr->priority; + param.sched_priority = attr->priority; - /* If we are setting *both* the priority and the scheduler, - * then we will call nxsched_set_scheduler() below. - */ + /* If we are setting *both* the priority and the scheduler, + * then we will call nxsched_set_scheduler() below. + */ - if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) == 0) - { - sinfo("Setting priority=%d for pid=%d\n", - param.sched_priority, pid); - - ret = nxsched_set_param(pid, ¶m); - if (ret < 0) + if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) == 0) { - return ret; + sinfo("Setting priority=%d for pid=%d\n", + param.sched_priority, pid); + + ret = nxsched_set_param(pid, ¶m); } } } @@ -215,17 +210,13 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr) else if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) != 0) { ret = nxsched_get_param(0, ¶m); - if (ret < 0) - { - return ret; - } } /* Are we setting the scheduling policy? If so, use the priority * setting determined above. */ - if ((attr->flags & POSIX_SPAWN_SETSCHEDULER) != 0) + if (ret == OK && (attr->flags & POSIX_SPAWN_SETSCHEDULER) != 0) { sinfo("Setting policy=%d priority=%d for pid=%d\n", attr->policy, param.sched_priority, pid); @@ -243,7 +234,7 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr) nxsched_set_scheduler(pid, attr->policy, ¶m); } - return OK; + return ret; } /**************************************************************************** @@ -328,11 +319,12 @@ spawn_file_is_duplicateable(FAR const posix_spawn_file_actions_t *actions, FAR struct spawn_close_file_action_s *close; FAR struct spawn_open_file_action_s *open; FAR struct spawn_dup2_file_action_s *dup2; + int dup = -1; /* check each file action */ for (entry = (FAR struct spawn_general_file_action_s *)actions; - entry != NULL; + entry != NULL && dup < 0; entry = entry->flink) { switch (entry->action) @@ -341,7 +333,7 @@ spawn_file_is_duplicateable(FAR const posix_spawn_file_actions_t *actions, close = (FAR struct spawn_close_file_action_s *)entry; if (close->fd == fd) { - return false; + dup = 0; } break; @@ -349,11 +341,11 @@ spawn_file_is_duplicateable(FAR const posix_spawn_file_actions_t *actions, dup2 = (FAR struct spawn_dup2_file_action_s *)entry; if (dup2->fd1 == fd) { - return true; + dup = 1; } else if (dup2->fd2 == fd) { - return false; + dup = 0; } break; @@ -361,7 +353,7 @@ spawn_file_is_duplicateable(FAR const posix_spawn_file_actions_t *actions, open = (FAR struct spawn_open_file_action_s *)entry; if (open->fd == fd) { - return false; + dup = 0; } break; @@ -370,10 +362,10 @@ spawn_file_is_duplicateable(FAR const posix_spawn_file_actions_t *actions, } } - if (cloexec) + if (dup < 0) { - return false; + dup = cloexec ? 0 : 1; } - return true; + return dup > 0; }
