Linux Framebuffer Layer development
 help / color / mirror / Atom feed
* [PATCH] staging: fbtft: use ARRAY_SIZE() in NUMARGS macro
@ 2026-06-24  7:38 Joyeta Modak
  2026-06-24 11:31 ` Andy Shevchenko
  2026-06-24 13:02 ` kernel test robot
  0 siblings, 2 replies; 6+ messages in thread
From: Joyeta Modak @ 2026-06-24  7:38 UTC (permalink / raw)
  To: andy, gregkh
  Cc: dri-devel, linux-fbdev, linux-staging, linux-kernel, 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.

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

Signed-off-by: Joyeta Modak <joyetamdk@gmail.com>
---
 drivers/staging/fbtft/fbtft.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h
index c7afb0fd3..48da1503f 100644
--- a/drivers/staging/fbtft/fbtft.h
+++ b/drivers/staging/fbtft/fbtft.h
@@ -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__))
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: fbtft: use ARRAY_SIZE() in NUMARGS macro
  2026-06-24  7:38 [PATCH] staging: fbtft: use ARRAY_SIZE() in NUMARGS macro Joyeta Modak
@ 2026-06-24 11:31 ` Andy Shevchenko
  2026-06-26  8:57   ` Joyeta Modak
  2026-06-24 13:02 ` kernel test robot
  1 sibling, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-06-24 11:31 UTC (permalink / raw)
  To: Joyeta Modak
  Cc: andy, gregkh, dri-devel, linux-fbdev, linux-staging, linux-kernel

On Wed, Jun 24, 2026 at 01:08:04PM +0530, Joyeta Modak wrote:
> 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.

...

> -#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



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: fbtft: use ARRAY_SIZE() in NUMARGS macro
  2026-06-24  7:38 [PATCH] staging: fbtft: use ARRAY_SIZE() in NUMARGS macro Joyeta Modak
  2026-06-24 11:31 ` Andy Shevchenko
@ 2026-06-24 13:02 ` kernel test robot
  1 sibling, 0 replies; 6+ messages in thread
From: kernel test robot @ 2026-06-24 13:02 UTC (permalink / raw)
  To: Joyeta Modak, andy, gregkh
  Cc: llvm, oe-kbuild-all, dri-devel, linux-fbdev, linux-staging,
	linux-kernel, Joyeta Modak

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/202606242026.MmYHG2FZ-lkp@intel.com/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/202606242026.MmYHG2FZ-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/202606242026.MmYHG2FZ-lkp@intel.com/

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: fbtft: use ARRAY_SIZE() in NUMARGS macro
  2026-06-24 11:31 ` Andy Shevchenko
@ 2026-06-26  8:57   ` Joyeta Modak
  2026-06-26 12:23     ` Andy Shevchenko
  2026-06-26 13:41     ` David Laight
  0 siblings, 2 replies; 6+ messages in thread
From: Joyeta Modak @ 2026-06-26  8:57 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: andy, gregkh, dri-devel, linux-fbdev, linux-staging, linux-kernel

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.

On Wed, Jun 24, 2026 at 5:01 PM Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Wed, Jun 24, 2026 at 01:08:04PM +0530, Joyeta Modak wrote:
> > 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.
>
> ...
>
> > -#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
>
>


-- 
Regards,
Joyeta Modak

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: fbtft: use ARRAY_SIZE() in NUMARGS macro
  2026-06-26  8:57   ` Joyeta Modak
@ 2026-06-26 12:23     ` Andy Shevchenko
  2026-06-26 13:41     ` David Laight
  1 sibling, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-06-26 12:23 UTC (permalink / raw)
  To: Joyeta Modak
  Cc: andy, gregkh, dri-devel, linux-fbdev, linux-staging, linux-kernel

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

Please, do not top-post!

> 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.

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

> 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.

> On Wed, Jun 24, 2026 at 5:01 PM Andy Shevchenko
> <andriy.shevchenko@intel.com> wrote:
> >
> > On Wed, Jun 24, 2026 at 01:08:04PM +0530, Joyeta Modak wrote:
> > > 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.

...

> > > -#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



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: fbtft: use ARRAY_SIZE() in NUMARGS macro
  2026-06-26  8:57   ` Joyeta Modak
  2026-06-26 12:23     ` Andy Shevchenko
@ 2026-06-26 13:41     ` David Laight
  1 sibling, 0 replies; 6+ messages in thread
From: David Laight @ 2026-06-26 13:41 UTC (permalink / raw)
  To: Joyeta Modak
  Cc: Andy Shevchenko, andy, gregkh, dri-devel, linux-fbdev,
	linux-staging, linux-kernel

On Fri, 26 Jun 2026 14:27:25 +0530
Joyeta Modak <joyetamdk@gmail.com> 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

> 
> 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.
> 
> On Wed, Jun 24, 2026 at 5:01 PM Andy Shevchenko
> <andriy.shevchenko@intel.com> wrote:
> >
> > On Wed, Jun 24, 2026 at 01:08:04PM +0530, Joyeta Modak wrote:  
> > > 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.  
> >
> > ...
> >  
> > > -#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
> >
> >  
> 
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-06-26 13:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-24  7:38 [PATCH] staging: fbtft: use ARRAY_SIZE() in NUMARGS macro Joyeta Modak
2026-06-24 11:31 ` Andy Shevchenko
2026-06-26  8:57   ` Joyeta Modak
2026-06-26 12:23     ` Andy Shevchenko
2026-06-26 13:41     ` David Laight
2026-06-24 13:02 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox