diff --git a/mm/share_pool.c b/mm/share_pool.c
index e9d2ae0a5352d6d03399161fa43f2972231c440b..ababe279c44d3de97778cffa0ecc3fa0aa7ab6f3 100644
--- a/mm/share_pool.c
+++ b/mm/share_pool.c
@@ -487,8 +487,8 @@ static int init_local_group(struct mm_struct *mm)
 
 	spg = create_spg(spg_id, 0);
 	if (IS_ERR(spg)) {
-		ret = PTR_ERR(spg);
-		goto free_spg_id;
+		free_new_spg_id(true, spg_id);
+		return PTR_ERR(spg);
 	}
 
 	master->local = spg;
@@ -509,11 +509,9 @@ static int init_local_group(struct mm_struct *mm)
 	return 0;
 
 free_spg:
+	/* spg_id is freed in free_sp_group_locked */
 	free_sp_group_locked(spg);
 	master->local = NULL;
-free_spg_id:
-	free_new_spg_id(true, spg_id);
-
 	return ret;
 }