sched/clock Add special handling for TCB null pointer cases

Adding a judgment in the code that null return values are not referenced for dereference

Signed-off-by: zhuanglin <zhuanglin@xiaomi.com>
This commit is contained in:
zhuanglin
2023-09-19 14:22:11 +08:00
committed by Xiang Xiao
parent 2db471fab3
commit 13ee3f8117
+17
View File
@@ -153,8 +153,15 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
tcb = nxsched_get_tcb(pid); tcb = nxsched_get_tcb(pid);
} }
if (tcb != NULL)
{
up_perf_convert(tcb->run_time, tp); up_perf_convert(tcb->run_time, tp);
} }
else
{
ret = -EFAULT;
}
}
else if (clock_type == CLOCK_PROCESS_CPUTIME_ID) else if (clock_type == CLOCK_PROCESS_CPUTIME_ID)
{ {
FAR struct task_group_s *group; FAR struct task_group_s *group;
@@ -174,6 +181,8 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
tcb = nxsched_get_tcb(pid); tcb = nxsched_get_tcb(pid);
} }
if (tcb != NULL)
{
group = tcb->group; group = tcb->group;
runtime = 0; runtime = 0;
@@ -181,12 +190,20 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
for (i = group->tg_nmembers - 1; i >= 0; i--) for (i = group->tg_nmembers - 1; i >= 0; i--)
{ {
tcb = nxsched_get_tcb(group->tg_members[i]); tcb = nxsched_get_tcb(group->tg_members[i]);
if (tcb != NULL)
{
runtime += tcb->run_time; runtime += tcb->run_time;
} }
}
leave_critical_section(flags); leave_critical_section(flags);
up_perf_convert(runtime, tp); up_perf_convert(runtime, tp);
} }
else
{
ret = -EFAULT;
}
}
#endif #endif
else else
{ {