Re: [PATCH v2 07/11] zswap: do not free the entry if its pool is NULL

From: Yosry Ahmed

Date: Tue Nov 10 2026 - 11:52:31 EST


On Tue, Nov 10, 2026 at 02:48:12PM +0900, Sergey Senozhatsky wrote:
> zswap_entry_free() warns if the entry has no pool (which should never
> happen), skips zs_free() and then frees the entry. A subsequent patch
> embeds zsmalloc handle into zswap_entry, so zsmalloc object will point
> to the entry, and we cannot free the entry while the object is still
> there.
>
> Bail out early and leak the entry, its cgroup charge and stats instead.
>
> Suggested-by: Yosry Ahmed <yosry@xxxxxxxxxx>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>

Acked-by: Yosry Ahmed <yosry@xxxxxxxxxx>

> ---
> mm/zswap.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/mm/zswap.c b/mm/zswap.c
> index 1160bd34e289..dc0400d7e1a3 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -787,10 +787,11 @@ static void zswap_entry_free(struct zswap_entry *entry)
> struct zswap_pool *pool = zswap_entry_pool(entry);
>
> zswap_lru_del(entry);
> - if (!WARN_ON_ONCE(!pool)) {
> - zs_free(pool->zs_pool, entry->handle);
> - zswap_pool_put(pool);
> - }
> + if (WARN_ON_ONCE(!pool))
> + return;
> +
> + zs_free(pool->zs_pool, entry->handle);
> + zswap_pool_put(pool);
> if (entry->objcg) {
> obj_cgroup_uncharge_zswap(entry->objcg, entry->length);
> obj_cgroup_put(entry->objcg);
> --
> 2.56.0.506.g506a7eabc5-goog
>