[PATCH v3 3/4] nvmem: apple-spmi: improve calling safety with wrapper functions
Andy Shevchenko
andriy.shevchenko at intel.com
Thu Jul 16 11:07:13 PDT 2026
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 at linkmauve.fr>
...
> +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
More information about the linux-amlogic
mailing list