OSDN Git Service

zsmalloc: zs_malloc: return ERR_PTR on failure
authorHui Zhu <teawater@antgroup.com>
Thu, 14 Jul 2022 08:07:57 +0000 (16:07 +0800)
committerakpm <akpm@linux-foundation.org>
Sat, 30 Jul 2022 01:07:15 +0000 (18:07 -0700)
commitc7e6f17b52e9486a9d997368819dfec032b550e2
tree8a671ecdc4f7acb88558e20fd08e4a34f853484b
parentfef3e9066d19230f661048ca86937d954c12cd50
zsmalloc: zs_malloc: return ERR_PTR on failure

zs_malloc returns 0 if it fails.  zs_zpool_malloc will return -1 when
zs_malloc return 0.  But -1 makes the return value unclear.

For example, when zswap_frontswap_store calls zs_malloc through
zs_zpool_malloc, it will return -1 to its caller.  The other return value
is -EINVAL, -ENODEV or something else.

This commit changes zs_malloc to return ERR_PTR on failure.  It didn't
just let zs_zpool_malloc return -ENOMEM becaue zs_malloc has two types of
failure:

- size is not OK return -EINVAL
- memory alloc fail return -ENOMEM.

Link: https://lkml.kernel.org/r/20220714080757.12161-1-teawater@gmail.com
Signed-off-by: Hui Zhu <teawater@antgroup.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/block/zram/zram_drv.c
mm/zsmalloc.c