All of lore.kernel.org
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, Michael Walle <michael@walle.cc>,
	Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Subject: [PATCH v2 16/22] nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of()
Date: Mon,  6 Feb 2023 13:43:50 +0000	[thread overview]
Message-ID: <20230206134356.839737-17-srinivas.kandagatla@linaro.org> (raw)
In-Reply-To: <20230206134356.839737-1-srinivas.kandagatla@linaro.org>

From: Michael Walle <michael@walle.cc>

Convert nvmem_add_cells_from_of() to use the new nvmem_add_one_cell().
This will remove duplicate code and it will make it possible to add a
hook to a nvmem layout in between, which can change fields before the
cell is finally added.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 drivers/nvmem/core.c | 45 ++++++++++++++------------------------------
 1 file changed, 14 insertions(+), 31 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 58f8e33e7a8c..174ef3574e07 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -688,15 +688,14 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem)
 
 static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 {
-	struct device_node *parent, *child;
 	struct device *dev = &nvmem->dev;
-	struct nvmem_cell_entry *cell;
+	struct device_node *child;
 	const __be32 *addr;
-	int len;
+	int len, ret;
 
-	parent = dev->of_node;
+	for_each_child_of_node(dev->of_node, child) {
+		struct nvmem_cell_info info = {0};
 
-	for_each_child_of_node(parent, child) {
 		addr = of_get_property(child, "reg", &len);
 		if (!addr)
 			continue;
@@ -706,40 +705,24 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 			return -EINVAL;
 		}
 
-		cell = kzalloc(sizeof(*cell), GFP_KERNEL);
-		if (!cell) {
-			of_node_put(child);
-			return -ENOMEM;
-		}
-
-		cell->nvmem = nvmem;
-		cell->offset = be32_to_cpup(addr++);
-		cell->bytes = be32_to_cpup(addr);
-		cell->name = kasprintf(GFP_KERNEL, "%pOFn", child);
+		info.offset = be32_to_cpup(addr++);
+		info.bytes = be32_to_cpup(addr);
+		info.name = kasprintf(GFP_KERNEL, "%pOFn", child);
 
 		addr = of_get_property(child, "bits", &len);
 		if (addr && len == (2 * sizeof(u32))) {
-			cell->bit_offset = be32_to_cpup(addr++);
-			cell->nbits = be32_to_cpup(addr);
+			info.bit_offset = be32_to_cpup(addr++);
+			info.nbits = be32_to_cpup(addr);
 		}
 
-		if (cell->nbits)
-			cell->bytes = DIV_ROUND_UP(
-					cell->nbits + cell->bit_offset,
-					BITS_PER_BYTE);
+		info.np = of_node_get(child);
 
-		if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
-			dev_err(dev, "cell %s unaligned to nvmem stride %d\n",
-				cell->name, nvmem->stride);
-			/* Cells already added will be freed later. */
-			kfree_const(cell->name);
-			kfree(cell);
+		ret = nvmem_add_one_cell(nvmem, &info);
+		kfree(info.name);
+		if (ret) {
 			of_node_put(child);
-			return -EINVAL;
+			return ret;
 		}
-
-		cell->np = of_node_get(child);
-		nvmem_cell_entry_add(cell);
 	}
 
 	return 0;
-- 
2.25.1


  parent reply	other threads:[~2023-02-06 13:45 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06 13:43 [PATCH v2 00/22] nvmem: patches for 6.3 Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 01/22] nvmem: sunxi_sid: Drop the workaround on A64 Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 02/22] dt-bindings: nvmem: Fix qcom,qfprom compatibles enum ordering Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 03/22] dt-bindings: nvmem: Add compatible for MSM8976 Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 04/22] dt-bindings: nvmem: qfprom: add sdm670 compatible Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 05/22] dt-bindings: nvmem: Add compatible for SM8150 Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 06/22] dt-bindings: nvmem: Add compatible for SM8250 Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 07/22] nvmem: core: remove spurious white space Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 08/22] net: add helper eth_addr_add() Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 09/22] of: base: add of_parse_phandle_with_optional_args() Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 10/22] of: property: make #.*-cells optional for simple props Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 11/22] of: property: add #nvmem-cell-cells property Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 12/22] nvmem: core: add an index parameter to the cell Srinivas Kandagatla
2023-02-10 11:01   ` Alexander Stein
2023-02-06 13:43 ` [PATCH v2 13/22] nvmem: core: move struct nvmem_cell_info to nvmem-provider.h Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 14/22] nvmem: core: drop the removal of the cells in nvmem_add_cells() Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 15/22] nvmem: core: add nvmem_add_one_cell() Srinivas Kandagatla
2023-02-06 13:43 ` Srinivas Kandagatla [this message]
2023-02-06 13:43 ` [PATCH v2 17/22] nvmem: stm32: add OP-TEE support for STM32MP13x Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 18/22] nvmem: stm32: detect bsec pta presence for STM32MP15x Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 19/22] nvmem: rave-sp-eeprm: fix kernel-doc bad line warning Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 20/22] nvmem: qcom-spmi-sdam: register at device init time Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 21/22] dt-bindings: nvmem: qfprom: add IPQ8074 compatible Srinivas Kandagatla
2023-02-06 13:43 ` [PATCH v2 22/22] nvmem: stm32: fix OPTEE dependency Srinivas Kandagatla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230206134356.839737-17-srinivas.kandagatla@linaro.org \
    --to=srinivas.kandagatla@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael@walle.cc \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.