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

Andy Shevchenko <[email protected]>
Newsgroups org.kernel.vger.rust-for-linux,dev.linux.lists.asahi,dev.linux.lists.imx,org.infradead.lists.linux-amlogic,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-arm-msm,org.kernel.vger.linux-kernel
Organization Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo
Message-ID <[email protected]>
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 <[email protected]>

...

> +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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.