From 26104c34938685633266ba98306396208200b867 Mon Sep 17 00:00:00 2001 From: Tang Yizhou Date: Sat, 30 Oct 2021 11:09:55 +0800 Subject: [PATCH] share_pool: Free newly generated id when failed ascend inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4EUVI CVE: NA ------------------------------------------------- Free id at the end of sp_group_add_task when failed. Benefits are below: 1. Less time to hold locks. 2. Avoid to forget freeing id in other error handling branches. Signed-off-by: Tang Yizhou Reviewed-by: Ding Tianhong Reviewed-by: Weilong Chen Signed-off-by: Yang Yingliang --- mm/share_pool.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/mm/share_pool.c b/mm/share_pool.c index 607a5f0097a4..6a4da9ac83e1 100644 --- a/mm/share_pool.c +++ b/mm/share_pool.c @@ -664,10 +664,8 @@ int sp_group_add_task(int pid, int spg_id) rcu_read_unlock(); if (ret) { - if (id_newly_generated) - free_sp_group_id((unsigned int)spg_id); up_write(&sp_group_sem); - goto out_unlock; + goto out_free_id; } /* @@ -695,10 +693,8 @@ int sp_group_add_task(int pid, int spg_id) spg = find_or_alloc_sp_group(spg_id); if (IS_ERR(spg)) { - ret = PTR_ERR(spg); - if (id_newly_generated) - free_sp_group_id((unsigned int)spg_id); up_write(&sp_group_sem); + ret = PTR_ERR(spg); goto out_put_mm; } @@ -817,7 +813,9 @@ int sp_group_add_task(int pid, int spg_id) mmput(mm); out_put_task: put_task_struct(tsk); -out_unlock: +out_free_id: + if (unlikely(ret) && id_newly_generated) + free_sp_group_id((unsigned int)spg_id); return ret == 0 ? spg_id : ret; } EXPORT_SYMBOL_GPL(sp_group_add_task); -- GitLab