Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1663291rwn; Fri, 9 Sep 2022 01:56:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR7EyeDodhvPkOZmZsNyvBYlfBzExk33nU1ELVbKsjUSyC8rx2p3Sg3bmYR0o5okzKuypg5L X-Received: by 2002:a05:6a00:148c:b0:52e:a630:afc7 with SMTP id v12-20020a056a00148c00b0052ea630afc7mr13397392pfu.0.1662713806905; Fri, 09 Sep 2022 01:56:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662713806; cv=none; d=google.com; s=arc-20160816; b=qWH8G/eU6CU3aKVbFmwrefOXEc+Gw/ofOYxhfWB0uHQOE/qd3Bd9wpvbcQbm1qoLmt EjHGu0r/KaOfZn6dsiFa1UGqlsY4+5XgLmovQ7Zo2z79nHSGiZ8sX/koC7n5eaE6xNOY hZdSe880pSQUJCunJKspqbCOE6YWCix1Nf5W/uI8fziqUDWWakurV69O3QVH341ohkc/ 2qahMTfTBSYgdgEmA7dHXX1kWGbaFI0Vukbyzzqolp7R9xi/eAv0nJk+4NVNHH8g7ffO zfkWhi1NuqFlPUXghdgSESHDGqdXuDdGZykmBOtfqrtVLxFQRMkB4/GjJenu1l8stL8z 59tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=xUYfPwKfjWj8UMEg1ZOqkwBhAmHe0cmPeP+wDEVrkOQ=; b=D8f6Lcu80Z2cYGKueesmWOn++/8c/vdVz+G8bPOUlZ21Qzrj75dqQBG91ggtsJhrT4 MDjaGryyQFlLjbKg8/GOgTYJsPRHFchLMdQRcqpj8nfPIZPf89iUWZkkJpnX1bTlG066 Nq+e7W5RkNnX3U6AKcNJfQmsUY8oQnS68tkdRFMkszRmM6RBxt7DLeu+q6fxnVTxbMQh 63BF7YyeFPC1xMdvKLUnsfF5m5iFfWUxaWZXXzmfZiOcPAPJQwchanmszI5IvhdI8e0G 25ZYVCsdEwehONUV0CP3zQjePsdyE3AzbpSyXMeI/zqFFRpH0UHm1/kpvCnDDjCuD5Kv 0PvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TubYt+Gy; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q11-20020a056a00088b00b0053b36138dc5si437714pfj.222.2022.09.09.01.56.35; Fri, 09 Sep 2022 01:56:46 -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=@linaro.org header.s=google header.b=TubYt+Gy; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230154AbiIIIw3 (ORCPT + 99 others); Fri, 9 Sep 2022 04:52:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbiIIIwZ (ORCPT ); Fri, 9 Sep 2022 04:52:25 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58DCD12FB93 for ; Fri, 9 Sep 2022 01:52:16 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id n23-20020a7bc5d7000000b003a62f19b453so3947513wmk.3 for ; Fri, 09 Sep 2022 01:52:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=xUYfPwKfjWj8UMEg1ZOqkwBhAmHe0cmPeP+wDEVrkOQ=; b=TubYt+GybM3R6FXjLZ/HMzhZe/TPRKvDFmW4wnSeSjkjwv7l4KlvYzC5QXADNJrGvd JOaD0zwqo1+n1dO/0X9WCrJ7DwiGCZ7yCZGN06+ztXv9HvKgMtS19rT43Y5/dXIu5bXS eYqIliMmVz+St0Navdlh2leuJlnzrJG4A5smh9Mf/cH8z2wJxaSKk+s9q/9dMTSgz3eM ch5re4PO6rxPqhP8acOlfiWaCVtgnEGZqqLvRPb+VjfyOC5uKlYUq9zOq9fx+tE6VNE9 sc58LAPXfMnjboti2FKUJnFRul2unn2US5QO1sBHb80J369YvubNxnXsut6Tq0lcidTu S7Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=xUYfPwKfjWj8UMEg1ZOqkwBhAmHe0cmPeP+wDEVrkOQ=; b=0FEzqL2SmZFG1P8eWVM6I3zsAGQPq9gZ1ncYRJBu/fQ+93OHl2zAtfxWyGpecNlLUa FBxsolldxR++5WH7jmCjHK0bSLc/KjeUlxgNHqNZslg6R3tlqyNAk01utI2DiimQl87k SBDEqg2IxbnCSPpUESeCQ7lZiwm9+r/zrC70hyZAAkEjQtsjsyHeJLAXv98kjRln5vbI FEy0VvZE3KHYNLvRVBqOCQ9uQJ7V8ADfDf3f6Wg561YTHUd7eRJyB4FYU+jOYA16+7RG fFIO/S3m7uFcvJi5Ye7S5O7XL2iAoBg/IokNU+GBmCORwPc6CLw65KrYUIjF3YI7Z+oC eQOQ== X-Gm-Message-State: ACgBeo1HgV6QD/OQP5P4vbTtJpyEBmQAc2UUOw8N6j8vzfG/i3FuiOSm L7xE4DCUU2fOaIQ+4oSxAX2WBQ== X-Received: by 2002:a05:600c:2059:b0:3a5:92cc:19c5 with SMTP id p25-20020a05600c205900b003a592cc19c5mr4469580wmg.101.1662713534861; Fri, 09 Sep 2022 01:52:14 -0700 (PDT) Received: from [192.168.86.238] (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.googlemail.com with ESMTPSA id bg35-20020a05600c3ca300b003a5c1e916c8sm1012461wmb.1.2022.09.09.01.52.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Sep 2022 01:52:13 -0700 (PDT) Message-ID: Date: Fri, 9 Sep 2022 09:52:12 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v2 06/20] nvmem: core: add nvmem_add_one_cell() Content-Language: en-US To: Michael Walle , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Shawn Guo , Li Yang , =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= , 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 References: <20220901221857.2600340-1-michael@walle.cc> <20220901221857.2600340-7-michael@walle.cc> From: Srinivas Kandagatla In-Reply-To: <20220901221857.2600340-7-michael@walle.cc> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, 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 On 01/09/2022 23:18, Michael Walle wrote: > 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; > +} > + EXPORT_SYMBOL_GPL ??? > /** > * 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 */