From patchwork Wed Nov 23 18:01:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 13054097 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 2CC77C433FE for ; Wed, 23 Nov 2022 18:27:44 +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=n6XRKp++sw2yqOxzV+slhvRAK6rnRIgOX7r6XM5Dy+A=; b=spPECbvJWOqMjA lHBOXUjvJrCRO3FxH6Boj2F7JJgNeu5b6MGDXa4sCEzaCXNbO3Af44VERwp0fK7YveydyZ/RKdMBc mqdW9Hgli6VA8FSV24szS9SurI3HAJZrUgugboIcZ7Li0ew/uWOlVh1BJ2fJJaeMTox3JtJ/gVCJg t5y5m9WjG8cYBQsdztydbGI9MyUmyj/RSPc8h7nk8gscHa0vWjsWVx1i2mQmPj1N4h5xVPh1jPnc7 S+29ysFIlkUccIIGnmKllRXfv/en+7pzJCCQkT2JLdFTp5H0dmqXH3RexnND8IWrDr5TKje+SGtAa ZIcbGDCw3MD2Sdcg8XRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxuSI-001bEi-Nl; Wed, 23 Nov 2022 18:26:42 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxuS5-001b24-Sx for linux-arm-kernel@bombadil.infradead.org; Wed, 23 Nov 2022 18:26:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=WXol5tT/oIFKZhTAd0NDm/tufouMejDDn5FNjp75nXI=; b=WglIcMfoDtr+7WDDQy12/PaDba pNR++ehscNG2PsVah3beTVF6I2r3/fJHsUHNHux1+zU9OycxH/5L5LPesOGNOv1pc/2SxMMau5BYl u8buBSj1nAMMyzsHE8Qkf9p4xFKDiW6mMEgqhSmztXsqYJawCwIWYBdHM+C+MUXeLK8uALFbMV7t6 v2q4lLr2sFN5P5glm39pMU7iEhxrmMFno4aFXpGohwiVVssEpmf6W324W6b6k/J5Mg3/U0JjMcnFg NOO9L1LURTVEH5exdEBlLMGNO1kQwJoy34JkDbGc++Tz5l6Ov4lQW48FKjlcYG4cFg/Na06y/B+xN mNhWz7CQ==; Received: from 0001.3ffe.de ([159.69.201.130] helo=mail.3ffe.de) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxu4t-003sQb-Co for linux-arm-kernel@lists.infradead.org; Wed, 23 Nov 2022 18:02:36 +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 E74BF3B2D; Wed, 23 Nov 2022 19:02:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1669226543; 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=WXol5tT/oIFKZhTAd0NDm/tufouMejDDn5FNjp75nXI=; b=d42jT60xZRu6OI92S9R0pgqZ5Rr5mDmN1r2cDlA5DFBC/iHLLLHyRclbVm8cYR4xzuC5M/ /RrCXHVcHLquLp3ENBOUklnFAAeKR/JHo/45/aqFdslL+tvMuIOERwy07yIt3QF2GWHZuL jNy9w9lDPAUg1OeLH+PWhXFYuMsw93b5DsfaxQjxt+++qedSmLFhpiOemn6yoK4xXGBc9e dc+ttW6spRW5F3gwoCffA9tDACTKV1WxXLBEPfmo0GNYi/GCCai6Xi/4N5Pjj+TBGlDOSM Xl84Rkcgn3zzUfN7UK648yWPEqJV73G37UaB7y76QugAB4rhL+7VyJBvk91Osw== From: Michael Walle To: Jonathan Corbet , Srinivas Kandagatla , Miquel Raynal , Rob Herring , Frank Rowand , Sascha Hauer 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 v4 10/20] nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of() Date: Wed, 23 Nov 2022 19:01:41 +0100 Message-Id: <20221123180151.2160033-11-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221123180151.2160033-1-michael@walle.cc> References: <20221123180151.2160033-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-20221123_180231_797608_F01616EA X-CRM114-Status: GOOD ( 15.78 ) 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 v3: - none 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;