From patchwork Thu Sep 1 22:18:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 12963395 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8BB05ECAAD2 for ; Thu, 1 Sep 2022 22:26:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=K+KbE2IQYk8vQvVDp8Det9EI9EO04wu3Xzu6iXOXIPo=; b=Ly9avT7HTC6qPf KGJYE3gyVOlP0hxmmrE3ILb8Fol3IzD9NufgpA2HqJI/3twRCarJEpSQn8EFYH2gqNpAgB4OgZuEU cMsojnyAFWtCp6Yq0VulSkaBUyJtrjsKnfcGb9/1Vwryx976Cs3wSxN8FsoYFxDvOFtZw6AsQXA3h 2N/jFN/Fi7PRn8cizrpkRhXBP0pq9ngrjgfyPb2rCOE/Qehh6eRikCmKRPJr0eOk/U5ljjixNWbn4 ABmWmxDfk4MT+B5JN9RX2Gmb2il87F5jJfvRPLOcAmCCyGBh3w+PZEpLS9kfWpLp7LVjAl+zLBpHm DiGxcyAgDskcHvkAeTCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTscF-00FJCO-Sd; Thu, 01 Sep 2022 22:24:52 +0000 Received: from 0001.3ffe.de ([159.69.201.130] helo=mail.3ffe.de) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTsWt-00FEde-Vu; Thu, 01 Sep 2022 22:19:24 +0000 Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 7B95521C6; Fri, 2 Sep 2022 00:19:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1662070751; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mp1Anrg7RvtSnRweTlYNf0dthMjXidxRy4304FCk4PI=; b=WMetcScz3c92KdUF5vL3GP2woDolbQbrOFvSwM5HWetbrnJdWEQ6AIbOZwK0HfdJ0WBQ9x UjSKDDX+BV3qpnl25BoRj1Z9XPG1AZ4cOAy8Cq1/CBasQ9PMrm4dnbJZ0kkWcwXhzntikR 7NwDg6LelDwwbKzOHStD6BqRQ7nv7Zltus8m2lPifwgV8vUQif5jvYTvVMWsDF/d36znFH wmDoQWSmNnaoJ9z6vzLVRBYzGDaTt+V42ZfRkphxjpwfo4xXq3uCaYmEJzUlOiT4CP/+ju HnaxMnnL5cCH/fohA8JuaG6z42FatZoCJZfuZeyyFxTum7Tz9vrR01wPnyn3gg== From: Michael Walle To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Srinivas Kandagatla , Shawn Guo , Li Yang , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Frank Rowand Cc: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ahmad Fatoum , Philipp Zabel , Michael Walle Subject: [PATCH v2 07/20] nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of() Date: Fri, 2 Sep 2022 00:18:44 +0200 Message-Id: <20220901221857.2600340-8-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220901221857.2600340-1-michael@walle.cc> References: <20220901221857.2600340-1-michael@walle.cc> MIME-Version: 1.0 X-Spam: Yes X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220901_151920_257826_3AE519E8 X-CRM114-Status: GOOD ( 14.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- changes since v1: - new patch drivers/nvmem/core.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 3dfd149374a8..c640d411ab15 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -687,15 +687,15 @@ 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; @@ -711,34 +711,24 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) 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;