Skip to content

Commit

Permalink
mm/zsmalloc: do not attempt to free IS_ERR handle
Browse files Browse the repository at this point in the history
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/[email protected]
Fixes: c7e6f17 ("zsmalloc: zs_malloc: return ERR_PTR on failure")
Signed-off-by: Sergey Senozhatsky <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Nitin Gupta <[email protected]>,
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
sergey-senozhatsky authored and akpm00 committed Aug 28, 2022
1 parent 44e602b commit a5d2172
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mm/zsmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ void zs_free(struct zs_pool *pool, unsigned long handle)
struct size_class *class;
enum fullness_group fullness;

if (unlikely(!handle))
if (IS_ERR_OR_NULL((void *)handle))
return;

/*
Expand Down

0 comments on commit a5d2172

Please sign in to comment.