[PATCH 02/11] nvmem: drain keepout and cell post-processing accesses
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Tue Nov 17 11:50:06 PST 2026
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] nvmem: core: race condition in __nvmem_reg_write() during
WP GPIO toggling [1]
--
commit 1a5a4f5f38aeaf6b1486ab8a21e16285a6795aae
Author: James Hilliard <james.hilliard1 at gmail.com>
nvmem: drain keepout and cell post-processing accesses
This commit extends SRCU read-lock protection and nvmem->ops validation to
cover keepout region handling in nvmem_reg_read() and nvmem_reg_write() as
well as cell post-processing in __nvmem_cell_read().
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 802637f375f8b..73aa53145f0b7 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
[ ... ]
> @@ -173,6 +177,10 @@ 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)
> {
> + guard(srcu)(&nvmem->srcu);
> + if (!srcu_dereference(nvmem->ops, &nvmem->srcu))
> + return -ENODEV;
> +
> if (!nvmem->nkeepout)
> return __nvmem_reg_write(nvmem, offset, val, bytes);
[Severity: Critical]
This problem wasn't introduced by this patch, but can concurrent callers of
__nvmem_reg_write() race on nvmem->wp_gpio [1]?
drivers/nvmem/core.c:__nvmem_reg_write() {
...
ret = gpiod_set_value_cansleep(nvmem->wp_gpio, 0);
if (ret)
return ret;
wr_ok = ops->reg_write(nvmem->priv, offset, val, bytes);
ret = gpiod_set_value_cansleep(nvmem->wp_gpio, 1);
...
}
Nothing serializes the write-protect GPIO transitions across concurrent
writes:
CPU0 CPU1
__nvmem_reg_write() __nvmem_reg_write()
gpiod_set_value_cansleep(wp, 0)
gpiod_set_value_cansleep(wp, 0)
ops->reg_write(...)
gpiod_set_value_cansleep(wp, 1)
ops->reg_write(...) <-- WP active
CPU0 re-asserts write protection while CPU1 is still executing
ops->reg_write(), which can cause dropped writes, hardware errors, or
silent data corruption.
[1] https://sashiko.dev/#/bug/linux-d7d845df-786a-40cf-b43c-f4ce2e295c82
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-submit-nvmem-provider-lifetime-v1-v1-0-3cfbd48812b5@gmail.com?part=2
More information about the linux-mtd
mailing list