Skip to contentSkip to conversation

staging: fbtft: use ARRAY_SIZE() in NUMARGS macro

PATCH In review Joyeta Modak 4 participants 6 messages Jun 24 – Jun 26

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: fbtft: use ARRAY_SIZE() in NUMARGS macro

NUMARGS() computes the number of arguments by dividing the size of a temporary int array by sizeof(int). Using the standard ARRAY_SIZE() macro is the correct way to count array elements in the kernel, and ARRAY_SIZE() also provides a __must_be_array() compile time check. There are no functional changes.

Found using make coccicheck (scripts/coccinelle/misc/array_size.cocci).

---
 drivers/staging/fbtft/fbtft.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/fbtft/fbtft.h +2 -1
index c7afb0fd3..48da1503f 100644
@@ -4,6 +4,7 @@
 #ifndef __LINUX_FBTFT_H
 #define __LINUX_FBTFT_H
 
+#include <linux/array_size.h>
 #include <linux/fb.h>
 #include <linux/spinlock.h>
 #include <linux/spi/spi.h>
@@ -233,7 +234,7 @@ struct fbtft_par {
 	bool polarity;
 };
 
-#define NUMARGS(...)  (sizeof((int[]){__VA_ARGS__}) / sizeof(int))
+#define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
 
 #define write_reg(par, ...)                                            \
 	((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
Signature · 1 line
2.53.0
#1 lore raw
Quoted 5 lines · Joyeta Modak

NUMARGS() computes the number of arguments by dividing the size of a temporary int array by sizeof(int). Using the standard ARRAY_SIZE() macro is the correct way to count array elements in the kernel, and ARRAY_SIZE() also provides a __must_be_array() compile time check. There are no functional changes.

...

drivers/staging/fbtft/fbtft.h struct fbtft_par { · line 240

Quoted 5 lines
drivers/staging/fbtft/fbtft.h +1 -1
-#define NUMARGS(...)  (sizeof((int[]){__VA_ARGS__}) / sizeof(int))
+#define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
 
 #define write_reg(par, ...)                                            \
 	((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))

What is the maximum parameters .write_register() takes in practice in the fbtft drivers? If it's less than or equal to 15, we may use args.h instead.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
In reply to Joyeta Modak
kernel test robot noticed the following build errors:

Hi Joyeta,

kernel test robot noticed the following build errors:

[auto build test ERROR on staging/staging-testing]

url:    https://github.com/intel-lab-lkp/linux/commits/Joyeta-Modak/staging-fbtft-use-ARRAY_SIZE-in-NUMARGS-macro/20260624-153912
base:   staging/staging-testing
patch link:    https://lore.kernel.org/r/20260624073804.4391-1-joyetamdk%40gmail.com
patch subject: [PATCH] staging: fbtft: use ARRAY_SIZE() in NUMARGS macro
config: um-randconfig-002-20260624 (https://download.01.org/0day-ci/archive/20260624/[email protected]/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260624/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from drivers/staging/fbtft/fb_ili9486.c:13:
In file included from drivers/staging/fbtft/fbtft.h:8:
In file included from include/linux/fb.h:5:
In file included from include/uapi/linux/fb.h:6:
In file included from include/linux/i2c.h:19:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:27:
In file included from include/linux/kernel_stat.h:8:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from arch/um/include/asm/hardirq.h:24:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:12:
In file included from arch/um/include/asm/io.h:24:
include/asm-generic/io.h:1209:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
1209 | return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
| ~~~~~~~~~~ ^

>> drivers/staging/fbtft/fb_ili9486.c:51:11: error: initializer element is not a compile-time constant
      51 |                           0x80 | (par->bgr << 3));
         |                           ~~~~~^~~~~~~~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                                      ^~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                                           ^~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                                           ^~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler.h:204:39: note: expanded from macro '__is_array'
     204 | #define __is_array(a)           (!__same_type((a), &(a)[0]))
         |                                                ^
   include/linux/compiler_types.h:610:63: note: expanded from macro '__same_type'
     610 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/compiler.h:200:84: note: expanded from macro '__BUILD_BUG_ON_ZERO_MSG'
     200 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg, ...) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                                                    ^
   drivers/staging/fbtft/fb_ili9486.c:55:11: error: initializer element is not a compile-time constant
      55 |                           0x20 | (par->bgr << 3));
         |                           ~~~~~^~~~~~~~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                                      ^~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                                           ^~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                                           ^~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler.h:204:39: note: expanded from macro '__is_array'
     204 | #define __is_array(a)           (!__same_type((a), &(a)[0]))
         |                                                ^
   include/linux/compiler_types.h:610:63: note: expanded from macro '__same_type'
     610 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/compiler.h:200:84: note: expanded from macro '__BUILD_BUG_ON_ZERO_MSG'
     200 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg, ...) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                                                    ^
   drivers/staging/fbtft/fb_ili9486.c:59:11: error: initializer element is not a compile-time constant
      59 |                           0x40 | (par->bgr << 3));
         |                           ~~~~~^~~~~~~~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                                      ^~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                                           ^~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                                           ^~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler.h:204:39: note: expanded from macro '__is_array'
     204 | #define __is_array(a)           (!__same_type((a), &(a)[0]))
         |                                                ^
   include/linux/compiler_types.h:610:63: note: expanded from macro '__same_type'
     610 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/compiler.h:200:84: note: expanded from macro '__BUILD_BUG_ON_ZERO_MSG'
     200 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg, ...) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                                                    ^
   drivers/staging/fbtft/fb_ili9486.c:63:11: error: initializer element is not a compile-time constant
      63 |                           0xE0 | (par->bgr << 3));
         |                           ~~~~~^~~~~~~~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                                      ^~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                                           ^~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                                           ^~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler.h:204:39: note: expanded from macro '__is_array'
     204 | #define __is_array(a)           (!__same_type((a), &(a)[0]))
         |                                                ^
   include/linux/compiler_types.h:610:63: note: expanded from macro '__same_type'
     610 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/compiler.h:200:84: note: expanded from macro '__BUILD_BUG_ON_ZERO_MSG'
     200 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg, ...) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                                                    ^

