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 206D6C38142 for ; Fri, 27 Jan 2023 11:18:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232230AbjA0LSw (ORCPT ); Fri, 27 Jan 2023 06:18:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232285AbjA0LSY (ORCPT ); Fri, 27 Jan 2023 06:18:24 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1586E06B for ; Fri, 27 Jan 2023 03:18:02 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id b7so4677640wrt.3 for ; Fri, 27 Jan 2023 03:18:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RiCtgga95+oBIC2lKHYt0aFS1kvbxISlsHgDAHK16wM=; b=Le2aoPmh5jAonw9gud3H2OPhixp3bN8sx3gCJWsnRC45dfKAScx9lJcIbLUdjCBOID vEEIDQ4Q6+BUTStj0P/zLq7UZRsNe51DDFBsZ3Hppndg3f7D6RxoNG4WiPo/wV84ZIYT YMwlx2d07RlPGor446UoN6C0zradKcN7b4Mqa6wt4rciin1bIgJgpQDLt24pEo3/w08E py8L1/o7ZNDQwtD0m+Njixzo6QkJuLQ+5ISmMjCXLUkGIJzLT4nrUXEls1/R1o4HoOJ0 IH+MBRqd+S+En7IEM7HmKUu2sPrg2Yc6KipUMJnc1xNI1YckPfBqMgMmdwDJ6kfz09xg /6lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RiCtgga95+oBIC2lKHYt0aFS1kvbxISlsHgDAHK16wM=; b=A7/IpY9i7ECVtZXagxMY0kAKQYrRSwqtOhpAXhybrrf6e2HXXmpUuWbSs5YptfrhY4 tRtoid9QnPQWxsSNOu2jxpI36gWOmJ5NZUJtnUGTudmTITkXK3a4q089J2Xxh88EAj10 XpL9B28VRupdA7jHQgK+GqJntlTXmv6F9e37Fz2H5DKAgRTgJJGIDaa8TyV/M52vENop fNP5w5wlhSL4Kj9TOF6r6EsKT6lOiZvin9D+l5rIUWM5liUI3LG6pg5X5F9McL663e/G Fh+PD5EnYwFeTK1+QdAuDuwDXECqJVop9WGLrBo+xpbww8kR7r7geIMPTHcSUtIUd/OK /qZw== X-Gm-Message-State: AFqh2kqy7QP+hrUVD/NDSNMCMGeVObvdTqXCKxX1p7dSctRak54zF2BR TRXz561kF2oXG/9pcwAYWHejyA== X-Google-Smtp-Source: AMrXdXs3EDYq2+lUJKsAXfZIRJ0YyjCLmfCNAGTa/HM2yAxV8UOeXWkvFTpim05QCoqvkhvwos+LDQ== X-Received: by 2002:a5d:6b0e:0:b0:2be:d03:287 with SMTP id v14-20020a5d6b0e000000b002be0d030287mr34462049wrw.44.1674818280558; Fri, 27 Jan 2023 03:18:00 -0800 (PST) Received: from localhost.localdomain ([5.133.47.210]) by smtp.gmail.com with ESMTPSA id c13-20020adffb0d000000b002bfd190fd60sm1843314wrr.108.2023.01.27.03.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 03:17:59 -0800 (PST) From: Srinivas Kandagatla To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, Michael Walle , Srinivas Kandagatla Subject: [PATCH 15/37] nvmem: core: add nvmem_add_one_cell() Date: Fri, 27 Jan 2023 11:15:43 +0000 Message-Id: <20230127111605.25958-16-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230127111605.25958-1-srinivas.kandagatla@linaro.org> References: <20230127111605.25958-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Walle 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 Signed-off-by: Srinivas Kandagatla --- drivers/nvmem/core.c | 59 ++++++++++++++++++++-------------- include/linux/nvmem-provider.h | 8 +++++ 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 98ae70695f36..58f8e33e7a8c 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -501,6 +501,36 @@ 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; +} +EXPORT_SYMBOL_GPL(nvmem_add_one_cell); + /** * nvmem_add_cells() - Add cell information to an nvmem device * @@ -514,34 +544,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 a953a3a59535..0262b86194eb 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -153,6 +153,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) @@ -170,6 +173,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.25.1