Re: [PATCH] regmap: define cleanup helper for regmap_field
From: Sander Vanheule
Date: Fri Feb 20 2026 - 11:00:35 EST
On Fri, 2026-02-20 at 15:43 +0000, Mark Brown wrote:
> On Fri, Feb 20, 2026 at 04:36:46PM +0100, Sander Vanheule wrote:
>
> > struct regmap_field *field = regmap_field_alloc(...);
> > if (!field)
> > return -ENOMEM;
> >
> > int err = regmap_field_write(...);
> >
> > regmap_field_free(field);
> >
> > return err;
>
> That seems like a bit of an odd pattern, I'd expect the fields to live
> for the lifetime of the driver rather than a function. OTOH if people
> are doing that then sure.
That is usually the case yes. I did find myself using devm_regmap_field_alloc()
in a proposed driver [1] to avoid goto's in less trivial logic. I'll update the
example in v2 to show the benefit a bit more.
[1] https://lore.kernel.org/all/20251215175115.135294-5-sander@xxxxxxxxxxxxx/
Best,
Sander