sched: Check g_pidhash[hash_ndx] isn't NULL before access pid field in nxsched_get_tcb

Fix the regression by commit:
commit 8b67944c75
Author: Xiang Xiao <xiaoxiang@xiaomi.com>
Date:   Thu Oct 14 11:03:07 2021 +0800

    sched: Remove pidhash_s and move ticks to tcb_s

    simplify the code logic and reduce memory a little bit

    Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2021-10-17 14:20:07 +08:00 committed by Masayuki Ishikawa
parent 7b43d11435
commit 4a7915e72b

View File

@ -56,6 +56,8 @@ FAR struct tcb_s *nxsched_get_tcb(pid_t pid)
irqstate_t flags;
int hash_ndx;
flags = enter_critical_section();
/* Verify whether g_pidhash hash table has already been allocated and
* whether the PID is within range.
*/
@ -68,24 +70,22 @@ FAR struct tcb_s *nxsched_get_tcb(pid_t pid)
* terminating asynchronously.
*/
flags = enter_critical_section();
/* Get the hash_ndx associated with the pid */
hash_ndx = PIDHASH(pid);
/* Verify that the correct TCB was found. */
if (g_pidhash && pid == g_pidhash[hash_ndx]->pid)
if (g_pidhash[hash_ndx] != NULL && pid == g_pidhash[hash_ndx]->pid)
{
/* Return the TCB associated with this pid (if any) */
ret = g_pidhash[hash_ndx];
}
leave_critical_section(flags);
}
leave_critical_section(flags);
/* Return the TCB. */
return ret;