[1/8] nvmem: core: make reg_write() take a const void *

Message ID 20260715175229.24672-2-linkmauve@linkmauve.fr (mailing list archive)
State New
Headers
Series nvmem: make reg_write() take a const void * |

Commit Message

Link Mauve July 15, 2026, 5:52 p.m. UTC
This callback used to take a mutable void * for no reason, this was
found while drafting the Rust abstraction.

Signed-off-by: Link Mauve <linkmauve@linkmauve.fr>
---
 drivers/nvmem/core.c           | 2 +-
 include/linux/nvmem-provider.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
  

Comments

sashiko-bot@kernel.org July 15, 2026, 6 p.m. UTC | #1
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Modifying the `nvmem_reg_write_t` callback signature to use `const void *val` without updating the implementing drivers causes widespread build failures and runtime kCFI panics.
--

--- Patch [1]: [PATCH 1/8] nvmem: core: make reg_write() take a const void * ---
commit 465aa1ef7ad6475c286716a1fffc7cdb9b6f09dc
Author: Link Mauve <linkmauve@linkmauve.fr>

nvmem: core: make reg_write() take a const void *

This commit changes the nvmem_reg_write_t callback signature to expect
a const void * instead of a mutable void *.

> diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
> index f3b13da78aac9..e62285836cbbe 100644
> --- a/include/linux/nvmem-provider.h
> +++ b/include/linux/nvmem-provider.h
> @@ -19,7 +19,7 @@ struct nvmem_device;
>  typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
>  				void *val, size_t bytes);
>  typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
> -				 void *val, size_t bytes);
> +				 const void *val, size_t bytes);

[Severity: High]
Does modifying this callback signature without updating the implementing
drivers cause widespread build failures and runtime kCFI panics?

For example, drivers/nvmem/bcm-ocotp.c:bcm_otpc_write() still expects
a mutable void *:

static int bcm_otpc_write(void *context, unsigned int offset, void *val,
                          size_t bytes)

When this is assigned to reg_write in bcm_otpc_nvmem_config, it causes an
incompatible pointer type mismatch. This leads to build errors with modern
compilers or -Werror, and will trigger kernel panics upon any nvmem write
operation on kernels with Control-Flow Integrity (kCFI) enabled.
  
Andy Shevchenko July 15, 2026, 6:58 p.m. UTC | #2
On Wed, Jul 15, 2026 at 07:52:17PM +0200, Link Mauve wrote:
> This callback used to take a mutable void * for no reason, this was
> found while drafting the Rust abstraction.

I don't understand how it was compiled. const void * != void * in C and can't
be implicitly covered, if I am not mistaken. So, this patch heavily should
break the build. What did I miss?
  
Link Mauve July 15, 2026, 7:03 p.m. UTC | #3
On Wed, Jul 15, 2026 at 09:58:08PM +0300, Andy Shevchenko wrote:
> On Wed, Jul 15, 2026 at 07:52:17PM +0200, Link Mauve wrote:
> > This callback used to take a mutable void * for no reason, this was
> > found while drafting the Rust abstraction.
> 
> I don't understand how it was compiled. const void * != void * in C and can't
> be implicitly covered, if I am not mistaken. So, this patch heavily should
> break the build. What did I miss?

I think I missed a lot of those drivers while compiling, probably
because I built it for my target hardware instead of doing a
COMPILE_TEST.

> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
>
  

Patch

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index e871181751f3..202607013054 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -62,7 +62,7 @@  static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
 }
 
 static int __nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
-			     void *val, size_t bytes)
+			     const void *val, size_t bytes)
 {
 	int ret;
 
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index f3b13da78aac..e62285836cbb 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -19,7 +19,7 @@  struct nvmem_device;
 typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
 				void *val, size_t bytes);
 typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
-				 void *val, size_t bytes);
+				 const void *val, size_t bytes);
 /* used for vendor specific post processing of cell data */
 typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index,
 					 unsigned int offset, void *buf,