2024-02-07 06:58:25

by Sergey Senozhatsky

[permalink] [raw]
Subject: [RFC][PATCH 1/2] zram: do not allocate buffer if crypto comp allocation failed

Do not allocate working buffer if we failed to lookup and
alloc crypto comp. User-space can request unsupported
compression algorithm.

Signed-off-by: Sergey Senozhatsky <[email protected]>
---
drivers/block/zram/zcomp.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index 8237b08c49d8..d88954e8c7bf 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -50,12 +50,15 @@ static void zcomp_strm_free(struct zcomp_strm *zstrm)
static int zcomp_strm_init(struct zcomp_strm *zstrm, struct zcomp *comp)
{
zstrm->tfm = crypto_alloc_comp(comp->name, 0, 0);
+ if (IS_ERR_OR_NULL(zstrm->tfm))
+ return -EINVAL;
+
/*
* allocate 2 pages. 1 for compressed data, plus 1 extra for the
* case when compressed size is larger than the original one
*/
zstrm->buffer = vzalloc(2 * PAGE_SIZE);
- if (IS_ERR_OR_NULL(zstrm->tfm) || !zstrm->buffer) {
+ if (!zstrm->buffer) {
zcomp_strm_free(zstrm);
return -ENOMEM;
}
--
2.43.0.594.gd9cf4e227d-goog