]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
zram: check that backends array has at least one backend
authorSergey Senozhatsky <senozhatsky@chromium.org>
Fri, 12 Jul 2024 05:18:23 +0000 (14:18 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 17 Aug 2024 00:52:29 +0000 (17:52 -0700)
Make sure that backends array has anything apart from the
sentinel NULL value.

We also select LZO_BACKEND if none backends were selected.

Link: https://lkml.kernel.org/r/20240712051850.484318-13-senozhatsky@chromium.org
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Nick Terrell <terrelln@fb.com>
Cc: Nitin Gupta <ngupta@vflare.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/block/zram/Kconfig
drivers/block/zram/zcomp.c

index ddc19853ea963b0d9e8dc8079515cb70ca924a74..40e035468de22bf44cbe6b1fd555f9df5855d2a7 100644 (file)
@@ -15,12 +15,6 @@ config ZRAM
 
          See Documentation/admin-guide/blockdev/zram.rst for more information.
 
-config ZRAM_BACKEND_LZO
-       bool "lzo and lzo-rle compression support"
-       depends on ZRAM
-       select LZO_COMPRESS
-       select LZO_DECOMPRESS
-
 config ZRAM_BACKEND_LZ4
        bool "lz4 compression support"
        depends on ZRAM
@@ -51,6 +45,19 @@ config ZRAM_BACKEND_842
        select 842_COMPRESS
        select 842_DECOMPRESS
 
+config ZRAM_BACKEND_FORCE_LZO
+       depends on ZRAM
+       def_bool !ZRAM_BACKEND_LZ4 && !ZRAM_BACKEND_LZ4HC && \
+               !ZRAM_BACKEND_ZSTD && !ZRAM_BACKEND_DEFLATE && \
+               !ZRAM_BACKEND_842
+
+config ZRAM_BACKEND_LZO
+       bool "lzo and lzo-rle compression support" if !ZRAM_BACKEND_FORCE_LZO
+       depends on ZRAM
+       default ZRAM_BACKEND_FORCE_LZO
+       select LZO_COMPRESS
+       select LZO_DECOMPRESS
+
 choice
        prompt "Default zram compressor"
        default ZRAM_DEF_COMP_LZORLE
index 48ac7a3e89062f0e33f3b7c19f16a8a867df4c73..cb7afbd4d8fee0250e747ae692cae1a0677b2665 100644 (file)
@@ -191,6 +191,14 @@ struct zcomp *zcomp_create(const char *alg)
        struct zcomp *comp;
        int error;
 
+       /*
+        * The backends array has a sentinel NULL value, so the minimum
+        * size is 1. In order to be valid the array, apart from the
+        * sentinel NULL element, should have at least one compression
+        * backend selected.
+        */
+       BUILD_BUG_ON(ARRAY_SIZE(backends) <= 1);
+
        comp = kzalloc(sizeof(struct zcomp), GFP_KERNEL);
        if (!comp)
                return ERR_PTR(-ENOMEM);