Re: [PATCH] bitfield.h: add FIELD_MAX_CONST

From: Yury Norov
Date: Tue May 21 2024 - 15:53:02 EST


On Tue, May 21, 2024 at 04:44:33PM +0200, Michal Schmidt wrote:
> On Tue, May 21, 2024 at 2:33 PM Alex Elder <elder@xxxxxxxxxx> wrote:
> > On 5/20/24 2:29 PM, Yury Norov wrote:
> > > + Alex Elder <elder@xxxxxxxxxx>, Jakub Kicinski <kuba@xxxxxxxxxx> and
> > > David S. Miller <davem@xxxxxxxxxxxxx>
> >
> > Thanks for adding me to this.
> >
> > My bottom line response is that I don't understand exactly
> > what problem this is solving (but I trust it solves a
> > problem for you). It *seems* like the existing macro(s)
> > should work for you, and if they don't, you might not be
> > using it (them) correctly. And... if a fix is needed, it
> > should be made to the existing macro if possible.
>
> Yury, Jakub, Alex,
> thanks for your reviews so far.
>
> All of you want to avoid adding another macro. I agree and I will be back
> with v2.
>
> To clarify where exactly I ran into the current limitations of FIELD_MAX:
> I am reworking drivers/net/ethernet/intel/ice/ice_gnss.c:ice_gnss_read().
> There, I will be changing "buf" to a small on-stack array:
> char buf[ICE_MAX_I2C_DATA_SIZE];
> where ICE_MAX_I2C_DATA_SIZE is defined using FIELD_MAX.
>
> There are a few more issues. I extracted them into this test case that
> I would like to make compilable:

Whatever you make with this, please add a 2nd patch with a test(s)
covering your cases. You can refer the test_bitmap_const_eval() in
lib/test_bitmap.c for an examples of how the compile-time expressions
are tested. The best place for the test would be lib/test_bitops, I
think.

Thanks,
Yury