From dfd1e38b40b394ae2882d9a9c1b3c0b4d934d5be Mon Sep 17 00:00:00 2001 From: chao an Date: Tue, 5 Mar 2024 10:39:27 +0800 Subject: [PATCH] sched/environ: check envcp validity before hold sched_lock() check envcp validity before hold sched_lock() to avoid unnecessary schedule lock Signed-off-by: chao an --- sched/environ/env_dup.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sched/environ/env_dup.c b/sched/environ/env_dup.c index 3e3be281e8..8ab1ea38e6 100644 --- a/sched/environ/env_dup.c +++ b/sched/environ/env_dup.c @@ -70,16 +70,16 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp) DEBUGASSERT(group != NULL); - /* Pre-emption must be disabled throughout the following because the - * environment may be shared. - */ - - sched_lock(); - /* Is there an environment ? */ if (envcp != NULL) { + /* Pre-emption must be disabled throughout the following because the + * environment may be shared. + */ + + sched_lock(); + /* Count the strings */ while (envcp[envc] != NULL) @@ -138,9 +138,10 @@ int env_dup(FAR struct task_group_s *group, FAR char * const *envcp) /* Save the child environment allocation. */ group->tg_envp = envp; + + sched_unlock(); } - sched_unlock(); return ret; }