From: "Kanchana P. Sridhar" <kanchanapsridhar2026@gmail.com>
To: hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com,
chengming.zhou@linux.dev, akpm@linux-foundation.org,
kanchanapsridhar2026@gmail.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Cc: herbert@gondor.apana.org.au, senozhatsky@chromium.org
Subject: [PATCH v2 1/2] mm: zswap: Remove redundant checks in zswap_cpu_comp_dead().
Date: Mon, 16 Mar 2026 18:48:01 -0700 [thread overview]
Message-ID: <20260317014802.27591-2-kanchanapsridhar2026@gmail.com> (raw)
In-Reply-To: <20260317014802.27591-1-kanchanapsridhar2026@gmail.com>
There are presently redundant checks on the per-CPU acomp_ctx and it's
"req" member in zswap_cpu_comp_dead(): redundant because they are
inconsistent with zswap_pool_create() handling of failure in allocating
the acomp_ctx, and with the expected NULL return value from the
acomp_request_alloc() API when it fails to allocate an acomp_req.
Fix these by converting to them to be NULL checks.
Add comments in zswap_cpu_comp_prepare() clarifying the expected return
values of the crypto_alloc_acomp_node() and acomp_request_alloc() API.
Suggested-by: Yosry Ahmed <yosry@kernel.org>
Signed-off-by: Kanchana P. Sridhar <kanchanapsridhar2026@gmail.com>
---
mm/zswap.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/mm/zswap.c b/mm/zswap.c
index bdd24430f6ff..8ac38f1d0469 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -749,6 +749,10 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node)
goto fail;
}
+ /*
+ * In case of an error, crypto_alloc_acomp_node() returns an
+ * error pointer, never NULL.
+ */
acomp = crypto_alloc_acomp_node(pool->tfm_name, 0, 0, cpu_to_node(cpu));
if (IS_ERR(acomp)) {
pr_err("could not alloc crypto acomp %s : %pe\n",
@@ -757,6 +761,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node)
goto fail;
}
+ /* acomp_request_alloc() returns NULL in case of an error. */
req = acomp_request_alloc(acomp);
if (!req) {
pr_err("could not alloc crypto acomp_request %s\n",
@@ -802,7 +807,7 @@ static int zswap_cpu_comp_dead(unsigned int cpu, struct hlist_node *node)
struct crypto_acomp *acomp;
u8 *buffer;
- if (IS_ERR_OR_NULL(acomp_ctx))
+ if (!acomp_ctx)
return 0;
mutex_lock(&acomp_ctx->mutex);
@@ -817,8 +822,11 @@ static int zswap_cpu_comp_dead(unsigned int cpu, struct hlist_node *node)
/*
* Do the actual freeing after releasing the mutex to avoid subtle
* locking dependencies causing deadlocks.
+ *
+ * If there was an error in allocating @acomp_ctx->req, it
+ * would be set to NULL.
*/
- if (!IS_ERR_OR_NULL(req))
+ if (req)
acomp_request_free(req);
if (!IS_ERR_OR_NULL(acomp))
crypto_free_acomp(acomp);
--
2.39.5
next prev parent reply other threads:[~2026-03-17 1:48 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 1:48 [PATCH v2 0/2] zswap pool per-CPU acomp_ctx simplifications Kanchana P. Sridhar
2026-03-17 1:48 ` Kanchana P. Sridhar [this message]
2026-03-17 19:19 ` [PATCH v2 1/2] mm: zswap: Remove redundant checks in zswap_cpu_comp_dead() Yosry Ahmed
2026-03-17 21:09 ` Kanchana P. Sridhar
2026-03-17 1:48 ` [PATCH v2 2/2] mm: zswap: Tie per-CPU acomp_ctx lifetime to the pool Kanchana P. Sridhar
2026-03-27 2:23 ` Andrew Morton
2026-03-27 19:30 ` Kanchana P. Sridhar
2026-03-30 18:32 ` Yosry Ahmed
2026-03-30 18:51 ` Andrew Morton
2026-03-30 18:52 ` Yosry Ahmed
2026-03-30 18:59 ` Kanchana P. Sridhar
2026-03-30 19:12 ` Andrew Morton
2026-03-30 19:13 ` Yosry Ahmed
2026-03-30 21:53 ` Kanchana P. Sridhar
2026-03-30 21:47 ` Kanchana P. Sridhar
2026-03-17 19:45 ` [PATCH v2 0/2] zswap pool per-CPU acomp_ctx simplifications Andrew Morton
2026-03-17 19:48 ` Yosry Ahmed
2026-03-17 21:15 ` Kanchana P. Sridhar
2026-03-17 21:21 ` Kanchana P. Sridhar
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=20260317014802.27591-2-kanchanapsridhar2026@gmail.com \
--to=kanchanapsridhar2026@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=hannes@cmpxchg.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=senozhatsky@chromium.org \
--cc=yosry@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox