* [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write
@ 2026-07-15 19:55 Link Mauve
2026-07-15 19:55 ` [PATCH v2 1/2] nvmem: core: deprecate reg_write callback and add reg_write_const Link Mauve
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Link Mauve @ 2026-07-15 19:55 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: Link Mauve, Andy Shevchenko, Sven Peter, Janne Grunau, Neal Gompa,
Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Vladimir Zapolskiy, André Draszik, Neil Armstrong,
Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Orson Zhai,
Baolin Wang, Chunyan Zhang, Maxime Coquelin, Alexandre Torgue,
Kalyani Akula, Michal Simek, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, asahi, linux-arm-kernel,
linux-kernel, imx, linux-amlogic, linux-arm-msm, linux-stm32,
rust-for-linux
This callback used to take a mutable void * for no reason, which causes
the compiler to be unaware that the val buffer should never be modified
by the callback.
This was found while drafting the nvmem-provider Rust abstraction.
Thanks to the guidance of Andy Shevchenko, this now introduces a new
callback and deprecates the existing one, with the goal of renaming the
new one into the old one once no user remains in the kernel.
Changes since v1:
- Link to v1:
https://lore.kernel.org/rust-for-linux/20260715175229.24672-1-linkmauve@linkmauve.fr/
- Removed all changes to other subsystems than nvmem.
- Added a new reg_write_const callback instead of changing the exisitng
reg_write.
- Deprecated the existing reg_write callback, it will get removed once
all users in the kernel will be done migrating to the new one.
Link Mauve (2):
nvmem: core: deprecate reg_write callback and add reg_write_const
nvmem: make all reg_write callbacks take const void *
drivers/nvmem/apple-spmi-nvmem.c | 2 +-
drivers/nvmem/bcm-ocotp.c | 6 +++---
drivers/nvmem/core.c | 26 +++++++++++++++++---------
drivers/nvmem/imx-ocotp-scu.c | 6 +++---
drivers/nvmem/imx-ocotp.c | 6 +++---
drivers/nvmem/internals.h | 1 +
drivers/nvmem/lan9662-otpc.c | 6 +++---
drivers/nvmem/lpc18xx_eeprom.c | 6 +++---
drivers/nvmem/max77759-nvmem.c | 4 ++--
drivers/nvmem/meson-efuse.c | 6 +++---
drivers/nvmem/qcom-spmi-sdam.c | 4 ++--
drivers/nvmem/qfprom.c | 6 +++---
drivers/nvmem/rave-sp-eeprom.c | 6 +++---
drivers/nvmem/snvs_lpgpr.c | 4 ++--
drivers/nvmem/sprd-efuse.c | 6 +++---
drivers/nvmem/stm32-bsec-optee-ta.c | 2 +-
drivers/nvmem/stm32-bsec-optee-ta.h | 4 ++--
drivers/nvmem/stm32-romem.c | 10 +++++-----
drivers/nvmem/zynqmp_nvmem.c | 6 +++---
include/linux/nvmem-provider.h | 6 +++++-
20 files changed, 68 insertions(+), 55 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/2] nvmem: core: deprecate reg_write callback and add reg_write_const
2026-07-15 19:55 [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write Link Mauve
@ 2026-07-15 19:55 ` Link Mauve
2026-07-15 19:55 ` [PATCH v2 2/2] nvmem: make all reg_write callbacks take const void * Link Mauve
2026-07-16 9:03 ` [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write Andy Shevchenko
2 siblings, 0 replies; 8+ messages in thread
From: Link Mauve @ 2026-07-15 19:55 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: Link Mauve, Andy Shevchenko, Sven Peter, Janne Grunau, Neal Gompa,
Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Vladimir Zapolskiy, André Draszik, Neil Armstrong,
Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Orson Zhai,
Baolin Wang, Chunyan Zhang, Maxime Coquelin, Alexandre Torgue,
Kalyani Akula, Michal Simek, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, asahi, linux-arm-kernel,
linux-kernel, imx, linux-amlogic, linux-arm-msm, linux-stm32,
rust-for-linux
This callback used to take a mutable void * for no reason, which causes
the compiler to be unaware that the val buffer should never be modified
by the callback.
This was found while drafting the nvmem-provider Rust abstraction.
Signed-off-by: Link Mauve <linkmauve@linkmauve.fr>
---
drivers/nvmem/core.c | 26 +++++++++++++++++---------
drivers/nvmem/internals.h | 1 +
include/linux/nvmem-provider.h | 6 +++++-
3 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index e871181751f3..24c9e6f953c6 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -62,13 +62,20 @@ 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;
+ if (nvmem->reg_write_const) {
+ gpiod_set_value_cansleep(nvmem->wp_gpio, 0);
+ ret = nvmem->reg_write_const(nvmem->priv, offset, val, bytes);
+ gpiod_set_value_cansleep(nvmem->wp_gpio, 1);
+ return ret;
+ }
+
if (nvmem->reg_write) {
gpiod_set_value_cansleep(nvmem->wp_gpio, 0);
- ret = nvmem->reg_write(nvmem->priv, offset, val, bytes);
+ ret = nvmem->reg_write(nvmem->priv, offset, (void *)val, bytes);
gpiod_set_value_cansleep(nvmem->wp_gpio, 1);
return ret;
}
@@ -264,7 +271,7 @@ static ssize_t bin_attr_nvmem_write(struct file *filp, struct kobject *kobj,
count = round_down(count, nvmem->word_size);
- if (!nvmem->reg_write || nvmem->read_only)
+ if (!nvmem->reg_write || !nvmem->reg_write_const || nvmem->read_only)
return -EPERM;
rc = nvmem_reg_write(nvmem, pos, buf, count);
@@ -285,7 +292,7 @@ static umode_t nvmem_bin_attr_get_umode(struct nvmem_device *nvmem)
if (!nvmem->read_only)
mode |= 0200;
- if (!nvmem->reg_write)
+ if (!nvmem->reg_write || !nvmem->reg_write_const)
mode &= ~0200;
if (!nvmem->reg_read)
@@ -321,13 +328,13 @@ static umode_t nvmem_attr_is_visible(struct kobject *kobj,
struct nvmem_device *nvmem = to_nvmem_device(dev);
/*
- * If the device has no .reg_write operation, do not allow
- * configuration as read-write.
+ * If the device has no .reg_write or .reg_write_const operation, do
+ * not allow configuration as read-write.
* If the device is set as read-only by configuration, it
* can be forced into read-write mode using the 'force_ro'
* attribute.
*/
- if (attr == &dev_attr_force_ro.attr && !nvmem->reg_write)
+ if (attr == &dev_attr_force_ro.attr && !nvmem->reg_write && !nvmem->reg_write_const)
return 0; /* Attribute not visible */
return attr->mode;
@@ -905,7 +912,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
if (!config->dev)
return ERR_PTR(-EINVAL);
- if (!config->reg_read && !config->reg_write)
+ if (!config->reg_read && !config->reg_write && !config->reg_write_const)
return ERR_PTR(-EINVAL);
nvmem = kzalloc_obj(*nvmem);
@@ -950,6 +957,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
nvmem->type = config->type;
nvmem->reg_read = config->reg_read;
nvmem->reg_write = config->reg_write;
+ nvmem->reg_write_const = config->reg_write_const;
nvmem->keepout = config->keepout;
nvmem->nkeepout = config->nkeepout;
if (config->of_node)
@@ -975,7 +983,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
goto err_put_device;
nvmem->read_only = device_property_present(config->dev, "read-only") ||
- config->read_only || !nvmem->reg_write;
+ config->read_only || !nvmem->reg_write || !nvmem->reg_write_const;
#ifdef CONFIG_NVMEM_SYSFS
nvmem->dev.groups = nvmem_dev_groups;
diff --git a/drivers/nvmem/internals.h b/drivers/nvmem/internals.h
index 18fed57270e5..184711dfd6a6 100644
--- a/drivers/nvmem/internals.h
+++ b/drivers/nvmem/internals.h
@@ -29,6 +29,7 @@ struct nvmem_device {
unsigned int nkeepout;
nvmem_reg_read_t reg_read;
nvmem_reg_write_t reg_write;
+ nvmem_reg_write_const_t reg_write_const;
struct gpio_desc *wp_gpio;
struct nvmem_layout *layout;
void *priv;
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index f3b13da78aac..c6e77ba1a8c1 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -20,6 +20,8 @@ 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);
+typedef int (*nvmem_reg_write_const_t)(void *priv, unsigned int offset,
+ 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,
@@ -93,7 +95,8 @@ struct nvmem_cell_info {
* @root_only: Device is accessibly to root only.
* @of_node: If given, this will be used instead of the parent's of_node.
* @reg_read: Callback to read data; return zero if successful.
- * @reg_write: Callback to write data; return zero if successful.
+ * @reg_write: **DEPRECATED** - please use reg_write_const instead.
+ * @reg_write_const: Callback to write data; return zero if successful.
* @size: Device size.
* @word_size: Minimum read/write access granularity.
* @stride: Minimum read/write access stride.
@@ -128,6 +131,7 @@ struct nvmem_config {
struct device_node *of_node;
nvmem_reg_read_t reg_read;
nvmem_reg_write_t reg_write;
+ nvmem_reg_write_const_t reg_write_const;
int size;
int word_size;
int stride;
--
2.55.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] nvmem: make all reg_write callbacks take const void *
2026-07-15 19:55 [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write Link Mauve
2026-07-15 19:55 ` [PATCH v2 1/2] nvmem: core: deprecate reg_write callback and add reg_write_const Link Mauve
@ 2026-07-15 19:55 ` Link Mauve
2026-07-16 9:03 ` [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write Andy Shevchenko
2 siblings, 0 replies; 8+ messages in thread
From: Link Mauve @ 2026-07-15 19:55 UTC (permalink / raw)
To: Srinivas Kandagatla
Cc: Link Mauve, Andy Shevchenko, Sven Peter, Janne Grunau, Neal Gompa,
Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Vladimir Zapolskiy, André Draszik, Neil Armstrong,
Kevin Hilman, Jerome Brunet, Martin Blumenstingl, Orson Zhai,
Baolin Wang, Chunyan Zhang, Maxime Coquelin, Alexandre Torgue,
Kalyani Akula, Michal Simek, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
Trevor Gross, Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, asahi, linux-arm-kernel,
linux-kernel, imx, linux-amlogic, linux-arm-msm, linux-stm32,
rust-for-linux
The previous commit switched from a pointer to mutable data to a pointer
to immutable data, so let’s fix all users of this API.
Signed-off-by: Link Mauve <linkmauve@linkmauve.fr>
---
drivers/nvmem/apple-spmi-nvmem.c | 2 +-
drivers/nvmem/bcm-ocotp.c | 6 +++---
drivers/nvmem/imx-ocotp-scu.c | 6 +++---
drivers/nvmem/imx-ocotp.c | 6 +++---
drivers/nvmem/lan9662-otpc.c | 6 +++---
drivers/nvmem/lpc18xx_eeprom.c | 6 +++---
drivers/nvmem/max77759-nvmem.c | 4 ++--
drivers/nvmem/meson-efuse.c | 6 +++---
drivers/nvmem/qcom-spmi-sdam.c | 4 ++--
drivers/nvmem/qfprom.c | 6 +++---
drivers/nvmem/rave-sp-eeprom.c | 6 +++---
drivers/nvmem/snvs_lpgpr.c | 4 ++--
drivers/nvmem/sprd-efuse.c | 6 +++---
drivers/nvmem/stm32-bsec-optee-ta.c | 2 +-
drivers/nvmem/stm32-bsec-optee-ta.h | 4 ++--
drivers/nvmem/stm32-romem.c | 10 +++++-----
drivers/nvmem/zynqmp_nvmem.c | 6 +++---
17 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/drivers/nvmem/apple-spmi-nvmem.c b/drivers/nvmem/apple-spmi-nvmem.c
index 88614005d5ce..cbf25c53d048 100644
--- a/drivers/nvmem/apple-spmi-nvmem.c
+++ b/drivers/nvmem/apple-spmi-nvmem.c
@@ -29,7 +29,7 @@ static int apple_spmi_nvmem_probe(struct spmi_device *sdev)
.stride = 1,
.size = 0xffff,
.reg_read = (void *)regmap_bulk_read,
- .reg_write = (void *)regmap_bulk_write,
+ .reg_write_const = (void *)regmap_bulk_write,
};
regmap = devm_regmap_init_spmi_ext(sdev, &apple_spmi_regmap_config);
diff --git a/drivers/nvmem/bcm-ocotp.c b/drivers/nvmem/bcm-ocotp.c
index 2490f44caa40..5853ae0fe02d 100644
--- a/drivers/nvmem/bcm-ocotp.c
+++ b/drivers/nvmem/bcm-ocotp.c
@@ -179,11 +179,11 @@ static int bcm_otpc_read(void *context, unsigned int offset, void *val,
return 0;
}
-static int bcm_otpc_write(void *context, unsigned int offset, void *val,
+static int bcm_otpc_write(void *context, unsigned int offset, const void *val,
size_t bytes)
{
struct otpc_priv *priv = context;
- u32 *buf = val;
+ const u32 *buf = val;
u32 bytes_written;
u32 address = offset / priv->config->word_size;
int i, ret;
@@ -223,7 +223,7 @@ static struct nvmem_config bcm_otpc_nvmem_config = {
.word_size = 4,
.stride = 4,
.reg_read = bcm_otpc_read,
- .reg_write = bcm_otpc_write,
+ .reg_write_const = bcm_otpc_write,
};
static const struct of_device_id bcm_otpc_dt_ids[] = {
diff --git a/drivers/nvmem/imx-ocotp-scu.c b/drivers/nvmem/imx-ocotp-scu.c
index 517d83e11af2..57008228100f 100644
--- a/drivers/nvmem/imx-ocotp-scu.c
+++ b/drivers/nvmem/imx-ocotp-scu.c
@@ -178,11 +178,11 @@ static int imx_scu_ocotp_read(void *context, unsigned int offset,
}
static int imx_scu_ocotp_write(void *context, unsigned int offset,
- void *val, size_t bytes)
+ const void *val, size_t bytes)
{
struct ocotp_priv *priv = context;
struct arm_smccc_res res;
- u32 *buf = val;
+ const u32 *buf = val;
u32 tmp;
u32 index;
int ret;
@@ -226,7 +226,7 @@ static struct nvmem_config imx_scu_ocotp_nvmem_config = {
.stride = 1,
.owner = THIS_MODULE,
.reg_read = imx_scu_ocotp_read,
- .reg_write = imx_scu_ocotp_write,
+ .reg_write_const = imx_scu_ocotp_write,
};
static const struct of_device_id imx_scu_ocotp_dt_ids[] = {
diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c
index 108d78d7f6cb..36d4a37aed93 100644
--- a/drivers/nvmem/imx-ocotp.c
+++ b/drivers/nvmem/imx-ocotp.c
@@ -310,11 +310,11 @@ static void imx_ocotp_set_imx7_timing(struct ocotp_priv *priv)
writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING);
}
-static int imx_ocotp_write(void *context, unsigned int offset, void *val,
+static int imx_ocotp_write(void *context, unsigned int offset, const void *val,
size_t bytes)
{
struct ocotp_priv *priv = context;
- u32 *buf = val;
+ const u32 *buf = val;
int ret;
u32 ctrl;
@@ -483,7 +483,7 @@ static struct nvmem_config imx_ocotp_nvmem_config = {
.word_size = 4,
.stride = 1,
.reg_read = imx_ocotp_read,
- .reg_write = imx_ocotp_write,
+ .reg_write_const = imx_ocotp_write,
};
static const struct ocotp_params imx6q_params = {
diff --git a/drivers/nvmem/lan9662-otpc.c b/drivers/nvmem/lan9662-otpc.c
index 56fc19f092a7..7e4579c404d4 100644
--- a/drivers/nvmem/lan9662-otpc.c
+++ b/drivers/nvmem/lan9662-otpc.c
@@ -140,10 +140,10 @@ static int lan9662_otp_read(void *context, unsigned int offset,
}
static int lan9662_otp_write(void *context, unsigned int offset,
- void *_val, size_t bytes)
+ const void *_val, size_t bytes)
{
struct lan9662_otp *otp = context;
- u8 *val = _val;
+ const u8 *val = _val;
u8 data, newdata;
int i, rc = 0;
@@ -175,7 +175,7 @@ static struct nvmem_config otp_config = {
.stride = 1,
.word_size = 1,
.reg_read = lan9662_otp_read,
- .reg_write = lan9662_otp_write,
+ .reg_write_const = lan9662_otp_write,
.size = OTP_MEM_SIZE,
};
diff --git a/drivers/nvmem/lpc18xx_eeprom.c b/drivers/nvmem/lpc18xx_eeprom.c
index 504155e30bab..78a35ef095fb 100644
--- a/drivers/nvmem/lpc18xx_eeprom.c
+++ b/drivers/nvmem/lpc18xx_eeprom.c
@@ -87,7 +87,7 @@ static int lpc18xx_eeprom_busywait_until_prog(struct lpc18xx_eeprom_dev *eeprom)
}
static int lpc18xx_eeprom_gather_write(void *context, unsigned int reg,
- void *val, size_t bytes)
+ const void *val, size_t bytes)
{
struct lpc18xx_eeprom_dev *eeprom = context;
unsigned int offset = reg;
@@ -109,7 +109,7 @@ static int lpc18xx_eeprom_gather_write(void *context, unsigned int reg,
usleep_range(100, 200);
while (bytes) {
- writel(*(u32 *)val, eeprom->mem_base + offset);
+ writel(*(const u32 *)val, eeprom->mem_base + offset);
ret = lpc18xx_eeprom_busywait_until_prog(eeprom);
if (ret < 0)
return ret;
@@ -155,7 +155,7 @@ static struct nvmem_config lpc18xx_nvmem_config = {
.stride = 4,
.word_size = 4,
.reg_read = lpc18xx_eeprom_read,
- .reg_write = lpc18xx_eeprom_gather_write,
+ .reg_write_const = lpc18xx_eeprom_gather_write,
};
static int lpc18xx_eeprom_probe(struct platform_device *pdev)
diff --git a/drivers/nvmem/max77759-nvmem.c b/drivers/nvmem/max77759-nvmem.c
index 283000ec3a2c..86c025cfc2f6 100644
--- a/drivers/nvmem/max77759-nvmem.c
+++ b/drivers/nvmem/max77759-nvmem.c
@@ -59,7 +59,7 @@ static int max77759_nvmem_reg_read(void *priv, unsigned int offset,
}
static int max77759_nvmem_reg_write(void *priv, unsigned int offset,
- void *val, size_t bytes)
+ const void *val, size_t bytes)
{
struct max77759_nvmem *nvmem = priv;
DEFINE_FLEX(struct max77759_maxq_command, cmd, cmd, length,
@@ -99,7 +99,7 @@ static int max77759_nvmem_probe(struct platform_device *pdev)
.word_size = sizeof(u8),
.stride = sizeof(u8),
.reg_read = max77759_nvmem_reg_read,
- .reg_write = max77759_nvmem_reg_write,
+ .reg_write_const = max77759_nvmem_reg_write,
};
struct max77759_nvmem *nvmem;
diff --git a/drivers/nvmem/meson-efuse.c b/drivers/nvmem/meson-efuse.c
index d7f9ac99a212..94b24d11a1a3 100644
--- a/drivers/nvmem/meson-efuse.c
+++ b/drivers/nvmem/meson-efuse.c
@@ -27,12 +27,12 @@ static int meson_efuse_read(void *context, unsigned int offset,
}
static int meson_efuse_write(void *context, unsigned int offset,
- void *val, size_t bytes)
+ const void *val, size_t bytes)
{
struct meson_sm_firmware *fw = context;
int ret;
- ret = meson_sm_call_write(fw, (u8 *)val, bytes, SM_EFUSE_WRITE, offset,
+ ret = meson_sm_call_write(fw, (void *)val, bytes, SM_EFUSE_WRITE, offset,
bytes, 0, 0, 0);
return ret < 0 ? ret : 0;
@@ -83,7 +83,7 @@ static int meson_efuse_probe(struct platform_device *pdev)
econfig->stride = 1;
econfig->word_size = 1;
econfig->reg_read = meson_efuse_read;
- econfig->reg_write = meson_efuse_write;
+ econfig->reg_write_const = meson_efuse_write;
econfig->size = size;
econfig->priv = fw;
diff --git a/drivers/nvmem/qcom-spmi-sdam.c b/drivers/nvmem/qcom-spmi-sdam.c
index 4f1cca6eab71..6758cbc34577 100644
--- a/drivers/nvmem/qcom-spmi-sdam.c
+++ b/drivers/nvmem/qcom-spmi-sdam.c
@@ -81,7 +81,7 @@ static int sdam_read(void *priv, unsigned int offset, void *val,
return rc;
}
-static int sdam_write(void *priv, unsigned int offset, void *val,
+static int sdam_write(void *priv, unsigned int offset, const void *val,
size_t bytes)
{
struct sdam_chip *sdam = priv;
@@ -147,7 +147,7 @@ static int sdam_probe(struct platform_device *pdev)
sdam->sdam_config.size = sdam->size;
sdam->sdam_config.word_size = 1;
sdam->sdam_config.reg_read = sdam_read;
- sdam->sdam_config.reg_write = sdam_write;
+ sdam->sdam_config.reg_write_const = sdam_write;
sdam->sdam_config.priv = sdam;
nvmem = devm_nvmem_register(&pdev->dev, &sdam->sdam_config);
diff --git a/drivers/nvmem/qfprom.c b/drivers/nvmem/qfprom.c
index 1de3435df116..16b7f647a3f6 100644
--- a/drivers/nvmem/qfprom.c
+++ b/drivers/nvmem/qfprom.c
@@ -252,13 +252,13 @@ static int qfprom_enable_fuse_blowing(const struct qfprom_priv *priv,
*
* Return: 0 or -err.
*/
-static int qfprom_reg_write(void *context, unsigned int reg, void *_val,
+static int qfprom_reg_write(void *context, unsigned int reg, const void *_val,
size_t bytes)
{
struct qfprom_priv *priv = context;
struct qfprom_touched_values old;
int words = bytes / 4;
- u32 *value = _val;
+ const u32 *value = _val;
u32 blow_status;
int ret;
int i;
@@ -443,7 +443,7 @@ static int qfprom_probe(struct platform_device *pdev)
/* Only enable writing if we have SoC data and a valid clock */
if (priv->soc_data && priv->secclk)
- econfig.reg_write = qfprom_reg_write;
+ econfig.reg_write_const = qfprom_reg_write;
}
pm_runtime_enable(dev);
diff --git a/drivers/nvmem/rave-sp-eeprom.c b/drivers/nvmem/rave-sp-eeprom.c
index 9ecf3873cbb7..c703d303eb6c 100644
--- a/drivers/nvmem/rave-sp-eeprom.c
+++ b/drivers/nvmem/rave-sp-eeprom.c
@@ -278,10 +278,10 @@ static int rave_sp_eeprom_reg_read(void *eeprom, unsigned int offset,
}
static int rave_sp_eeprom_reg_write(void *eeprom, unsigned int offset,
- void *val, size_t bytes)
+ const void *val, size_t bytes)
{
return rave_sp_eeprom_access(eeprom, RAVE_SP_EEPROM_WRITE,
- offset, val, bytes);
+ offset, (void *)val, bytes);
}
static int rave_sp_eeprom_probe(struct platform_device *pdev)
@@ -331,7 +331,7 @@ static int rave_sp_eeprom_probe(struct platform_device *pdev)
config.add_legacy_fixed_of_cells = true;
config.size = size;
config.reg_read = rave_sp_eeprom_reg_read;
- config.reg_write = rave_sp_eeprom_reg_write;
+ config.reg_write_const = rave_sp_eeprom_reg_write;
config.word_size = 1;
config.stride = 1;
diff --git a/drivers/nvmem/snvs_lpgpr.c b/drivers/nvmem/snvs_lpgpr.c
index 89c27112320f..3e76d33dff20 100644
--- a/drivers/nvmem/snvs_lpgpr.c
+++ b/drivers/nvmem/snvs_lpgpr.c
@@ -50,7 +50,7 @@ static const struct snvs_lpgpr_cfg snvs_lpgpr_cfg_imx7d = {
.size = 16,
};
-static int snvs_lpgpr_write(void *context, unsigned int offset, void *val,
+static int snvs_lpgpr_write(void *context, unsigned int offset, const void *val,
size_t bytes)
{
struct snvs_lpgpr_priv *priv = context;
@@ -127,7 +127,7 @@ static int snvs_lpgpr_probe(struct platform_device *pdev)
cfg->size = dcfg->size;
cfg->owner = THIS_MODULE;
cfg->reg_read = snvs_lpgpr_read;
- cfg->reg_write = snvs_lpgpr_write;
+ cfg->reg_write_const = snvs_lpgpr_write;
nvmem = devm_nvmem_register(dev, cfg);
diff --git a/drivers/nvmem/sprd-efuse.c b/drivers/nvmem/sprd-efuse.c
index 1a7e4e5d8b86..f960fa8cb25c 100644
--- a/drivers/nvmem/sprd-efuse.c
+++ b/drivers/nvmem/sprd-efuse.c
@@ -192,7 +192,7 @@ static void sprd_efuse_set_prog_en(struct sprd_efuse *efuse, bool en)
}
static int sprd_efuse_raw_prog(struct sprd_efuse *efuse, u32 blk, bool doub,
- bool lock, u32 *data)
+ bool lock, const u32 *data)
{
u32 status;
int ret = 0;
@@ -321,7 +321,7 @@ static int sprd_efuse_read(void *context, u32 offset, void *val, size_t bytes)
return ret;
}
-static int sprd_efuse_write(void *context, u32 offset, void *val, size_t bytes)
+static int sprd_efuse_write(void *context, u32 offset, const void *val, size_t bytes)
{
struct sprd_efuse *efuse = context;
bool blk_double = efuse->data->blk_double;
@@ -410,7 +410,7 @@ static int sprd_efuse_probe(struct platform_device *pdev)
econfig.size = efuse->data->blk_nums * SPRD_EFUSE_BLOCK_WIDTH;
econfig.add_legacy_fixed_of_cells = true;
econfig.reg_read = sprd_efuse_read;
- econfig.reg_write = sprd_efuse_write;
+ econfig.reg_write_const = sprd_efuse_write;
econfig.priv = efuse;
econfig.dev = &pdev->dev;
nvmem = devm_nvmem_register(&pdev->dev, &econfig);
diff --git a/drivers/nvmem/stm32-bsec-optee-ta.c b/drivers/nvmem/stm32-bsec-optee-ta.c
index f89ce791dd12..3184b976b1f9 100644
--- a/drivers/nvmem/stm32-bsec-optee-ta.c
+++ b/drivers/nvmem/stm32-bsec-optee-ta.c
@@ -203,7 +203,7 @@ int stm32_bsec_optee_ta_read(struct tee_context *ctx, unsigned int offset,
/* stm32_bsec_optee_ta_write() - nvmem write access using PTA client driver */
int stm32_bsec_optee_ta_write(struct tee_context *ctx, unsigned int lower,
- unsigned int offset, void *buf, size_t bytes)
+ unsigned int offset, const void *buf, size_t bytes)
{ struct tee_shm *shm;
struct tee_ioctl_invoke_arg arg;
struct tee_param param[2];
diff --git a/drivers/nvmem/stm32-bsec-optee-ta.h b/drivers/nvmem/stm32-bsec-optee-ta.h
index 3966a0535179..74658a54fe57 100644
--- a/drivers/nvmem/stm32-bsec-optee-ta.h
+++ b/drivers/nvmem/stm32-bsec-optee-ta.h
@@ -50,7 +50,7 @@ int stm32_bsec_optee_ta_read(struct tee_context *ctx, unsigned int offset,
* On success, 0. On failure, -errno.
*/
int stm32_bsec_optee_ta_write(struct tee_context *ctx, unsigned int lower,
- unsigned int offset, void *buf, size_t bytes);
+ unsigned int offset, const void *buf, size_t bytes);
#else
@@ -72,7 +72,7 @@ static inline int stm32_bsec_optee_ta_read(struct tee_context *ctx,
static inline int stm32_bsec_optee_ta_write(struct tee_context *ctx,
unsigned int lower,
- unsigned int offset, void *buf,
+ unsigned int offset, const void *buf,
size_t bytes)
{
return -EOPNOTSUPP;
diff --git a/drivers/nvmem/stm32-romem.c b/drivers/nvmem/stm32-romem.c
index 82879b1c9eb9..622093b0755c 100644
--- a/drivers/nvmem/stm32-romem.c
+++ b/drivers/nvmem/stm32-romem.c
@@ -118,12 +118,12 @@ static int stm32_bsec_read(void *context, unsigned int offset, void *buf,
return 0;
}
-static int stm32_bsec_write(void *context, unsigned int offset, void *buf,
+static int stm32_bsec_write(void *context, unsigned int offset, const void *buf,
size_t bytes)
{
struct stm32_romem_priv *priv = context;
struct device *dev = priv->cfg.dev;
- u32 *buf32 = buf;
+ const u32 *buf32 = buf;
int ret, i;
/* Allow only writing complete 32-bits aligned words */
@@ -153,7 +153,7 @@ static int stm32_bsec_pta_read(void *context, unsigned int offset, void *buf,
return stm32_bsec_optee_ta_read(priv->ctx, offset, buf, bytes);
}
-static int stm32_bsec_pta_write(void *context, unsigned int offset, void *buf,
+static int stm32_bsec_pta_write(void *context, unsigned int offset, const void *buf,
size_t bytes)
{
struct stm32_romem_priv *priv = context;
@@ -239,10 +239,10 @@ static int stm32_romem_probe(struct platform_device *pdev)
return rc;
}
priv->cfg.reg_read = stm32_bsec_pta_read;
- priv->cfg.reg_write = stm32_bsec_pta_write;
+ priv->cfg.reg_write_const = stm32_bsec_pta_write;
} else {
priv->cfg.reg_read = stm32_bsec_read;
- priv->cfg.reg_write = stm32_bsec_write;
+ priv->cfg.reg_write_const = stm32_bsec_write;
}
}
diff --git a/drivers/nvmem/zynqmp_nvmem.c b/drivers/nvmem/zynqmp_nvmem.c
index d297ff150dc0..54905a608157 100644
--- a/drivers/nvmem/zynqmp_nvmem.c
+++ b/drivers/nvmem/zynqmp_nvmem.c
@@ -183,7 +183,7 @@ static int zynqmp_nvmem_read(void *context, unsigned int offset, void *val, size
}
static int zynqmp_nvmem_write(void *context,
- unsigned int offset, void *val, size_t bytes)
+ unsigned int offset, const void *val, size_t bytes)
{
int pufflag = 0;
@@ -194,7 +194,7 @@ static int zynqmp_nvmem_write(void *context,
pufflag = 1;
return zynqmp_efuse_access(context, offset,
- val, bytes, EFUSE_WRITE, pufflag);
+ (void *)val, bytes, EFUSE_WRITE, pufflag);
}
static const struct of_device_id zynqmp_nvmem_match[] = {
@@ -216,7 +216,7 @@ static int zynqmp_nvmem_probe(struct platform_device *pdev)
econfig.priv = dev;
econfig.add_legacy_fixed_of_cells = true;
econfig.reg_read = zynqmp_nvmem_read;
- econfig.reg_write = zynqmp_nvmem_write;
+ econfig.reg_write_const = zynqmp_nvmem_write;
return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &econfig));
}
--
2.55.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write
2026-07-15 19:55 [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write Link Mauve
2026-07-15 19:55 ` [PATCH v2 1/2] nvmem: core: deprecate reg_write callback and add reg_write_const Link Mauve
2026-07-15 19:55 ` [PATCH v2 2/2] nvmem: make all reg_write callbacks take const void * Link Mauve
@ 2026-07-16 9:03 ` Andy Shevchenko
2026-07-16 11:07 ` Link Mauve
2026-07-16 11:29 ` Link Mauve
2 siblings, 2 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-07-16 9:03 UTC (permalink / raw)
To: Link Mauve
Cc: Srinivas Kandagatla, Andy Shevchenko, Sven Peter, Janne Grunau,
Neal Gompa, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, Vladimir Zapolskiy, André Draszik,
Neil Armstrong, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
Orson Zhai, Baolin Wang, Chunyan Zhang, Maxime Coquelin,
Alexandre Torgue, Kalyani Akula, Michal Simek, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, asahi, linux-arm-kernel, linux-kernel, imx,
linux-amlogic, linux-arm-msm, linux-stm32, rust-for-linux
On Wed, Jul 15, 2026 at 09:55:16PM +0200, Link Mauve wrote:
> This callback used to take a mutable void * for no reason, which causes
> the compiler to be unaware that the val buffer should never be modified
> by the callback.
>
> This was found while drafting the nvmem-provider Rust abstraction.
>
> Thanks to the guidance of Andy Shevchenko, this now introduces a new
> callback and deprecates the existing one, with the goal of renaming the
> new one into the old one once no user remains in the kernel.
You forgot to use --base. It's unclear against what should be this applied.
I tried Linux Next (next-20260715), and it fails.
Yes, it applies against v7.2-rc3, but it means that this won't be applied on
top of maintainer's tree (which has something already that you have to take
into consideration).
For the record, the first version of the series was no go as the first patch
there breaks the things, like
drivers/nvmem/qfprom.c:446:22: error: incompatible function pointer types assigning to 'nvmem_reg_write_t' (aka 'int (*)(void *, unsigned int, const void *, unsigned long)') from 'int (void *, unsigned int, void *, size_t)' (aka 'int (void *, unsigned int, void *, unsigned long)') [-Wincompatible-function-pointer-types]
446 | econfig.reg_write = qfprom_reg_write;
| ^ ~~~~~~~~~~~~~~~~
1 error generated.
This version doesn't have this issue (at least with my smoke build tests
on x86_64).
Now, what catches me is that regmap_bulk_read() proto used for both cases in
drivers/nvmem/apple-spmi-nvmem.c without any changes. Which makes me think
that the approach can be done in a simpler way, id est converting users first
to use const specifiers in their callbacks first. But this trick is done with
using (void *) casting (?) which makes warning to disappear, which is
interesting case. So I think the Apple driver should actually use proper
protos and hence wrappers, otherwise it makes compiler blind, which is not
good. TL;DR: you should fix the Apple driver (and might more if any of them
use that dirty trick).
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write
2026-07-16 9:03 ` [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write Andy Shevchenko
@ 2026-07-16 11:07 ` Link Mauve
2026-07-16 17:48 ` Andy Shevchenko
2026-07-16 11:29 ` Link Mauve
1 sibling, 1 reply; 8+ messages in thread
From: Link Mauve @ 2026-07-16 11:07 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Link Mauve, Srinivas Kandagatla, Andy Shevchenko, Sven Peter,
Janne Grunau, Neal Gompa, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Vladimir Zapolskiy,
André Draszik, Neil Armstrong, Kevin Hilman, Jerome Brunet,
Martin Blumenstingl, Orson Zhai, Baolin Wang, Chunyan Zhang,
Maxime Coquelin, Alexandre Torgue, Kalyani Akula, Michal Simek,
Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, asahi, linux-arm-kernel,
linux-kernel, imx, linux-amlogic, linux-arm-msm, linux-stm32,
rust-for-linux
[-- Attachment #1: Type: text/plain, Size: 3385 bytes --]
On Thu, Jul 16, 2026 at 12:03:17PM +0300, Andy Shevchenko wrote:
> On Wed, Jul 15, 2026 at 09:55:16PM +0200, Link Mauve wrote:
> > This callback used to take a mutable void * for no reason, which causes
> > the compiler to be unaware that the val buffer should never be modified
> > by the callback.
> >
> > This was found while drafting the nvmem-provider Rust abstraction.
> >
> > Thanks to the guidance of Andy Shevchenko, this now introduces a new
> > callback and deprecates the existing one, with the goal of renaming the
> > new one into the old one once no user remains in the kernel.
>
> You forgot to use --base. It's unclear against what should be this applied.
> I tried Linux Next (next-20260715), and it fails.
>
> Yes, it applies against v7.2-rc3, but it means that this won't be applied on
> top of maintainer's tree (which has something already that you have to take
> into consideration).
Indeed I developed against Linus’s master, I’ll rebase on linux-next for
v3.
>
> For the record, the first version of the series was no go as the first patch
> there breaks the things, like
>
> drivers/nvmem/qfprom.c:446:22: error: incompatible function pointer types assigning to 'nvmem_reg_write_t' (aka 'int (*)(void *, unsigned int, const void *, unsigned long)') from 'int (void *, unsigned int, void *, size_t)' (aka 'int (void *, unsigned int, void *, unsigned long)') [-Wincompatible-function-pointer-types]
> 446 | econfig.reg_write = qfprom_reg_write;
> | ^ ~~~~~~~~~~~~~~~~
> 1 error generated.
>
> This version doesn't have this issue (at least with my smoke build tests
> on x86_64).
Yup, I enabled the drivers but didn’t select COMPILE_TEST, so they
didn’t actually build and I assumed everything was correct… This won’t
happen again.
>
> Now, what catches me is that regmap_bulk_read() proto used for both cases in
> drivers/nvmem/apple-spmi-nvmem.c without any changes. Which makes me think
> that the approach can be done in a simpler way, id est converting users first
> to use const specifiers in their callbacks first. But this trick is done with
> using (void *) casting (?) which makes warning to disappear, which is
> interesting case. So I think the Apple driver should actually use proper
> protos and hence wrappers, otherwise it makes compiler blind, which is not
> good. TL;DR: you should fix the Apple driver (and might more if any of them
> use that dirty trick).
This series only affects the reg_write callback, not reg_read, so it’s
to be expected that regmap_bulk_read() keeps its void * parameter as it
will modify it, it’s regmap_bulk_write() which correctly takes const
void *. The Apple driver completely removes all function pointer safety
by casting the function into void *, although that’s not due to const
incompatibility but due to the first argument being struct regmap *
instead of void *.
I’ve attached a patch fixing this particular issue, I will include it in
my v3 if that’s ok with you (or it could go as a different series, I
don’t care much).
I think I’ve found another bug in that driver, it says .max_register =
0xffff but .size = 0xffff, one or the other is probably off-by-one, and
I suspect .size should be 0x10000 instead.
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
Thanks!
--
Link Mauve
[-- Attachment #2: 0001-nvmem-apple-spmi-improve-calling-safety-with-wrapper.patch --]
[-- Type: text/plain, Size: 1873 bytes --]
From ec85ce97c6c835d99aa28b11b78af2744b45dc49 Mon Sep 17 00:00:00 2001
From: Link Mauve <linkmauve@linkmauve.fr>
Date: Thu, 16 Jul 2026 12:59:13 +0200
Subject: [PATCH] nvmem: apple-spmi: improve calling safety with wrapper
functions
This driver used to cast the regmap_bulk_*() functions to void *,
bypassing any compiler safety around incompatible function pointers.
With two small helpers, which just convert the void * priv parameter
into the wanted struct regmap *, we can remove the void * cast
altogether.
Signed-off-by: Link Mauve <linkmauve@linkmauve.fr>
---
drivers/nvmem/apple-spmi-nvmem.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/drivers/nvmem/apple-spmi-nvmem.c b/drivers/nvmem/apple-spmi-nvmem.c
index cbf25c53d048..81d9e242c836 100644
--- a/drivers/nvmem/apple-spmi-nvmem.c
+++ b/drivers/nvmem/apple-spmi-nvmem.c
@@ -18,6 +18,20 @@ static const struct regmap_config apple_spmi_regmap_config = {
.max_register = 0xffff,
};
+static int apple_spmi_nvmem_read(void *priv, unsigned int offset,
+ void *val, size_t bytes)
+{
+ struct regmap *regmap = priv;
+ return regmap_bulk_read(regmap, 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);
+}
+
static int apple_spmi_nvmem_probe(struct spmi_device *sdev)
{
struct regmap *regmap;
@@ -28,8 +42,8 @@ static int apple_spmi_nvmem_probe(struct spmi_device *sdev)
.word_size = 1,
.stride = 1,
.size = 0xffff,
- .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,
};
regmap = devm_regmap_init_spmi_ext(sdev, &apple_spmi_regmap_config);
--
2.55.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write
2026-07-16 9:03 ` [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write Andy Shevchenko
2026-07-16 11:07 ` Link Mauve
@ 2026-07-16 11:29 ` Link Mauve
2026-07-16 17:50 ` Andy Shevchenko
1 sibling, 1 reply; 8+ messages in thread
From: Link Mauve @ 2026-07-16 11:29 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Link Mauve, Srinivas Kandagatla, Andy Shevchenko, Sven Peter,
Janne Grunau, Neal Gompa, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Vladimir Zapolskiy,
André Draszik, Neil Armstrong, Kevin Hilman, Jerome Brunet,
Martin Blumenstingl, Orson Zhai, Baolin Wang, Chunyan Zhang,
Maxime Coquelin, Alexandre Torgue, Kalyani Akula, Michal Simek,
Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
Alexandre Courbot, Onur Özkan, asahi, linux-arm-kernel,
linux-kernel, imx, linux-amlogic, linux-arm-msm, linux-stm32,
rust-for-linux
On Thu, Jul 16, 2026 at 12:03:17PM +0300, Andy Shevchenko wrote:
[…]
> ..... TL;DR: you should fix the Apple driver (and might more if any of them
> use that dirty trick).
It was the only one of the drivers/nvmem/ to do that. Three other
drivers use a pattern where they merge read and write operations into a
single access function with a type=read/write parameter, so const safety
can’t work there and I’ll continue casting from const void * to void *
in the write function to keep that pattern working.
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
--
Link Mauve
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write
2026-07-16 11:07 ` Link Mauve
@ 2026-07-16 17:48 ` Andy Shevchenko
0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-07-16 17:48 UTC (permalink / raw)
To: Link Mauve
Cc: Srinivas Kandagatla, Andy Shevchenko, Sven Peter, Janne Grunau,
Neal Gompa, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, Vladimir Zapolskiy, André Draszik,
Neil Armstrong, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
Orson Zhai, Baolin Wang, Chunyan Zhang, Maxime Coquelin,
Alexandre Torgue, Kalyani Akula, Michal Simek, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, asahi, linux-arm-kernel, linux-kernel, imx,
linux-amlogic, linux-arm-msm, linux-stm32, rust-for-linux
On Thu, Jul 16, 2026 at 01:07:26PM +0200, Link Mauve wrote:
> On Thu, Jul 16, 2026 at 12:03:17PM +0300, Andy Shevchenko wrote:
> > On Wed, Jul 15, 2026 at 09:55:16PM +0200, Link Mauve wrote:
...
> I’ve attached a patch fixing this particular issue, I will include it in
> my v3 if that’s ok with you (or it could go as a different series, I
> don’t care much).
Works for me.
> I think I’ve found another bug in that driver, it says .max_register =
> 0xffff but .size = 0xffff, one or the other is probably off-by-one, and
> I suspect .size should be 0x10000 instead.
Yeah, max_register means offset of the last _accessible_ register.
So, 0xffff sounds about right there. As for size being 0xffff, I weakly
remember that there was a discussion about these values. Can you dig the
lore archive?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write
2026-07-16 11:29 ` Link Mauve
@ 2026-07-16 17:50 ` Andy Shevchenko
0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2026-07-16 17:50 UTC (permalink / raw)
To: Link Mauve
Cc: Srinivas Kandagatla, Andy Shevchenko, Sven Peter, Janne Grunau,
Neal Gompa, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
Fabio Estevam, Vladimir Zapolskiy, André Draszik,
Neil Armstrong, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
Orson Zhai, Baolin Wang, Chunyan Zhang, Maxime Coquelin,
Alexandre Torgue, Kalyani Akula, Michal Simek, Miguel Ojeda,
Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
Onur Özkan, asahi, linux-arm-kernel, linux-kernel, imx,
linux-amlogic, linux-arm-msm, linux-stm32, rust-for-linux
On Thu, Jul 16, 2026 at 01:29:44PM +0200, Link Mauve wrote:
> On Thu, Jul 16, 2026 at 12:03:17PM +0300, Andy Shevchenko wrote:
[…]
> > TL;DR: you should fix the Apple driver (and might more if any of them
> > use that dirty trick).
>
> It was the only one of the drivers/nvmem/ to do that. Three other
> drivers use a pattern where they merge read and write operations into a
> single access function with a type=read/write parameter, so const safety
> can’t work there and I’ll continue casting from const void * to void *
> in the write function to keep that pattern working.
I meant all the driver in the kernel that are going to be affected by this
change.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-07-16 17:50 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-15 19:55 [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write Link Mauve
2026-07-15 19:55 ` [PATCH v2 1/2] nvmem: core: deprecate reg_write callback and add reg_write_const Link Mauve
2026-07-15 19:55 ` [PATCH v2 2/2] nvmem: make all reg_write callbacks take const void * Link Mauve
2026-07-16 9:03 ` [PATCH v2 0/2] nvmem: fix a const-unsoundness in reg_write Andy Shevchenko
2026-07-16 11:07 ` Link Mauve
2026-07-16 17:48 ` Andy Shevchenko
2026-07-16 11:29 ` Link Mauve
2026-07-16 17:50 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox