diff options
author | Sergey Senozhatsky <senozhatsky@chromium.org> | 2024-09-02 12:56:00 +0200 |
---|---|---|
committer | Andrew Morton <akpm@linux-foundation.org> | 2024-09-10 01:39:09 +0200 |
commit | 1a78390d8760c20c188f27feae74ddb44ae6f0bb (patch) | |
tree | 63d4a86dc69bdb03089f4fbabe2f831c7af1ebc1 /drivers/block/zram/zcomp.c | |
parent | zram: add 842 compression backend support (diff) | |
download | linux-1a78390d8760c20c188f27feae74ddb44ae6f0bb.tar.xz linux-1a78390d8760c20c188f27feae74ddb44ae6f0bb.zip |
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/20240902105656.1383858-13-senozhatsky@chromium.org
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nick Terrell <terrelln@fb.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'drivers/block/zram/zcomp.c')
-rw-r--r-- | drivers/block/zram/zcomp.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index 94e1c9503267..76d21ee77067 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -192,6 +192,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); |