Re: [PATCH v1 1/1] regmap: Add REG_FIELD_GENMASK() helper macro

From: Andy Shevchenko

Date: Thu Nov 05 2026 - 12:56:57 EST


On Thu, Nov 05, 2026 at 09:39:45AM -0600, Victor Chernyakin wrote:
> > #define REG_FIELD_GENMASK(_reg_field) GENMASK(_reg_field.msb, _reg_field.lsb)
>
> Macro parameter should have parens around it:

In this case no, it shouldn't. It a shortcut which assumes that _reg_field is
not an expression.

> + #define REG_FIELD_GENMASK(_reg_field) GENMASK((_reg_field).msb, (_reg_field).lsb)

This doesn't look good as it implies that _reg_field can be an expression that
will be evaluated twice.

> (In the patch you link to, I wrote it without parens at first too,
> then had to figure out why I was getting "too many arguments to macro"
> error messages)

This is strange.

I have compiled it with GCC-15 and clang-22 (in both cases sparse enabled),
no such a problem (It's also -Werror build). Can you elaborate?

> BTW, I've been thinking about making reg_field store the mask directly,
> by putting GENMASK(lsb, msb) in the REG_FIELD macro, but that's probably
> a more involved change.

But it's already there as you see in the regmap core. What you want is to make
it at the beginning. Not sure if it's feasible and needed change.

--
With Best Regards,
Andy Shevchenko