1 warning and 4 errors generated.
--
In file included from drivers/staging/fbtft/fbtft-core.c:18:
In file included from include/linux/fb.h:5:
In file included from include/uapi/linux/fb.h:6:
In file included from include/linux/i2c.h:19:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:27:
In file included from include/linux/kernel_stat.h:8:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from arch/um/include/asm/hardirq.h:24:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:12:
In file included from arch/um/include/asm/io.h:24:
include/asm-generic/io.h:1209:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
1209 | return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
| ~~~~~~~~~~ ^

>> drivers/staging/fbtft/fbtft-core.c:204:15: error: initializer element is not a compile-time constant
     204 |                   (xs >> 8) & 0xFF, xs & 0xFF, (xe >> 8) & 0xFF, xe & 0xFF);
         |                   ~~~~~~~~~~^~~~~~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                                      ^~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                                           ^~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                                           ^~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler.h:204:39: note: expanded from macro '__is_array'
     204 | #define __is_array(a)           (!__same_type((a), &(a)[0]))
         |                                                ^
   include/linux/compiler_types.h:610:63: note: expanded from macro '__same_type'
     610 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/compiler.h:200:84: note: expanded from macro '__BUILD_BUG_ON_ZERO_MSG'
     200 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg, ...) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                                                    ^
   drivers/staging/fbtft/fbtft-core.c:207:15: error: initializer element is not a compile-time constant
     207 |                   (ys >> 8) & 0xFF, ys & 0xFF, (ye >> 8) & 0xFF, ye & 0xFF);
         |                   ~~~~~~~~~~^~~~~~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                                      ^~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                                           ^~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                                           ^~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler.h:204:39: note: expanded from macro '__is_array'
     204 | #define __is_array(a)           (!__same_type((a), &(a)[0]))
         |                                                ^
   include/linux/compiler_types.h:610:63: note: expanded from macro '__same_type'
     610 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/compiler.h:200:84: note: expanded from macro '__BUILD_BUG_ON_ZERO_MSG'
     200 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg, ...) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                                                    ^

