Skip to content

Commit a5d2172

Browse files
sergey-senozhatskyakpm00
authored andcommitted
mm/zsmalloc: do not attempt to free IS_ERR handle
zsmalloc() now returns ERR_PTR values as handles, which zram accidentally can pass to zs_free(). Another bad scenario is when zcomp_compress() fails - handle has default -ENOMEM value, and zs_free() will try to free that "pointer value". Add the missing check and make sure that zs_free() bails out when ERR_PTR() is passed to it. Link: https://lkml.kernel.org/r/20220816050906.2583956-1-senozhatsky@chromium.org Fixes: c7e6f17 ("zsmalloc: zs_malloc: return ERR_PTR on failure") Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Minchan Kim <minchan@kernel.org> Cc: Nitin Gupta <ngupta@vflare.org>, Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 44e602b commit a5d2172

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/zsmalloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ void zs_free(struct zs_pool *pool, unsigned long handle)
14871487
struct size_class *class;
14881488
enum fullness_group fullness;
14891489

1490-
if (unlikely(!handle))
1490+
if (IS_ERR_OR_NULL((void *)handle))
14911491
return;
14921492

14931493
/*

0 commit comments

Comments
 (0)