Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1253168rwe; Thu, 1 Sep 2022 15:23:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR4wM5bcuChHVed3eoH59wQUE22iUzMNX8nKG+spYR3K8iC0AigeN3Q9u3TeLMPV4kITOiXF X-Received: by 2002:a05:6402:11d1:b0:43e:33b:93fa with SMTP id j17-20020a05640211d100b0043e033b93famr31305545edw.419.1662071007183; Thu, 01 Sep 2022 15:23:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662071007; cv=none; d=google.com; s=arc-20160816; b=WsCJCSHlVTLHrussBJ1sNkp2dkUqucWvjalM3CM1Lcs835hOFf+E5aegha3CgvOcXP 0pqltAceON5kdwF4xQe5HrrM73gXZFmh4fVGgewlbO45HDrZXlcJPiRX2gH9s5TtNeps zjbqOW2rKZ5+YnrxnUBgooTyN9aHFDVX0eFzDw+lTV2pTCiVYKyWpfYLd4h9zY28VoHm I5YQW/4/lkQNZaJYV7mTpQrahzHsieJXk0WDgRg2a7WZW81htTjyqT9dmswSjer10GF5 v9OG4gSiRlyz51g6Ng49/RZMYmSuhDsuV8lc4QgtIBHfoNT+K+orWF/RetHSwwdfoADT l0KQ== 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=FaU7kyN0Fc4LtvOrLl11/a8pYKjp2wZgnNmymVUr7I4=; b=0rydf+cAYbc858vGAyUnE9c9E6M5+8weJ58asdxU2SF15T3AI02+/he2w8J5G9QM+K JSE9+gcHNxdkM/o9rjKfF3oL/Nccw6evAAJPXz6EC2rpEcFcPxLOGSIbh1lsZR4/9jo7 4wtmcNT0+pEIF8EYiUURwwo0ybUD3+CCYBzVCfku3eX2J2VD9+3rVqSzeR/MoeU33Fbq JdCOUwlnD7Q7iwbDqWCY6VsnT1fBhxtSWy36pmQFDmZA8Q4kQSZeZoBMkJX0dc319ahJ gmEQzilLGlQMzzdctvchgpsS8Q9n99NuCRbtSjGtfElIT3nj2ylT4QgJV72VQ6bKvU5w gW6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=eWXtH8bh; 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 dr21-20020a170907721500b0073d753fe303si316358ejc.611.2022.09.01.15.23.01; Thu, 01 Sep 2022 15:23:27 -0700 (PDT) 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=eWXtH8bh; 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 S235276AbiIAWVt (ORCPT + 99 others); Thu, 1 Sep 2022 18:21:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235058AbiIAWU5 (ORCPT ); Thu, 1 Sep 2022 18:20:57 -0400 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37930A2214; Thu, 1 Sep 2022 15:19:18 -0700 (PDT) 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 DC9B821C0; Fri, 2 Sep 2022 00:19:10 +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=FaU7kyN0Fc4LtvOrLl11/a8pYKjp2wZgnNmymVUr7I4=; b=eWXtH8bhkki3soEuyZ0vkxrOfahdp279Fnu7LFhhTevSSz8ailu36OdBDESAE9PvEF+a86 49HI0RW2veGVqKrl4ErCEUBaSQNAzneV/h9x27k+w3rCyB6CLMI2mYjggr8DuWmAhKp60n xGt3lVfTFqo3RbMGU6ZKizm7nsGF/1ffoL8BVc+IaikXkTg8OvALp7z3lMDhpQc7KW/AG3 feAe8E84QPHu60qWq0lR/GnuBBk9Czyfa0ZucfuPQkuXNv1c4Ip7R2/0k4w7J4udHvC7L+ NBk80oheXoqjUt4yHwdh38PYQCCKyuJE65C4ZgY6DCjJQTgLP0k1mTfopRCIkA== From: Michael Walle To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Srinivas Kandagatla , Shawn Guo , Li Yang , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , 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 06/20] nvmem: core: add nvmem_add_one_cell() Date: Fri, 2 Sep 2022 00:18:43 +0200 Message-Id: <20220901221857.2600340-7-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 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, T_SCC_BODY_TEXT_LINE 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 Add a new function to add exactly one cell. This will be used by the nvmem layout drivers to add custom cells. In contrast to the nvmem_add_cells(), this has the advantage that we don't have to assemble a list of cells on runtime. Signed-off-by: Michael Walle --- changes since v1: - none drivers/nvmem/core.c | 58 ++++++++++++++++++++-------------- include/linux/nvmem-provider.h | 8 +++++ 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index be38e62fd190..3dfd149374a8 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -501,6 +501,35 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem, return 0; } +/** + * nvmem_add_one_cell() - Add one cell information to an nvmem device + * + * @nvmem: nvmem device to add cells to. + * @info: nvmem cell info to add to the device + * + * Return: 0 or negative error code on failure. + */ +int nvmem_add_one_cell(struct nvmem_device *nvmem, + const struct nvmem_cell_info *info) +{ + struct nvmem_cell_entry *cell; + int rval; + + cell = kzalloc(sizeof(*cell), GFP_KERNEL); + if (!cell) + return -ENOMEM; + + rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell); + if (rval) { + kfree(cell); + return rval; + } + + nvmem_cell_entry_add(cell); + + return 0; +} + /** * nvmem_add_cells() - Add cell information to an nvmem device * @@ -514,34 +543,15 @@ static int nvmem_add_cells(struct nvmem_device *nvmem, const struct nvmem_cell_info *info, int ncells) { - struct nvmem_cell_entry **cells; - int i, rval = 0; - - cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL); - if (!cells) - return -ENOMEM; + int i, rval; for (i = 0; i < ncells; i++) { - cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL); - if (!cells[i]) { - rval = -ENOMEM; - goto out; - } - - rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, &info[i], cells[i]); - if (rval) { - kfree(cells[i]); - goto out; - } - - nvmem_cell_entry_add(cells[i]); + rval = nvmem_add_one_cell(nvmem, &info[i]); + if (rval) + return rval; } -out: - /* remove tmp array */ - kfree(cells); - - return rval; + return 0; } /** diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 14a32a1bc249..385d29168008 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -155,6 +155,9 @@ struct nvmem_device *devm_nvmem_register(struct device *dev, void nvmem_add_cell_table(struct nvmem_cell_table *table); void nvmem_del_cell_table(struct nvmem_cell_table *table); +int nvmem_add_one_cell(struct nvmem_device *nvmem, + const struct nvmem_cell_info *info); + #else static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c) @@ -172,6 +175,11 @@ devm_nvmem_register(struct device *dev, const struct nvmem_config *c) static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {} static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {} +static inline int nvmem_add_one_cell(struct nvmem_device *nvmem, + const struct nvmem_cell_info *info) +{ + return -EOPNOTSUPP; +} #endif /* CONFIG_NVMEM */ #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */ -- 2.30.2