1 warning and 2 errors generated.
--
In file included from drivers/staging/fbtft/fb_upd161704.c:17:
In file included from drivers/staging/fbtft/fbtft.h:8:
In file included from include/linux/fb.h:5:
In file included from include/uapi/linux/fb.h:6:
In file included from include/linux/i2c.h:19:
In file included from include/linux/regulator/consumer.h:35:
In file included from include/linux/suspend.h:5:
In file included from include/linux/swap.h:9:
In file included from include/linux/memcontrol.h:13:
In file included from include/linux/cgroup.h:27:
In file included from include/linux/kernel_stat.h:8:
In file included from include/linux/interrupt.h:11:
In file included from include/linux/hardirq.h:11:
In file included from arch/um/include/asm/hardirq.h:24:
In file included from include/linux/irq.h:20:
In file included from include/linux/io.h:12:
In file included from arch/um/include/asm/io.h:24:
include/asm-generic/io.h:1209:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
1209 | return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
| ~~~~~~~~~~ ^

>> drivers/staging/fbtft/fb_upd161704.c:119:26: error: initializer element is not a compile-time constant
     119 |                 write_reg(par, 0x0006, xs);
         |                                        ^~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                                      ^~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                                           ^~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                                           ^~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler.h:204:39: note: expanded from macro '__is_array'
     204 | #define __is_array(a)           (!__same_type((a), &(a)[0]))
         |                                                ^
   include/linux/compiler_types.h:610:63: note: expanded from macro '__same_type'
     610 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/compiler.h:200:84: note: expanded from macro '__BUILD_BUG_ON_ZERO_MSG'
     200 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg, ...) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                                                    ^
   drivers/staging/fbtft/fb_upd161704.c:120:26: error: initializer element is not a compile-time constant
     120 |                 write_reg(par, 0x0007, ys);
         |                                        ^~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                                      ^~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                                           ^~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                                           ^~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler.h:204:39: note: expanded from macro '__is_array'
     204 | #define __is_array(a)           (!__same_type((a), &(a)[0]))
         |                                                ^
   include/linux/compiler_types.h:610:63: note: expanded from macro '__same_type'
     610 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/compiler.h:200:84: note: expanded from macro '__BUILD_BUG_ON_ZERO_MSG'
     200 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg, ...) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                                                    ^
   drivers/staging/fbtft/fb_upd161704.c:123:36: error: initializer element is not a compile-time constant
     123 |                 write_reg(par, 0x0006, WIDTH - 1 - xs);
         |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                              ~~~~~~~~^~~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                       ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                           ~~~~~~~~~~~~~~~~^~~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler.h:204:39: note: expanded from macro '__is_array'
     204 | #define __is_array(a)           (!__same_type((a), &(a)[0]))
         |                                                ^
   include/linux/compiler_types.h:610:63: note: expanded from macro '__same_type'
     610 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/compiler.h:200:84: note: expanded from macro '__BUILD_BUG_ON_ZERO_MSG'
     200 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg, ...) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                                                    ^
   drivers/staging/fbtft/fb_upd161704.c:124:37: error: initializer element is not a compile-time constant
     124 |                 write_reg(par, 0x0007, HEIGHT - 1 - ys);
         |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                              ~~~~~~~~^~~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                       ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                           ~~~~~~~~~~~~~~~~^~~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler.h:204:39: note: expanded from macro '__is_array'
     204 | #define __is_array(a)           (!__same_type((a), &(a)[0]))
         |                                                ^
   include/linux/compiler_types.h:610:63: note: expanded from macro '__same_type'
     610 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/compiler.h:200:84: note: expanded from macro '__BUILD_BUG_ON_ZERO_MSG'
     200 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg, ...) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                                                    ^
   drivers/staging/fbtft/fb_upd161704.c:127:36: error: initializer element is not a compile-time constant
     127 |                 write_reg(par, 0x0006, WIDTH - 1 - ys);
         |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                              ~~~~~~~~^~~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                       ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                           ~~~~~~~~~~~~~~~~^~~~

