mirror of
https://github.com/apache/nuttx.git
synced 2026-10-11 16:20:21 +00:00
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:
parent
2db471fab3
commit
13ee3f8117
1 changed files with 28 additions and 11 deletions
|
|
@ -153,7 +153,14 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
|
|||
tcb = nxsched_get_tcb(pid);
|
||||
}
|
||||
|
||||
up_perf_convert(tcb->run_time, tp);
|
||||
if (tcb != NULL)
|
||||
{
|
||||
up_perf_convert(tcb->run_time, tp);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -EFAULT;
|
||||
}
|
||||
}
|
||||
else if (clock_type == CLOCK_PROCESS_CPUTIME_ID)
|
||||
{
|
||||
|
|
@ -174,18 +181,28 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
|
|||
tcb = nxsched_get_tcb(pid);
|
||||
}
|
||||
|
||||
group = tcb->group;
|
||||
runtime = 0;
|
||||
|
||||
flags = enter_critical_section();
|
||||
for (i = group->tg_nmembers - 1; i >= 0; i--)
|
||||
if (tcb != NULL)
|
||||
{
|
||||
tcb = nxsched_get_tcb(group->tg_members[i]);
|
||||
runtime += tcb->run_time;
|
||||
}
|
||||
group = tcb->group;
|
||||
runtime = 0;
|
||||
|
||||
leave_critical_section(flags);
|
||||
up_perf_convert(runtime, tp);
|
||||
flags = enter_critical_section();
|
||||
for (i = group->tg_nmembers - 1; i >= 0; i--)
|
||||
{
|
||||
tcb = nxsched_get_tcb(group->tg_members[i]);
|
||||
if (tcb != NULL)
|
||||
{
|
||||
runtime += tcb->run_time;
|
||||
}
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
up_perf_convert(runtime, tp);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -EFAULT;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue