]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/zswap: fix error pointer free in zswap_cpu_comp_prepare()
authorPavel Butsykin <pbutsykin@cloudlinux.com>
Wed, 31 Dec 2025 07:46:38 +0000 (11:46 +0400)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 15 Jan 2026 06:16:24 +0000 (22:16 -0800)
crypto_alloc_acomp_node() may return ERR_PTR(), but the fail path checks
only for NULL and can pass an error pointer to crypto_free_acomp().  Use
IS_ERR_OR_NULL() to only free valid acomp instances.

Link: https://lkml.kernel.org/r/20251231074638.2564302-1-pbutsykin@cloudlinux.com
Fixes: 779b9955f643 ("mm: zswap: move allocations during CPU init outside the lock")
Signed-off-by: Pavel Butsykin <pbutsykin@cloudlinux.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Acked-by: Yosry Ahmed <yosry.ahmed@linux.dev>
Acked-by: Nhat Pham <nphamcs@gmail.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/zswap.c

index 5d0f8b13a958da3b5e74b63217b06e58ba2d3c26..ac9b7a60736bc668fb384009af35bf917ba9a734 100644 (file)
@@ -787,7 +787,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node)
        return 0;
 
 fail:
-       if (acomp)
+       if (!IS_ERR_OR_NULL(acomp))
                crypto_free_acomp(acomp);
        kfree(buffer);
        return ret;