Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1020584rwb; Fri, 18 Nov 2022 11:27:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf4WCA5jjZdDHSeyUflxOsL/kOOaJXj68Ub5tuXFsewfMmmZlUIWAoIUYhuCu9wY919QJiwc X-Received: by 2002:a17:902:e04b:b0:186:94b8:5980 with SMTP id x11-20020a170902e04b00b0018694b85980mr925657plx.113.1668799633419; Fri, 18 Nov 2022 11:27:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668799633; cv=none; d=google.com; s=arc-20160816; b=t9gBMGzUckB//iiijhMCcv6fvM32K+IkzpiZZHVceqlU5CRi+hcTNgCdkHhgfFq+ht +3FptC4GGLQtqPqpBn4xQeGkx5O4euq/Y3eww4VuLawbMWaI7ZO31dguZAtKN2a61G3x OYee7peao3n6HCddHtL9ETbZnlZ57zH5Qw9333mzv8Lxa0u/q2L10qvWcD3HjX/LGE7j ++qwCxqk3oL35Hu3GsVvfQ56ZH32V3nIdJW/MZODwWeNah59M+XOkNV4s4Xo2maP1AsR Jg4231jsOBcYpMdw3JOwpSqkpJccJrOmqhrowHhv9N9lFO2G+XHgMjpE9cJ9R0UbYPnv DUUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+XtMYbFsZ///Ed8CqwvzeDSkfjfKPwewOXH9ohdph+M=; b=RVeTv9rLrQeG6v2vdq3c3PVAjJiqIFxAOVqhlu2IxLJ1/UJf+mG1y4OAcGn0BZGKq0 YPmJsTrn/v9K1N/h5iEFyx9SGRwbodKddWX2HuvAuXJ1DMceV9A7HFayx81wdjcdFwv8 aXqld2752hreZtV4ylKE0wnBMmXn4h4Nv693GtyvV3WPt/5mECna6FfqrGt/LPzzSlrA iqCbhgNAfPTftcSs7gKMArGDanoFJla3iDuvHCsTLENHxJBD3lRcocoJ8v+i7NYiEEOu 2S5s/ywGgfH+ZiMrlRVU/h6yHu6znbL/yS+rvFt1IcilrQ6yUuQw93s3I0fx11LGxAbs /3FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=UNLo7mwI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a18-20020a17090ad81200b00212ca8e7457si3999222pjv.133.2022.11.18.11.27.01; Fri, 18 Nov 2022 11:27:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=UNLo7mwI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242904AbiKRSxf (ORCPT + 90 others); Fri, 18 Nov 2022 13:53:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242865AbiKRSvy (ORCPT ); Fri, 18 Nov 2022 13:51:54 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DE578FE77; Fri, 18 Nov 2022 10:51:53 -0800 (PST) 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 D33C7249C; Fri, 18 Nov 2022 19:51:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1668797489; 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=+XtMYbFsZ///Ed8CqwvzeDSkfjfKPwewOXH9ohdph+M=; b=UNLo7mwIh8hcCGM7VsZ9FolzHNB5EBh+A6lA8ZurYJrDFPeAaYsn0DdOScAeKK088kUrRo jNDb6/MMwbVMmnr5dCIKKyXkbM0uhKgO3ANXRcOSKfS/ELPKuAqRTZmYVJZLPD3EeANoak d23rk0pieJDMqe4uzusBIJfjkwnLJ+UgZgpKi8vwzWg74mxMhn75EqszsiCL0MZCGL+2P4 DQ67dj3p+6/9lvoL8wnrpGbAXME+0ra0ossgT0jYYiB0skgqlzhr/D+fVmuNJOKXQ0E9Ih kiIvTfYBkOUmw4kv7R7n3FnU88FDpQvU5Xo3nPLTAsPhCUq+aAEqqKRjaHvR9Q== From: Michael Walle To: Jonathan Corbet , Srinivas Kandagatla , Miquel Raynal , Rob Herring , Frank Rowand Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Michael Walle Subject: [PATCH v3 08/18] nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of() Date: Fri, 18 Nov 2022 19:51:08 +0100 Message-Id: <20221118185118.1190044-9-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221118185118.1190044-1-michael@walle.cc> References: <20221118185118.1190044-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam: Yes X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 v2: - none 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 cb25bf29dea7..26459d582e99 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -688,15 +688,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; @@ -712,34 +712,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; -- 2.30.2