From patchwork Fri Nov 18 18:51:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 22466 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp357170wrr; Fri, 18 Nov 2022 10:57:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Kl3WXGUp5a4fa3O9RlyVoD/SiyRrQp79a3pO8c/qS+F8nbg2VYe0uLImYmdlIdg3swwwi X-Received: by 2002:a05:6402:381b:b0:456:ee32:799b with SMTP id es27-20020a056402381b00b00456ee32799bmr461257edb.2.1668797826088; Fri, 18 Nov 2022 10:57:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668797826; cv=none; d=google.com; s=arc-20160816; b=cW+WH6BwC931OxkLmGBkAosFEBw8xEOmbqt5Lgl2v9jgfSSW2cuSIMISW3Ucvu7TkY D4o4AJ+Upj2/YOkmubpme2ew3OIqmvD++ihhgCPxigjOav+C9oDptSTjbp8STR2a2x0G 4opmzRTrgF35XO82x3+G2UQEOAxFquihj4Td1locMO77ZxosnPLS5lfH99uFUBzQO3RR Fs/8epYMUD7s/nVbUaid83mjEnIX+27+CwbwEDObv5EpSkMvxA0i/wcXz1mBgXjSigOl vhS1QCSCdW1P6ibV/kTZoIjcwSYFlUF4iuHTyu76KXRTD+y8z1rtmCfegGHz5oZVlhxj 1OhQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u1-20020a50eac1000000b0046911aa4967si1970023edp.555.2022.11.18.10.56.40; Fri, 18 Nov 2022 10:57:06 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749861349380835203?= X-GMAIL-MSGID: =?utf-8?q?1749861349380835203?= 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;