note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
--
In file included from drivers/staging/fbtft/fb_pcd8544.c:15:
In file included from include/linux/spi/spi.h:17:
In file included from include/linux/scatterlist.h:9:
In file included from arch/um/include/asm/io.h:24:
include/asm-generic/io.h:1209:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
1209 | return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
| ~~~~~~~~~~ ^

>> drivers/staging/fbtft/fb_pcd8544.c:53:17: error: initializer element is not a compile-time constant
      53 |         write_reg(par, 0x04 | (tc & 0x3));
         |                        ^~~~~~~~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                                      ^~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                                           ^~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                                           ^~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler.h:204:39: note: expanded from macro '__is_array'
     204 | #define __is_array(a)           (!__same_type((a), &(a)[0]))
         |                                                ^
   include/linux/compiler_types.h:610:63: note: expanded from macro '__same_type'
     610 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/compiler.h:200:84: note: expanded from macro '__BUILD_BUG_ON_ZERO_MSG'
     200 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg, ...) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                                                    ^
   drivers/staging/fbtft/fb_pcd8544.c:63:17: error: initializer element is not a compile-time constant
      63 |         write_reg(par, 0x10 | (bs & 0x7));
         |                        ^~~~~~~~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                                      ^~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                                           ^~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                                           ^~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler.h:204:39: note: expanded from macro '__is_array'
     204 | #define __is_array(a)           (!__same_type((a), &(a)[0]))
         |                                                ^
   include/linux/compiler_types.h:610:63: note: expanded from macro '__same_type'
     610 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/compiler.h:200:84: note: expanded from macro '__BUILD_BUG_ON_ZERO_MSG'
     200 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg, ...) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                                                    ^
   drivers/staging/fbtft/fb_pcd8544.c:137:17: error: initializer element is not a compile-time constant
     137 |         write_reg(par, 0x80 | curves[0]);
         |                        ^~~~~~~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:240:47: note: expanded from macro 'write_reg'
     240 |         ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))
         |                                                      ^~~~~~~~~~~
   drivers/staging/fbtft/fbtft.h:237:43: note: expanded from macro 'NUMARGS'
     237 | #define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
         |                                           ^~~~~~~~~~~
   include/linux/array_size.h:11:75: note: expanded from macro 'ARRAY_SIZE'
      11 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
         |                                                                           ^~~
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
   include/linux/compiler.h:204:39: note: expanded from macro '__is_array'
     204 | #define __is_array(a)           (!__same_type((a), &(a)[0]))
         |                                                ^
   include/linux/compiler_types.h:610:63: note: expanded from macro '__same_type'
     610 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
         |                                                               ^
   include/linux/compiler.h:200:84: note: expanded from macro '__BUILD_BUG_ON_ZERO_MSG'
     200 | #define __BUILD_BUG_ON_ZERO_MSG(e, msg, ...) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
         |                                                                                    ^

1 warning and 3 errors generated.
..

vim +51 drivers/staging/fbtft/fb_ili9486.c

