Re: [RFC PATCH v2 1/2] regmap: add regmap_reg_field_* APIs

From: Andy Shevchenko

Date: Fri Nov 13 2026 - 06:10:07 EST


On Fri, Nov 13, 2026 at 10:53 AM Victor Chernyakin
<chernyakin.victor.j@xxxxxxxxxxx> wrote:
>
> > > -#define REG_FIELD(_reg, _lsb, _msb) { \
> > > - .reg = _reg, \
> > > - .lsb = _lsb, \
> > > - .msb = _msb, \
> > > - }
> > > +#define REG_FIELD(_reg, _lsb, _msb) ((struct reg_field){ \
> > > + .reg = _reg, \
> > > + .lsb = _lsb, \
> > > + .msb = _msb, \
> > > + })
> > >
> > > -#define REG_FIELD_ID(_reg, _lsb, _msb, _size, _offset) { \
> > > - .reg = _reg, \
> > > - .lsb = _lsb, \
> > > - .msb = _msb, \
> > > - .id_size = _size, \
> > > - .id_offset = _offset, \
> > > - }
> > > +#define REG_FIELD_ID(_reg, _lsb, _msb, _size, _offset) ((struct reg_field){ \
> > > + .reg = _reg, \
> > > + .lsb = _lsb, \
> > > + .msb = _msb, \
> > > + .id_size = _size, \
> > > + .id_offset = _offset, \
> > > + })
> >
> > So, you convert them to compound literals. This change may be good on
> > its own (see other similar changes in the kernel).
> > The only problem you have is the outer parentheses. They should be
> > dropped. If you need them, it's a problem on the user's side of this
> > macros.
>
> In this comment:
>
> https://lore.kernel.org/all/auzCxxkUB9p6WKNC@ashevche-desk.local/
>
> ...I got the impresssion that you were *against* dealing with it
> on the user's side (in REG_FIELD_GENMASK), and I agreed:

Yes, that's true and I confirm that it's not a business to handle
expressions in REG_FIELD_GENMASK(). We imply that the parameter there
is a regfield.

> if it > can be handled in REG_FIELD, why make users worry about it?

But REG_FIELD is also a macro, it's not their business either.

> But now it seems you're saying the opposite.

Nothing is opposite. The statement is the same, dealing with the
expressions should be done on the caller's side in REG_FIELD_GENMASK()
and REG_FIELD() (as the latter is also a macro).

> Can you clarify
> your stance?

I assume you are trying to have a use of it like in __uart_port_tx().
See also uart_port_tx().

--
With Best Regards,
Andy Shevchenko