Re: [PATCH v3 3/4] nvmem: apple-spmi: improve calling safety with wrapper functions

From: Link Mauve

Date: Sun Jul 26 2026 - 08:56:34 EST


Ah, someone independently sent the same patch as this one in
7089170e1df160f5f8fb395bc5aa2e2697b4e896, so I’ll drop it from v4.

Sorry it took that long!

On Thu, Jul 16, 2026 at 09:07:13PM +0300, Andy Shevchenko wrote:
> On Thu, Jul 16, 2026 at 04:24:10PM +0200, Link Mauve wrote:
> > This driver used to cast the regmap_bulk_*() functions to void *,
> > bypassing any compiler safety around incompatible function pointers.
> >
> > With two small wrappers, which just convert the void * priv parameter
> > into the wanted struct regmap *, we can remove the void * cast
> > altogether.
>
> Reported-by: ?
>
> > Signed-off-by: Link Mauve <linkmauve@xxxxxxxxxxxx>
>
> ...
>
> > +static int apple_spmi_nvmem_read(void *priv, unsigned int offset,
> > + void *val, size_t bytes)
> > +{
>
> > + struct regmap *regmap = priv;
>
> No need :-)
>
> > + return regmap_bulk_read(regmap, offset, val, bytes);
> > +}
>
> static int apple_spmi_nvmem_read(void *map, unsigned int offset,
> void *val, size_t bytes)
> {
> return regmap_bulk_read(map, offset, val, bytes);
> }
>
> ...
>
> > +static int apple_spmi_nvmem_write(void *priv, unsigned int offset,
> > + const void *val, size_t bytes)
> > +{
> > + struct regmap *regmap = priv;
> > + return regmap_bulk_write(regmap, offset, val, bytes);
> > +}
>
> In the similar way as above.
>
> ...
>
> > - .reg_read = (void *)regmap_bulk_read,
> > - .reg_write_const = (void *)regmap_bulk_write,
> > + .reg_read = apple_spmi_nvmem_read,
> > + .reg_write_const = apple_spmi_nvmem_write,
>
> I think the proper ordering is to address this first (before your main change)
> and update later with const argument. Yes, it will be a bit more changes, but
> it will be cleaner.
>
> --
> With Best Regards,
> Andy Shevchenko
>
>

--
Link Mauve