8d64b032aa71963 Thomas Petazzoni 2014-12-31  45  
8d64b032aa71963 Thomas Petazzoni 2014-12-31  46  static int set_var(struct fbtft_par *par)
8d64b032aa71963 Thomas Petazzoni 2014-12-31  47  {
8d64b032aa71963 Thomas Petazzoni 2014-12-31  48  	switch (par->info->var.rotate) {
8d64b032aa71963 Thomas Petazzoni 2014-12-31  49  	case 0:
49475ed0cbb5623 Priit Laes       2015-12-20  50  		write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
49475ed0cbb5623 Priit Laes       2015-12-20 @51  			  0x80 | (par->bgr << 3));
8d64b032aa71963 Thomas Petazzoni 2014-12-31  52  		break;
8d64b032aa71963 Thomas Petazzoni 2014-12-31  53  	case 90:
49475ed0cbb5623 Priit Laes       2015-12-20  54  		write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
49475ed0cbb5623 Priit Laes       2015-12-20  55  			  0x20 | (par->bgr << 3));
8d64b032aa71963 Thomas Petazzoni 2014-12-31  56  		break;
8d64b032aa71963 Thomas Petazzoni 2014-12-31  57  	case 180:
49475ed0cbb5623 Priit Laes       2015-12-20  58  		write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
49475ed0cbb5623 Priit Laes       2015-12-20  59  			  0x40 | (par->bgr << 3));
8d64b032aa71963 Thomas Petazzoni 2014-12-31  60  		break;
8d64b032aa71963 Thomas Petazzoni 2014-12-31  61  	case 270:
49475ed0cbb5623 Priit Laes       2015-12-20  62  		write_reg(par, MIPI_DCS_SET_ADDRESS_MODE,
49475ed0cbb5623 Priit Laes       2015-12-20  63  			  0xE0 | (par->bgr << 3));
8d64b032aa71963 Thomas Petazzoni 2014-12-31  64  		break;
8d64b032aa71963 Thomas Petazzoni 2014-12-31  65  	default:
8d64b032aa71963 Thomas Petazzoni 2014-12-31  66  		break;
8d64b032aa71963 Thomas Petazzoni 2014-12-31  67  	}
8d64b032aa71963 Thomas Petazzoni 2014-12-31  68  
8d64b032aa71963 Thomas Petazzoni 2014-12-31  69  	return 0;
8d64b032aa71963 Thomas Petazzoni 2014-12-31  70  }
8d64b032aa71963 Thomas Petazzoni 2014-12-31  71  

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#2 lore raw
In reply to Andy Shevchenko

Thank you for the feedback and the question.

I checked every write_reg() across all fbtft drivers and found that the largest number of arguments is 129 in write_reg(par, MIPI_DCS_WRITE_LUT,...)
As COUNT_ARGS() in args.h only supports up to 15, it is not a safe fit here.

However, the kernel test robot reported a problem with my implementation as the __must_be_array() check in ARRAY_SIZE() requires the array to be a compile time constant expression and thus breaks the call at several places.(example par->bgr)

I tried to reproduce this locally on my system using both GCC and Clang with ARCH=um on x86_64 but could not reproduce the build failure.

Since the original sizeof() based approach had no such errors flagged, I am thinking of dropping the ARRAY_SIZE() approach.

Any other feedback is appreciated. Thanks again.

Quoted 24 lines · Andy Shevchenko
Quoted 5 lines · Joyeta Modak

NUMARGS() computes the number of arguments by dividing the size of a temporary int array by sizeof(int). Using the standard ARRAY_SIZE() macro is the correct way to count array elements in the kernel, and ARRAY_SIZE() also provides a __must_be_array() compile time check. There are no functional changes.

...

drivers/staging/fbtft/fbtft.h struct fbtft_par { · line 240

Quoted 5 lines
drivers/staging/fbtft/fbtft.h +1 -1
-#define NUMARGS(...)  (sizeof((int[]){__VA_ARGS__}) / sizeof(int))
+#define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
 
 #define write_reg(par, ...)                                            \
      ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))

What is the maximum parameters .write_register() takes in practice in the fbtft drivers? If it's less than or equal to 15, we may use args.h instead.

--
With Best Regards,
Andy Shevchenko

Signature · 2 lines
Regards,
Joyeta Modak
#3 lore raw

On Fri, Jun 26, 2026 at 02:27:25PM +0530, Joyeta Modak wrote:

Please, do not top-post!

Quoted 7 lines

Thank you for the feedback and the question.

I checked every write_reg() across all fbtft drivers and found that the largest number of arguments is 129 in write_reg(par, MIPI_DCS_WRITE_LUT,...)
As COUNT_ARGS() in args.h only supports up to 15, it is not a safe fit here.

