Re: [PATCH] staging: fbtft: use ARRAY_SIZE() in NUMARGS macro
Joyeta Modak <[email protected]>
| Newsgroups | org.kernel.vger.linux-fbdev,dev.linux.lists.linux-staging,org.freedesktop.lists.dri-devel,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CAN3JnUCem3Mw17e5D9b-aX58_ZaAvC6GZ-sBPEQfTTTP=o-WHA@mail.gmail.com> |
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 <[email protected]> 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