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>
Change-Id: Ieca31cf486d519cde67c28279b815df894ec468b
This commit is contained in:
Xiang Xiao
2021-10-17 14:20:07 +08:00
committed by xiaoxiang
parent ece151f20d
commit 1fb1a77214
+9 -7
View File
@@ -56,9 +56,13 @@ FAR struct tcb_s *nxsched_get_tcb(pid_t pid)
irqstate_t flags;
int hash_ndx;
/* Verify that the PID is within range */
flags = enter_critical_section();
if (pid >= 0)
/* Verify whether g_pidhash hash table has already been allocated and
* whether the PID is within range.
*/
if (g_pidhash != NULL && pid >= 0)
{
/* The test and the return setup should be atomic. This still does
* not provide proper protection if the recipient of the TCB does not
@@ -66,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;