Commit 50730227 authored by Hui Zhu's avatar Hui Zhu Committed by Jinjiang Tu
Browse files

zsmalloc: zs_malloc: return ERR_PTR on failure

mainline inclusion
from mainline-v6.0-rc1
commit c7e6f17b
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7TWVA
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=c7e6f17b52e9486a9d997368819dfec032b550e2

-------------------------------------------

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: default avatarHui 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: default avatarAndrew Morton <akpm@linux-foundation.org>

Conflicts:
	drivers/block/zram/zram_drv.c

Signed-off-by: default avatarJinjiang Tu <tujinjiang@huawei.com>
parent 369da114
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment