Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: zswap: remove redundant checks in zswap_cpu_comp_dead()

Patch series "zswap pool per-CPU acomp_ctx simplifications", v3.

This patchset first removes redundant checks on the acomp_ctx and its
"req" member in zswap_cpu_comp_dead().

Next, it persists the zswap pool's per-CPU acomp_ctx resources to last
until the pool is destroyed. It then simplifies the per-CPU acomp_ctx
mutex locking in zswap_compress()/zswap_decompress().

Code comments added after allocation and before checking to deallocate the
per-CPU acomp_ctx's members, based on expected crypto API return values
and zswap changes this patchset makes.

Patch 2 is an independent submission of patch 23 from [1], to
facilitate merging.


This patch (of 2):

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.

Link: https://lore.kernel.org/20260331183351.29844-2-kanchanapsridhar2026@gmail.com
Link: https://patchwork.kernel.org/project/linux-mm/list/?series=1046677
Signed-off-by: Kanchana P. Sridhar <kanchanapsridhar2026@gmail.com>
Suggested-by: Yosry Ahmed <yosry@kernel.org>
Acked-by: Yosry Ahmed <yosry@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kanchana P. Sridhar and committed by
Andrew Morton
1556478e 6b184277

+10 -2
+10 -2
mm/zswap.c
··· 749 749 goto fail; 750 750 } 751 751 752 + /* 753 + * In case of an error, crypto_alloc_acomp_node() returns an 754 + * error pointer, never NULL. 755 + */ 752 756 acomp = crypto_alloc_acomp_node(pool->tfm_name, 0, 0, cpu_to_node(cpu)); 753 757 if (IS_ERR(acomp)) { 754 758 pr_err("could not alloc crypto acomp %s : %pe\n", ··· 761 757 goto fail; 762 758 } 763 759 760 + /* acomp_request_alloc() returns NULL in case of an error. */ 764 761 req = acomp_request_alloc(acomp); 765 762 if (!req) { 766 763 pr_err("could not alloc crypto acomp_request %s\n", ··· 807 802 struct crypto_acomp *acomp; 808 803 u8 *buffer; 809 804 810 - if (IS_ERR_OR_NULL(acomp_ctx)) 805 + if (!acomp_ctx) 811 806 return 0; 812 807 813 808 mutex_lock(&acomp_ctx->mutex); ··· 822 817 /* 823 818 * Do the actual freeing after releasing the mutex to avoid subtle 824 819 * locking dependencies causing deadlocks. 820 + * 821 + * If there was an error in allocating @acomp_ctx->req, it 822 + * would be set to NULL. 825 823 */ 826 - if (!IS_ERR_OR_NULL(req)) 824 + if (req) 827 825 acomp_request_free(req); 828 826 if (!IS_ERR_OR_NULL(acomp)) 829 827 crypto_free_acomp(acomp);