Skip to content

Commit 1a78390

Browse files
sergey-senozhatskyakpm00
authored andcommitted
zram: check that backends array has at least one backend
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/[email protected] Signed-off-by: Sergey Senozhatsky <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Nick Terrell <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 1d3100c commit 1a78390

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

drivers/block/zram/Kconfig

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ config ZRAM
1414

1515
See Documentation/admin-guide/blockdev/zram.rst for more information.
1616

17-
config ZRAM_BACKEND_LZO
18-
bool "lzo and lzo-rle compression support"
19-
depends on ZRAM
20-
select LZO_COMPRESS
21-
select LZO_DECOMPRESS
22-
2317
config ZRAM_BACKEND_LZ4
2418
bool "lz4 compression support"
2519
depends on ZRAM
@@ -50,6 +44,19 @@ config ZRAM_BACKEND_842
5044
select 842_COMPRESS
5145
select 842_DECOMPRESS
5246

47+
config ZRAM_BACKEND_FORCE_LZO
48+
depends on ZRAM
49+
def_bool !ZRAM_BACKEND_LZ4 && !ZRAM_BACKEND_LZ4HC && \
50+
!ZRAM_BACKEND_ZSTD && !ZRAM_BACKEND_DEFLATE && \
51+
!ZRAM_BACKEND_842
52+
53+
config ZRAM_BACKEND_LZO
54+
bool "lzo and lzo-rle compression support" if !ZRAM_BACKEND_FORCE_LZO
55+
depends on ZRAM
56+
default ZRAM_BACKEND_FORCE_LZO
57+
select LZO_COMPRESS
58+
select LZO_DECOMPRESS
59+
5360
choice
5461
prompt "Default zram compressor"
5562
default ZRAM_DEF_COMP_LZORLE

drivers/block/zram/zcomp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ struct zcomp *zcomp_create(const char *alg)
192192
struct zcomp *comp;
193193
int error;
194194

195+
/*
196+
* The backends array has a sentinel NULL value, so the minimum
197+
* size is 1. In order to be valid the array, apart from the
198+
* sentinel NULL element, should have at least one compression
199+
* backend selected.
200+
*/
201+
BUILD_BUG_ON(ARRAY_SIZE(backends) <= 1);
202+
195203
comp = kzalloc(sizeof(struct zcomp), GFP_KERNEL);
196204
if (!comp)
197205
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)