diff mbox series

[08/14] zram: check that backends array has at least one backend

Message ID 20240503091823.3616962-9-senozhatsky@chromium.org (mailing list archive)
State New, archived
Headers show
Series zram: convert to custom comp API and allow algorithms configuration | expand

Commit Message

Sergey Senozhatsky May 3, 2024, 9:17 a.m. UTC
Make sure that backends array has anything apart from the
sentinel NULL value.

Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
 drivers/block/zram/zcomp.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

kernel test robot May 4, 2024, 6:54 a.m. UTC | #1
Hi Sergey,

kernel test robot noticed the following build errors:

[auto build test ERROR on axboe-block/for-next]
[also build test ERROR on akpm-mm/mm-everything linus/master v6.9-rc6 next-20240503]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sergey-Senozhatsky/zram-move-from-crypto-API-to-custom-comp-backends-API/20240503-172335
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
patch link:    https://lore.kernel.org/r/20240503091823.3616962-9-senozhatsky%40chromium.org
patch subject: [PATCH 08/14] zram: check that backends array has at least one backend
config: s390-defconfig (https://download.01.org/0day-ci/archive/20240504/202405041440.UTBQZAaf-lkp@intel.com/config)
compiler: clang version 19.0.0git (https://github.com/llvm/llvm-project 37ae4ad0eef338776c7e2cffb3896153d43dcd90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240504/202405041440.UTBQZAaf-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202405041440.UTBQZAaf-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/block/zram/zcomp.c:12:
   In file included from include/linux/cpu.h:17:
   In file included from include/linux/node.h:18:
   In file included from include/linux/device.h:32:
   In file included from include/linux/device/driver.h:21:
   In file included from include/linux/module.h:19:
   In file included from include/linux/elf.h:6:
   In file included from arch/s390/include/asm/elf.h:173:
   In file included from arch/s390/include/asm/mmu_context.h:11:
   In file included from arch/s390/include/asm/pgalloc.h:18:
   In file included from include/linux/mm.h:2208:
   include/linux/vmstat.h:508:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     508 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     509 |                            item];
         |                            ~~~~
   include/linux/vmstat.h:515:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     515 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     516 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   include/linux/vmstat.h:522:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     522 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   include/linux/vmstat.h:527:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     527 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     528 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   include/linux/vmstat.h:536:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     536 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     537 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
>> drivers/block/zram/zcomp.c:214:2: error: call to '__compiletime_assert_285' declared with 'error' attribute: BUILD_BUG_ON failed: ARRAY_SIZE(backends) <= 1
     214 |         BUILD_BUG_ON(ARRAY_SIZE(backends) <= 1);
         |         ^
   include/linux/build_bug.h:50:2: note: expanded from macro 'BUILD_BUG_ON'
      50 |         BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
         |         ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^
   include/linux/compiler_types.h:449:2: note: expanded from macro 'compiletime_assert'
     449 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |         ^
   include/linux/compiler_types.h:437:2: note: expanded from macro '_compiletime_assert'
     437 |         __compiletime_assert(condition, msg, prefix, suffix)
         |         ^
   include/linux/compiler_types.h:430:4: note: expanded from macro '__compiletime_assert'
     430 |                         prefix ## suffix();                             \
         |                         ^
   <scratch space>:97:1: note: expanded from here
      97 | __compiletime_assert_285
         | ^
   5 warnings and 1 error generated.


vim +214 drivers/block/zram/zcomp.c

   202	
   203	struct zcomp *zcomp_create(const char *alg)
   204	{
   205		struct zcomp *comp;
   206		int error;
   207	
   208		/*
   209		 * The backends array has a sentinel NULL value, so the minimum
   210		 * size is 1. In order to be valid the array, apart from the
   211		 * sentinel NULL element, should have at least one compression
   212		 * backend selected.
   213		 */
 > 214		BUILD_BUG_ON(ARRAY_SIZE(backends) <= 1);
Sergey Senozhatsky May 4, 2024, 7:14 a.m. UTC | #2
On (24/05/04 14:54), kernel test robot wrote:
>          |                            ~~~~~~~~~~~~~~~~~~~~~~
> >> drivers/block/zram/zcomp.c:214:2: error: call to '__compiletime_assert_285' declared with 'error' attribute: BUILD_BUG_ON failed: ARRAY_SIZE(backends) <= 1
>      214 |         BUILD_BUG_ON(ARRAY_SIZE(backends) <= 1);
>          |         ^

So this is what that BUILD_BUG_ON() is supposed to catch. You don't
have any backends selected in your .config:

# CONFIG_ZRAM_BACKEND_LZO is not set
# CONFIG_ZRAM_BACKEND_LZ4 is not set
# CONFIG_ZRAM_BACKEND_LZ4HC is not set
# CONFIG_ZRAM_BACKEND_ZSTD is not set
# CONFIG_ZRAM_BACKEND_DEFLATE is not set
CONFIG_ZRAM_DEF_COMP="unset-value"

Which is invalid configuration because it means that zram has no
compression enabled.
kernel test robot May 4, 2024, 7:15 a.m. UTC | #3
Hi Sergey,

kernel test robot noticed the following build errors:

[auto build test ERROR on axboe-block/for-next]
[also build test ERROR on akpm-mm/mm-everything linus/master v6.9-rc6 next-20240503]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sergey-Senozhatsky/zram-move-from-crypto-API-to-custom-comp-backends-API/20240503-172335
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
patch link:    https://lore.kernel.org/r/20240503091823.3616962-9-senozhatsky%40chromium.org
patch subject: [PATCH 08/14] zram: check that backends array has at least one backend
config: x86_64-rhel-8.3 (https://download.01.org/0day-ci/archive/20240504/202405041458.j3L25KZg-lkp@intel.com/config)
compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240504/202405041458.j3L25KZg-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202405041458.j3L25KZg-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from <command-line>:
   drivers/block/zram/zcomp.c: In function 'zcomp_create':
>> include/linux/compiler_types.h:449:45: error: call to '__compiletime_assert_419' declared with attribute error: BUILD_BUG_ON failed: ARRAY_SIZE(backends) <= 1
     449 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |                                             ^
   include/linux/compiler_types.h:430:25: note: in definition of macro '__compiletime_assert'
     430 |                         prefix ## suffix();                             \
         |                         ^~~~~~
   include/linux/compiler_types.h:449:9: note: in expansion of macro '_compiletime_assert'
     449 |         _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
         |         ^~~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
      39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
         |                                     ^~~~~~~~~~~~~~~~~~
   include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
      50 |         BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
         |         ^~~~~~~~~~~~~~~~
   drivers/block/zram/zcomp.c:214:9: note: in expansion of macro 'BUILD_BUG_ON'
     214 |         BUILD_BUG_ON(ARRAY_SIZE(backends) <= 1);
         |         ^~~~~~~~~~~~


vim +/__compiletime_assert_419 +449 include/linux/compiler_types.h

eb5c2d4b45e3d2 Will Deacon 2020-07-21  435  
eb5c2d4b45e3d2 Will Deacon 2020-07-21  436  #define _compiletime_assert(condition, msg, prefix, suffix) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21  437  	__compiletime_assert(condition, msg, prefix, suffix)
eb5c2d4b45e3d2 Will Deacon 2020-07-21  438  
eb5c2d4b45e3d2 Will Deacon 2020-07-21  439  /**
eb5c2d4b45e3d2 Will Deacon 2020-07-21  440   * compiletime_assert - break build and emit msg if condition is false
eb5c2d4b45e3d2 Will Deacon 2020-07-21  441   * @condition: a compile-time constant condition to check
eb5c2d4b45e3d2 Will Deacon 2020-07-21  442   * @msg:       a message to emit if condition is false
eb5c2d4b45e3d2 Will Deacon 2020-07-21  443   *
eb5c2d4b45e3d2 Will Deacon 2020-07-21  444   * In tradition of POSIX assert, this macro will break the build if the
eb5c2d4b45e3d2 Will Deacon 2020-07-21  445   * supplied condition is *false*, emitting the supplied error message if the
eb5c2d4b45e3d2 Will Deacon 2020-07-21  446   * compiler has support to do so.
eb5c2d4b45e3d2 Will Deacon 2020-07-21  447   */
eb5c2d4b45e3d2 Will Deacon 2020-07-21  448  #define compiletime_assert(condition, msg) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21 @449  	_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
eb5c2d4b45e3d2 Will Deacon 2020-07-21  450
Andrew Morton May 4, 2024, 11:10 p.m. UTC | #4
On Sat, 4 May 2024 16:14:16 +0900 Sergey Senozhatsky <senozhatsky@chromium.org> wrote:

> On (24/05/04 14:54), kernel test robot wrote:
> >          |                            ~~~~~~~~~~~~~~~~~~~~~~
> > >> drivers/block/zram/zcomp.c:214:2: error: call to '__compiletime_assert_285' declared with 'error' attribute: BUILD_BUG_ON failed: ARRAY_SIZE(backends) <= 1
> >      214 |         BUILD_BUG_ON(ARRAY_SIZE(backends) <= 1);
> >          |         ^
> 
> So this is what that BUILD_BUG_ON() is supposed to catch. You don't
> have any backends selected in your .config:
> 
> # CONFIG_ZRAM_BACKEND_LZO is not set
> # CONFIG_ZRAM_BACKEND_LZ4 is not set
> # CONFIG_ZRAM_BACKEND_LZ4HC is not set
> # CONFIG_ZRAM_BACKEND_ZSTD is not set
> # CONFIG_ZRAM_BACKEND_DEFLATE is not set
> CONFIG_ZRAM_DEF_COMP="unset-value"
> 
> Which is invalid configuration because it means that zram has no
> compression enabled.

We don't want s390 defconfig to be doing this!

I guess just pick one if none were selected.
Sergey Senozhatsky May 5, 2024, 4:39 a.m. UTC | #5
On (24/05/04 16:10), Andrew Morton wrote:
> > On (24/05/04 14:54), kernel test robot wrote:
> > >          |                            ~~~~~~~~~~~~~~~~~~~~~~
> > > >> drivers/block/zram/zcomp.c:214:2: error: call to '__compiletime_assert_285' declared with 'error' attribute: BUILD_BUG_ON failed: ARRAY_SIZE(backends) <= 1
> > >      214 |         BUILD_BUG_ON(ARRAY_SIZE(backends) <= 1);
> > >          |         ^
> > 
> > So this is what that BUILD_BUG_ON() is supposed to catch. You don't
> > have any backends selected in your .config:
> > 
> > # CONFIG_ZRAM_BACKEND_LZO is not set
> > # CONFIG_ZRAM_BACKEND_LZ4 is not set
> > # CONFIG_ZRAM_BACKEND_LZ4HC is not set
> > # CONFIG_ZRAM_BACKEND_ZSTD is not set
> > # CONFIG_ZRAM_BACKEND_DEFLATE is not set
> > CONFIG_ZRAM_DEF_COMP="unset-value"
> > 
> > Which is invalid configuration because it means that zram has no
> > compression enabled.
> 
> We don't want s390 defconfig to be doing this!
> 
> I guess just pick one if none were selected.

I'm looking into it.

We used to have "zram depends on crypto compression algorithm"

: config ZRAM
:        tristate "Compressed RAM block device support"
:        depends on BLOCK && SYSFS && MMU
:        depends on CRYPTO_LZO || CRYPTO_ZSTD || CRYPTO_LZ4 || CRYPTO_LZ4HC || CRYPTO_842

I sort of wanted to change it and make zram select compression algorithm,
instead of depending on some comp algorithm being already selected.
But I can probably keep the old behaviour

: config ZRAM
:        tristate "Compressed RAM block device support"
:        depends on BLOCK && SYSFS && MMU
:        select ZSMALLOC
:        depends on (LZO_COMPRESS && LZO_DECOMPRESS) || \
:                (LZ4_COMPRESS && LZ4_DECOMPRESS) || \
:                (LZ4HC_COMPRESS && LZ4_DECOMPRESS) || \
:                (ZSTD_COMPRESS && ZSTD_DECOMPRESS) || \
:                (ZLIB_DEFLATE && ZLIB_INFLATE)
Sergey Senozhatsky May 5, 2024, 5:13 a.m. UTC | #6
On (24/05/05 13:39), Sergey Senozhatsky wrote:
[..]
> > I guess just pick one if none were selected.

How do I pick one if none were selected? Does Kconfig support
something like that?

> : config ZRAM
> :        tristate "Compressed RAM block device support"
> :        depends on BLOCK && SYSFS && MMU
> :        select ZSMALLOC
> :        depends on (LZO_COMPRESS && LZO_DECOMPRESS) || \
> :                (LZ4_COMPRESS && LZ4_DECOMPRESS) || \
> :                (LZ4HC_COMPRESS && LZ4_DECOMPRESS) || \
> :                (ZSTD_COMPRESS && ZSTD_DECOMPRESS) || \
> :                (ZLIB_DEFLATE && ZLIB_INFLATE)

The problem I'm having with this is that FOO_COMPRESS can be M while
zram needs Y.
Sergey Senozhatsky May 5, 2024, 6:48 a.m. UTC | #7
On (24/05/05 14:13), Sergey Senozhatsky wrote:
> On (24/05/05 13:39), Sergey Senozhatsky wrote:
> [..]
> > > I guess just pick one if none were selected.
> 
> How do I pick one if none were selected? Does Kconfig support
> something like that?

This triggers Kconfig error:

config ZRAM_EMPTY_BACKENDS_FIXUP
       bool
       depends on ZRAM && !ZRAM_BACKEND_LZO && !ZRAM_BACKEND_LZ4 && \
               !ZRAM_BACKEND_LZ4HC && !ZRAM_BACKEND_ZSTD && \
               !ZRAM_BACKEND_DEFLATE
       select ZRAM_BACKEND_LZO


drivers/block/zram/Kconfig:17:error: recursive dependency detected!
drivers/block/zram/Kconfig:17:  symbol ZRAM_BACKEND_LZO is selected by ZRAM_EMPTY_BACKENDS_FIXUP
drivers/block/zram/Kconfig:52:  symbol ZRAM_EMPTY_BACKENDS_FIXUP depends on ZRAM_BACKEND_LZO


I'm a little surprised by this - EMPTY_BACKENDS_FIXUP does not depend
on ZRAM_BACKEND_LZO, it depends on NOT ZRAM_BACKEND_LZO.

Let me Cc linux-kbuild. Kbuild folks, how do I workaround this?
Sergey Senozhatsky May 6, 2024, 3:22 a.m. UTC | #8
On (24/05/05 15:48), Sergey Senozhatsky wrote:
> On (24/05/05 14:13), Sergey Senozhatsky wrote:
> > On (24/05/05 13:39), Sergey Senozhatsky wrote:
> > [..]
> > > > I guess just pick one if none were selected.
> > 
> > How do I pick one if none were selected? Does Kconfig support
> > something like that?
> 
> This triggers Kconfig error:
> 
> config ZRAM_EMPTY_BACKENDS_FIXUP
>        bool
>        depends on ZRAM && !ZRAM_BACKEND_LZO && !ZRAM_BACKEND_LZ4 && \
>                !ZRAM_BACKEND_LZ4HC && !ZRAM_BACKEND_ZSTD && \
>                !ZRAM_BACKEND_DEFLATE
>        select ZRAM_BACKEND_LZO
> 
> 
> drivers/block/zram/Kconfig:17:error: recursive dependency detected!
> drivers/block/zram/Kconfig:17:  symbol ZRAM_BACKEND_LZO is selected by ZRAM_EMPTY_BACKENDS_FIXUP
> drivers/block/zram/Kconfig:52:  symbol ZRAM_EMPTY_BACKENDS_FIXUP depends on ZRAM_BACKEND_LZO
> 
> 
> I'm a little surprised by this - EMPTY_BACKENDS_FIXUP does not depend
> on ZRAM_BACKEND_LZO, it depends on NOT ZRAM_BACKEND_LZO.
> 
> Let me Cc linux-kbuild. Kbuild folks, how do I workaround this?

Is this how one does it?

config ZRAM_BACKEND_LZO
       bool "lzo and lzo-rle compression support"
       depends on ZRAM
       default y if !ZRAM_BACKEND_LZ4 && !ZRAM_BACKEND_LZ4HC && \
               !ZRAM_BACKEND_ZSTD && !ZRAM_BACKEND_DEFLATE
       default n
       select LZO_COMPRESS
       select LZO_DECOMPRESS


User still can select N and then we'll have empty backends, but
at least default is Y if none of the algorithms were selected.
Is it good enough?
Masahiro Yamada May 6, 2024, 5:20 a.m. UTC | #9
On Mon, May 6, 2024 at 12:22 PM Sergey Senozhatsky
<senozhatsky@chromium.org> wrote:
>
> On (24/05/05 15:48), Sergey Senozhatsky wrote:
> > On (24/05/05 14:13), Sergey Senozhatsky wrote:
> > > On (24/05/05 13:39), Sergey Senozhatsky wrote:
> > > [..]
> > > > > I guess just pick one if none were selected.
> > >
> > > How do I pick one if none were selected? Does Kconfig support
> > > something like that?
> >
> > This triggers Kconfig error:
> >
> > config ZRAM_EMPTY_BACKENDS_FIXUP
> >        bool
> >        depends on ZRAM && !ZRAM_BACKEND_LZO && !ZRAM_BACKEND_LZ4 && \
> >                !ZRAM_BACKEND_LZ4HC && !ZRAM_BACKEND_ZSTD && \
> >                !ZRAM_BACKEND_DEFLATE
> >        select ZRAM_BACKEND_LZO
> >
> >
> > drivers/block/zram/Kconfig:17:error: recursive dependency detected!
> > drivers/block/zram/Kconfig:17:  symbol ZRAM_BACKEND_LZO is selected by ZRAM_EMPTY_BACKENDS_FIXUP
> > drivers/block/zram/Kconfig:52:  symbol ZRAM_EMPTY_BACKENDS_FIXUP depends on ZRAM_BACKEND_LZO
> >
> >
> > I'm a little surprised by this - EMPTY_BACKENDS_FIXUP does not depend
> > on ZRAM_BACKEND_LZO, it depends on NOT ZRAM_BACKEND_LZO.
> >
> > Let me Cc linux-kbuild. Kbuild folks, how do I workaround this?
>
> Is this how one does it?
>
> config ZRAM_BACKEND_LZO
>        bool "lzo and lzo-rle compression support"
>        depends on ZRAM
>        default y if !ZRAM_BACKEND_LZ4 && !ZRAM_BACKEND_LZ4HC && \
>                !ZRAM_BACKEND_ZSTD && !ZRAM_BACKEND_DEFLATE
>        default n
>        select LZO_COMPRESS
>        select LZO_DECOMPRESS
>
>
> User still can select N and then we'll have empty backends, but
> at least default is Y if none of the algorithms were selected.
> Is it good enough?


I interpret this sentence into:

"randconfig will eventually disable all ZRAM_BACKEND_*,
causing the build error again.
Is it good enough, Arnd?"



Some possible solutions:



config ZRAM_BACKEND_FORCE_LZO
        def_bool !ZRAM_BACKEND_LZ4 && !ZRAM_BACKEND_LZ4HC && \
                 !ZRAM_BACKEND_ZSTD && !ZRAM_BACKEND_DEFLATE
        depends on ZRAM
        select ZRAM_BACKEND_LZO

config ZRAM_BACKEND_LZO
        bool "lzo and lzo-rle compression support"
        depends on ZRAM
        select LZO_COMPRESS
        select LZO_DECOMPRESS


OR


config ZRAM_BACKEND_FORCE_LZO
        def_bool !ZRAM_BACKEND_LZ4 && !ZRAM_BACKEND_LZ4HC && \
                 !ZRAM_BACKEND_ZSTD && !ZRAM_BACKEND_DEFLATE

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




BTW, "default n" you are adding are redundant.
Sergey Senozhatsky May 6, 2024, 6:43 a.m. UTC | #10
On (24/05/06 14:20), Masahiro Yamada wrote:
> config ZRAM_BACKEND_FORCE_LZO
>         def_bool !ZRAM_BACKEND_LZ4 && !ZRAM_BACKEND_LZ4HC && \
>                  !ZRAM_BACKEND_ZSTD && !ZRAM_BACKEND_DEFLATE
> 
> 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

I'll take this one. Thank you.

> BTW, "default n" you are adding are redundant.

OK.
diff mbox series

Patch

diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index 9fc5477a6259..fdf06fc6b364 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -205,6 +205,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);