sched_getparam.c: coverity HIS_metric_violation: RETURN

This change consolidates multiple return statements in nxsched_get_param()
into a single exit point and restructures the error handling path to reduce
cyclomatic complexity and comply with MISRA HIS coding standards.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2026-01-28 14:16:59 +08:00 committed by Donny(董九柱)
parent 7b1e9eb8bc
commit 9ae2fce3c1

View file

@ -77,70 +77,71 @@ int nxsched_get_param(pid_t pid, FAR struct sched_param *param)
if (param == NULL)
{
return -EINVAL;
ret = -EINVAL;
}
/* Check if the task to restart is the calling task */
rtcb = this_task();
if (pid == 0 || pid == rtcb->pid)
{
/* Return the priority if the calling task. */
param->sched_priority = (int)rtcb->sched_priority;
}
/* This PID is not for the calling task, we will have to look it up */
else
{
/* Get the TCB associated with this PID */
/* Check if the task to restart is the calling task */
flags = enter_critical_section();
tcb = nxsched_get_tcb(pid);
if (!tcb)
rtcb = this_task();
if (pid == 0 || pid == rtcb->pid)
{
/* This PID does not correspond to any known task */
/* Return the priority if the calling task. */
ret = -ESRCH;
param->sched_priority = (int)rtcb->sched_priority;
}
/* This PID is not for the calling task, we will have to look it up */
else
{
#ifdef CONFIG_SCHED_SPORADIC
#endif
/* Return the priority of the task */
/* Get the TCB associated with this PID */
param->sched_priority = (int)tcb->sched_priority;
#ifdef CONFIG_SCHED_SPORADIC
if ((tcb->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_SPORADIC)
flags = enter_critical_section();
tcb = nxsched_get_tcb(pid);
if (!tcb)
{
FAR struct sporadic_s *sporadic = tcb->sporadic;
DEBUGASSERT(sporadic != NULL);
/* This PID does not correspond to any known task */
/* Return parameters associated with SCHED_SPORADIC */
param->sched_ss_low_priority = (int)sporadic->low_priority;
param->sched_ss_max_repl = (int)sporadic->max_repl;
clock_ticks2time(&param->sched_ss_repl_period,
sporadic->repl_period);
clock_ticks2time(&param->sched_ss_init_budget,
sporadic->budget);
ret = -ESRCH;
}
else
{
param->sched_ss_low_priority = 0;
param->sched_ss_max_repl = 0;
param->sched_ss_repl_period.tv_sec = 0;
param->sched_ss_repl_period.tv_nsec = 0;
param->sched_ss_init_budget.tv_sec = 0;
param->sched_ss_init_budget.tv_nsec = 0;
}
#endif
}
/* Return the priority of the task */
leave_critical_section(flags);
param->sched_priority = (int)tcb->sched_priority;
#ifdef CONFIG_SCHED_SPORADIC
if ((tcb->flags & TCB_FLAG_POLICY_MASK) ==
TCB_FLAG_SCHED_SPORADIC)
{
FAR struct sporadic_s *sporadic = tcb->sporadic;
DEBUGASSERT(sporadic != NULL);
/* Return parameters associated with SCHED_SPORADIC */
param->sched_ss_low_priority = (int)sporadic->low_priority;
param->sched_ss_max_repl = (int)sporadic->max_repl;
clock_ticks2time(&param->sched_ss_repl_period,
sporadic->repl_period);
clock_ticks2time(&param->sched_ss_init_budget,
sporadic->budget);
}
else
{
param->sched_ss_low_priority = 0;
param->sched_ss_max_repl = 0;
param->sched_ss_repl_period.tv_sec = 0;
param->sched_ss_repl_period.tv_nsec = 0;
param->sched_ss_init_budget.tv_sec = 0;
param->sched_ss_init_budget.tv_nsec = 0;
}
#endif
}
leave_critical_section(flags);
}
}
return ret;