[PATCH v8 3/8] nvmem: core: take a reference on dev.of_node in nvmem_register()
Michael Walle
michael at walle.cc
Thu Oct 15 02:12:28 PDT 2026
On Wed Oct 14, 2026 at 8:40 AM CEST, Manikandan Muralidharan wrote:
> nvmem_register() stores config->of_node (or config->dev->of_node)
> into nvmem->dev.of_node without taking its own reference. Callers
> that get the node via of_get_compatible_child() etc. and drop their
> reference right after registering leave nvmem->dev.of_node backed by
> no reference at all.
>
> Take an of_node_get() when assigning nvmem->dev.of_node and release
> it in nvmem_release(). Existing callers that hold their own get/put
> pair around the registration call need no changes, since get/put on
> a device_node is per-holder and independent of core now also holding
> one.
>
> Suggested-by: Michael Walle <mwalle at kernel.org>
> Signed-off-by: Manikandan Muralidharan <manikandan.m at microchip.com>
Nice!
Did you check if any callers are also taking a reference, which
might not be needed anymore now.
Reviewed-by: Michael Walle <mwalle at kernel.org>
-michael
> ---
> drivers/nvmem/core.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 0556d140170a..98192597b935 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -541,6 +541,7 @@ static void nvmem_release(struct device *dev)
>
> ida_free(&nvmem_ida, nvmem->id);
> gpiod_put(nvmem->wp_gpio);
> + of_node_put(nvmem->dev.of_node);
> kfree(nvmem->ops);
> kfree(nvmem);
> }
> @@ -950,9 +951,9 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
> nvmem->keepout = config->keepout;
> nvmem->nkeepout = config->nkeepout;
> if (config->of_node)
> - nvmem->dev.of_node = config->of_node;
> + nvmem->dev.of_node = of_node_get(config->of_node);
> else
> - nvmem->dev.of_node = config->dev->of_node;
> + nvmem->dev.of_node = of_node_get(config->dev->of_node);
>
> switch (config->id) {
> case NVMEM_DEVID_NONE:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 297 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-mtd/attachments/20261015/bc359452/attachment.sig>
More information about the linux-mtd
mailing list