From patchwork Tue Dec 6 20:07:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 30495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp3027178wrr; Tue, 6 Dec 2022 12:09:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf5GNVfaOxoVMtNxJb05CcIG/LF8j/Zlk5020oZg3vT5mu/0Kee8pUV2GWyejbfaRxXKWXlY X-Received: by 2002:a63:4087:0:b0:477:15c8:ff67 with SMTP id n129-20020a634087000000b0047715c8ff67mr65989297pga.275.1670357388614; Tue, 06 Dec 2022 12:09:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357388; cv=none; d=google.com; s=arc-20160816; b=DMXlX75P9Ibx51nCb7rFyL4FO6Eg0jpRw22RRiVXby6qXAzEkzqpr0ign6OARu/mUe KNWZDGvPgbthScfFKFqq/lWNPdery8I9L9VCVCtkZhC0wqfNfSw7Oz0DlDN1Hh0GGVJX 3ufvIonD48i5/EVJuirZWC5L4n74FK+sJyLE9IsvNstlVKG6xZtyYgN9EM4+YaASG5Uq 0oKVZgIyFDuXmw6ft3mWQMVlsTpa6CJ+T5O9cUCjxnJZcnTKjX1gTtaCHUJ+Mo6bg08A YGQkv+m3usvzk4Zm6OgpTErB/gF120xP13N2NgW950pTN2zfrUx9TQNYr/h5IaPxe6a5 mZeA== 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=fJvYnlOS07so9NTt9eBezqGlHSanr4dGO+tZaJE2fLQ=; b=o+Gtx5syO1mMbhIhDSH/ak7tCEOAbCKsK6VV8dMO0CAVOSGs12YtnP1aPvZdtjrPns Msa0nIDc0kofWnnrFMzmUqGcjnLtUqL5QlDRaSa1ti7AQoYCVjH7C4dFDjT2AO/y0MUN 6X1VL7UIKSiEXlOApz8NuMD9SB4YPqK/bpB9DwupwygV5N3E911weqCJrkHa23w1nMT2 8Rd/x1kv5A9ndJGicCEduXjTmox+WEoZ3cuSAUJauLfpJcCzj4ZvnFafSA7D7OKg3Gjy J3EHOAY6ZH26M/vFAf4f2zZM1ssnHrxTbbWTUUmR7/DCAZSlcPSQmphFFEDla1nT0WG8 ETdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=VNHypZmA; 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 g11-20020a65580b000000b00477cd4f65fasi18211523pgr.197.2022.12.06.12.09.34; Tue, 06 Dec 2022 12:09:48 -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=VNHypZmA; 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 S229769AbiLFUIS (ORCPT + 99 others); Tue, 6 Dec 2022 15:08:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbiLFUHy (ORCPT ); Tue, 6 Dec 2022 15:07:54 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB82017890; Tue, 6 Dec 2022 12:07:52 -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 F0ED83B3B; Tue, 6 Dec 2022 21:07:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1670357271; 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=fJvYnlOS07so9NTt9eBezqGlHSanr4dGO+tZaJE2fLQ=; b=VNHypZmAIZx9Lg40BeJsvFXwHpTfxcz/Tzy00fmDxoGRWvoLjn5s7Z0xK9P6UqYeoXPLRj kZlTjnwlYUEa899SDXkCq2D1hFYPCqN2HH5tuGkIfXWRfrTdAHxIWXB5B4mI6Eg8JL2dxv K7mDG09R3Na+tvedP4vuVF5tZoeOFWOh1NGpKflFIYn/4JNaZc1e9x1MJ3Qoww7Nw1kcTE SoXAMl787rd1O5lqrGSmZdx5iZbfs+eXyNJaJxRRQCCfE80+FyknoVyAY3CWVGgx/MUnC8 K5vI9tlHK7syo7D0ZxxyQimWPAcWgQzhpckjd94cC9vsxQCjwlQvcgfNaKxcUQ== 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 , Dan Carpenter Subject: [PATCH v5 10/21] nvmem: core: add nvmem_add_one_cell() Date: Tue, 6 Dec 2022 21:07:29 +0100 Message-Id: <20221206200740.3567551-11-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221206200740.3567551-1-michael@walle.cc> References: <20221206200740.3567551-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?1751496669078281422?= X-GMAIL-MSGID: =?utf-8?q?1751496669078281422?= 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 v4: - none changes since v3: - none changes since v2: - add EXPORT_SYMBOL_GPL() changes since v1: - none 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 70c3d0a20d0d..5db169aa7988 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 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 */