[PATCH 14/15] nvmem: core: provide own priv pointer in post process callback

Marco Felsch m.felsch at pengutronix.de
Mon Aug 4 07:37:00 PDT 2025


To remove the global nvmem->cell_post_process() and further sync our
code base with Linux, port the following commit:

| commit 8a134fd9f9323f4c39ec27055b3d3723cfb5c1e9
| Author: Michael Walle <michael at walle.cc>
| Date:   Tue Apr 4 18:21:28 2023 +0100
|
|     nvmem: core: provide own priv pointer in post process callback
|
|     It doesn't make any more sense to have a opaque pointer set up by the
|     nvmem device. Usually, the layout isn't associated with a particular
|     nvmem device. Instead, let the caller who set the post process callback
|     provide the priv pointer.
|
|     Signed-off-by: Michael Walle <michael at walle.cc>
|     Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
|     Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla at linaro.org>
|     Link: https://lore.kernel.org/r/20230404172148.82422-21-srinivas.kandagatla@linaro.org
|     Signed-off-by: Greg Kroah-Hartman <gregkh at linuxfoundation.org>

Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
---
 drivers/nvmem/core.c           | 4 +++-
 include/linux/nvmem-provider.h | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index d9b3e3bc8c1b9016975480d45da53f8c77a52881..7f4fd329c196efa3baac2c97016d6651d4c140a3 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -23,6 +23,7 @@ struct nvmem_cell_entry {
 	int			bit_offset;
 	int			nbits;
 	nvmem_cell_post_process_t read_post_process;
+	void			*priv;
 	struct device_node	*np;
 	struct nvmem_device	*nvmem;
 	struct list_head	node;
@@ -244,6 +245,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
 	cell->bytes = info->bytes;
 	cell->name = info->name;
 	cell->read_post_process = info->read_post_process;
+	cell->priv = info->priv;
 
 	cell->bit_offset = info->bit_offset;
 	cell->nbits = info->nbits;
@@ -836,7 +838,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
 		nvmem_shift_read_buffer_in_place(cell, buf);
 
 	if (cell->read_post_process) {
-		rc = cell->read_post_process(nvmem->priv, id, index,
+		rc = cell->read_post_process(cell->priv, id, index,
 				cell->offset, buf, cell->bytes);
 		if (rc)
 			return rc;
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index a8aa6b741395f810315d7f018d62e4ef64e618a5..e1e7d8871d67465157191e7e6a46b400a285e834 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -40,6 +40,7 @@ typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index,
  * @np:		Optional device_node pointer.
  * @read_post_process:	Callback for optional post processing of cell data
  *			on reads.
+ * @priv:	Opaque data passed to the read_post_process hook.
  */
 struct nvmem_cell_info {
 	const char		*name;
@@ -50,6 +51,7 @@ struct nvmem_cell_info {
 	unsigned int		nbits;
 	struct device_node	*np;
 	nvmem_cell_post_process_t read_post_process;
+	void			*priv;
 };
 
 /**

-- 
2.39.5




More information about the barebox mailing list