[PATCH 03/11] nvmem: exclude disconnected providers from callback admission
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Tue Nov 17 12:07:14 PST 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] nvmem: SRCU held across nvmem_cell_entry_add() without
rechecking ops
--
commit f2f33b1005de81978c098ebed41d0fc8a71c6f7e
Author: James Hilliard <james.hilliard1 at gmail.com>
nvmem: exclude disconnected providers from callback admission
This commit protects sysfs permission checks, cell addition, DT fixups,
layout population, and device matching with the provider's SRCU domain,
and serializes provider disconnection against consumer lookup under
nvmem_mutex.
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 73aa53145f0b7..c41266241f3f9 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
[ ... ]
> @@ -673,6 +682,10 @@ int nvmem_add_one_cell(struct nvmem_device *nvmem,
> struct nvmem_cell_entry *cell;
> int rval;
>
> + guard(srcu)(&nvmem->srcu);
> + if (!srcu_dereference(nvmem->ops, &nvmem->srcu))
> + return -ENODEV;
> +
> cell = kzalloc_obj(*cell);
> if (!cell)
> return -ENOMEM;
[Severity: Medium]
Does holding nvmem->srcu across nvmem_cell_entry_add() invert the lock
ordering with nvmem_notifier.rwsem and allow cells to be added after
nvmem_unregister() has disconnected the provider?
nvmem_cell_entry_add() calls blocking_notifier_call_chain(&nvmem_notifier,
NVMEM_CELL_ADD, cell) while nvmem->srcu is held. All nvmem->srcu instances
are initialized with init_srcu_struct() and share a single static lockdep
class. Notifier callbacks such as cp500_nvmem() call nvmem_register() and
nvmem_unregister() under nvmem_notifier.rwsem, which on error unwind or
removal calls nvmem_disconnect() -> synchronize_srcu(&nvmem->srcu):
CPU0 CPU1
---- ----
lock(&nvmem->srcu)
down_read(&nvmem_notifier.rwsem)
down_read(&nvmem_notifier.rwsem)
synchronize_srcu(&nvmem->srcu)
*** DEADLOCK ***
CPU0: nvmem_add_one_cell() -> nvmem_cell_entry_add()
CPU1: blocking_notifier_call_chain() -> cp500_nvmem() -> nvmem_register()
-> nvmem_disconnect()
In addition, nvmem_add_one_cell() only checks nvmem->ops at entry before
nvmem_cell_entry_add() acquires nvmem_mutex:
drivers/nvmem/core.c:nvmem_cell_entry_add() {
scoped_guard(mutex, &nvmem_mutex)
list_add_tail(&cell->node, &cell->nvmem->cells);
blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_ADD, cell);
}
If nvmem_unregister() runs concurrently, it sends NVMEM_REMOVE, clears
nvmem->ops under nvmem_mutex in nvmem_disconnect(), and waits in
synchronize_srcu(). An in-flight nvmem_add_one_cell() that passed the
initial check then acquires nvmem_mutex without rechecking nvmem->ops,
appends the cell to the disconnected provider, and emits NVMEM_CELL_ADD
after NVMEM_REMOVE.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-submit-nvmem-provider-lifetime-v1-v1-0-3cfbd48812b5@gmail.com?part=3
More information about the linux-mtd
mailing list