Quoted 8 lines

However, the kernel test robot reported a problem with my implementation as the __must_be_array() check in ARRAY_SIZE() requires the array to be a compile time constant expression and thus breaks the call at several places.(example par->bgr)

I tried to reproduce this locally on my system using both GCC and Clang with ARCH=um on x86_64 but could not reproduce the build failure.

How "um" is anyhow related to the real world cases? Try to compile your stuff with real ARCH settings, like x86_64.

Quoted 14 lines

Since the original sizeof() based approach had no such errors flagged, I am thinking of dropping the ARRAY_SIZE() approach.

Any other feedback is appreciated. Thanks again.

Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Joyeta Modak

NUMARGS() computes the number of arguments by dividing the size of a temporary int array by sizeof(int). Using the standard ARRAY_SIZE() macro is the correct way to count array elements in the kernel, and ARRAY_SIZE() also provides a __must_be_array() compile time check. There are no functional changes.

...

Quoted 8 lines
Quoted 8 lines

drivers/staging/fbtft/fbtft.h struct fbtft_par { · line 240

Quoted 5 lines
drivers/staging/fbtft/fbtft.h +1 -1
-#define NUMARGS(...)  (sizeof((int[]){__VA_ARGS__}) / sizeof(int))
+#define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
 
 #define write_reg(par, ...)                                            \
      ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))

What is the maximum parameters .write_register() takes in practice in the fbtft drivers? If it's less than or equal to 15, we may use args.h instead.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
In reply to Joyeta Modak
Quoted 6 lines · On Fri, 26 Jun 2026 14:27:25 +0530 Joyeta Modak <[email protected]> wrote:

Thank you for the feedback and the question.

I checked every write_reg() across all fbtft drivers and found that the largest number of arguments is 129 in write_reg(par, MIPI_DCS_WRITE_LUT,...)
As COUNT_ARGS() in args.h only supports up to 15, it is not a safe fit here.

That is also a pretty horrid way to write that message out. The function call itself uses well over 512 bytes of stack. Then there is all the code to push the arguments.

It really shouldn't be too hard to pass the address of a const u8[] all the way through to the code that copies the data to the hardware.

I tried to follow the code earlier. The 'common functions' that pretty much just call back through per-driver functions with names the 'write' really don't make it easy.

David

Quoted 43 lines

However, the kernel test robot reported a problem with my implementation as the __must_be_array() check in ARRAY_SIZE() requires the array to be a compile time constant expression and thus breaks the call at several places.(example par->bgr)

I tried to reproduce this locally on my system using both GCC and Clang with ARCH=um on x86_64 but could not reproduce the build failure.

Since the original sizeof() based approach had no such errors flagged, I am thinking of dropping the ARRAY_SIZE() approach.

Any other feedback is appreciated. Thanks again.

Quoted 24 lines · Andy Shevchenko
Quoted 5 lines · Joyeta Modak

NUMARGS() computes the number of arguments by dividing the size of a temporary int array by sizeof(int). Using the standard ARRAY_SIZE() macro is the correct way to count array elements in the kernel, and ARRAY_SIZE() also provides a __must_be_array() compile time check. There are no functional changes.

...

drivers/staging/fbtft/fbtft.h struct fbtft_par { · line 240

Quoted 5 lines
drivers/staging/fbtft/fbtft.h +1 -1
-#define NUMARGS(...)  (sizeof((int[]){__VA_ARGS__}) / sizeof(int))
+#define NUMARGS(...)  ARRAY_SIZE(((int[]){__VA_ARGS__}))
 
 #define write_reg(par, ...)                                            \
      ((par)->fbtftops.write_register(par, NUMARGS(__VA_ARGS__), __VA_ARGS__))  

What is the maximum parameters .write_register() takes in practice in the fbtft drivers? If it's less than or equal to 15, we may use args.h instead.

--
With Best Regards,
Andy Shevchenko