[PATCH v3 07/11] zswap: do not free the entry if its pool is NULL
From: Sergey Senozhatsky
Date: Wed Nov 11 2026 - 02:01:12 EST
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>
Acked-by: Yosry Ahmed <yosry@xxxxxxxxxx>
Acked-by: Nhat Pham <nphamcs@xxxxxxxxx>
Signed-off-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>
---
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.542.g3ef89b7020-goog