From nobody Mon Apr 6 23:08:48 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF5FAECAAD2 for ; Thu, 1 Sep 2022 22:21:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235278AbiIAWVu (ORCPT ); Thu, 1 Sep 2022 18:21:50 -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: quoted-printable X-Spam: Yes Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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; } =20 +/** + * 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 =3D kzalloc(sizeof(*cell), GFP_KERNEL); + if (!cell) + return -ENOMEM; + + rval =3D 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 =3D 0; - - cells =3D kcalloc(ncells, sizeof(*cells), GFP_KERNEL); - if (!cells) - return -ENOMEM; + int i, rval; =20 for (i =3D 0; i < ncells; i++) { - cells[i] =3D kzalloc(sizeof(**cells), GFP_KERNEL); - if (!cells[i]) { - rval =3D -ENOMEM; - goto out; - } - - rval =3D 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 =3D nvmem_add_one_cell(nvmem, &info[i]); + if (rval) + return rval; } =20 -out: - /* remove tmp array */ - kfree(cells); - - return rval; + return 0; } =20 /** 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); =20 +int nvmem_add_one_cell(struct nvmem_device *nvmem, + const struct nvmem_cell_info *info); + #else =20 static inline struct nvmem_device *nvmem_register(const struct nvmem_confi= g *c) @@ -172,6 +175,11 @@ devm_nvmem_register(struct device *dev, const struct n= vmem_config *c) =20 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; +} =20 #endif /* CONFIG_NVMEM */ #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */ --=20 2.30.2