From: Baoquan He <bhe@redhat.com>
To: Youngjun Park <youngjun.park@lge.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, Kemeng Shi <shikemeng@huaweicloud.com>,
Kairui Song <kasong@tencent.com>, Nhat Pham <nphamcs@gmail.com>,
Barry Song <baohua@kernel.org>, Chris Li <chrisl@kernel.org>
Subject: Re: [PATCH v2 1/5] mm, swap: Fix memory leak in setup_clusters() error path
Date: Sat, 1 Nov 2025 08:01:57 +0800 [thread overview]
Message-ID: <aQVN9WssAGUUPi7i@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20251031065011.40863-2-youngjun.park@lge.com>
On 10/31/25 at 03:50pm, Youngjun Park wrote:
> The setup_clusters() function could leak 'cluster_info' memory if an
> error occurred on a path that did not jump to the 'err_free' label.
>
> This patch simplifies the error handling by removing the goto label
> and instead calling free_cluster_info() on all error exit paths.
>
> The new logic is safe, as free_cluster_info() already handles NULL
> pointer inputs.
>
> Fixes: 07adc4cf1ecd ("mm, swap: implement dynamic allocation of swap table")
> Signed-off-by: Youngjun Park <youngjun.park@lge.com>
> Reviewed-by: Kairui Song <kasong@tencent.com>
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index c35bb8593f50..ed2c8e4edb71 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
LGTM,
Reviewed-by: Baoquan He <bhe@redhat.com>
> @@ -3324,7 +3324,7 @@ static struct swap_cluster_info *setup_clusters(struct swap_info_struct *si,
> si->global_cluster = kmalloc(sizeof(*si->global_cluster),
> GFP_KERNEL);
> if (!si->global_cluster)
> - goto err_free;
> + goto err;
> for (i = 0; i < SWAP_NR_ORDERS; i++)
> si->global_cluster->next[i] = SWAP_ENTRY_INVALID;
> spin_lock_init(&si->global_cluster_lock);
> @@ -3377,9 +3377,8 @@ static struct swap_cluster_info *setup_clusters(struct swap_info_struct *si,
> }
>
> return cluster_info;
> -err_free:
> - free_cluster_info(cluster_info, maxpages);
> err:
> + free_cluster_info(cluster_info, maxpages);
> return ERR_PTR(err);
> }
>
> --
> 2.34.1
>
next prev parent reply other threads:[~2025-11-01 0:02 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-31 6:50 [PATCH v2 0/5] mm: swap: small fixes and comment cleanups Youngjun Park
2025-10-31 6:50 ` [PATCH v2 1/5] mm, swap: Fix memory leak in setup_clusters() error path Youngjun Park
2025-11-01 0:01 ` Baoquan He [this message]
2025-11-05 4:30 ` Chris Li
2025-10-31 6:50 ` [PATCH v2 2/5] mm, swap: Use SWP_SOLIDSTATE to determine if swap is rotational Youngjun Park
2025-11-01 0:02 ` Baoquan He
2025-11-05 4:30 ` Chris Li
2025-10-31 6:50 ` [PATCH v2 3/5] mm, swap: Remove redundant comment for read_swap_cache_async Youngjun Park
2025-11-01 0:02 ` Baoquan He
2025-11-05 6:03 ` Chris Li
2025-11-05 7:58 ` Chris Li
2025-11-05 9:27 ` YoungJun Park
2025-11-06 0:29 ` Andrew Morton
2025-11-20 5:00 ` Chris Li
2025-11-20 16:54 ` Andrew Morton
2025-11-20 18:34 ` Chris Li
2025-10-31 6:50 ` [PATCH v2 4/5] mm: swap: change swap_alloc_slow() to void Youngjun Park
2025-11-01 0:03 ` Baoquan He
2025-11-05 6:04 ` Chris Li
2025-10-31 6:50 ` [PATCH v2 5/5] mm: swap: remove scan_swap_map_slots() references from comments Youngjun Park
2025-11-01 0:03 ` Baoquan He
2025-11-05 6:50 ` Chris Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aQVN9WssAGUUPi7i@MiWiFi-R3L-srv \
--to=bhe@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=chrisl@kernel.org \
--cc=kasong@tencent.com \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=shikemeng@huaweicloud.com \
--cc=youngjun.park@lge.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.