diff mbox series

[RFC,1/2] zram: do not allocate buffer if crypto comp allocation failed

Message ID 20240207065751.1908939-2-senozhatsky@chromium.org (mailing list archive)
State New, archived
Headers show
Series zram: decouple comp stream and comp buffer | expand

Commit Message

Sergey Senozhatsky Feb. 7, 2024, 6:57 a.m. UTC
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 <senozhatsky@chromium.org>
---
 drivers/block/zram/zcomp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

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;
 	}