From patchwork Fri Nov 18 18:51:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 13048620 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0FF95C4332F for ; Fri, 18 Nov 2022 18:56:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wINdmACemb7zPHflzEMzmpxlrira0/USaIjhwfExHKA=; b=y8d77LtOtpbMri 30xPdKzSccJCH3E3ZR5jAaTivQwiHanl85LmX58eK7vMqyed5TkRfBSz8i0UNB2lL0azUJCibuJmn JrLKaD8PQ+JEzAMifYpD6cUfL9Yy373rZcjsQq+vsJvxe3WXJbzh0EXa9ZpziPDqCYm6F1YT4rSSE aqsIbLxGAQk+VdvvceP5QyvSgXU1kWbIWBt6SM8PL38R/S7Yn45w7hj1etQekq0ietmGa5c8GORnU zuou5tf7JGhbrjQInuBoGmcE4K4axN3AtV+EVR+QpOaKIX6KgJ5Cw7tT1oTrWiLMJwOUvYZr4RG0M 0qAYj8vmWWBEmHcPUhvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ow6Vv-007LIK-2z; Fri, 18 Nov 2022 18:54:59 +0000 Received: from 0001.3ffe.de ([159.69.201.130] helo=mail.3ffe.de) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ow6Sd-007JRW-Mz for linux-arm-kernel@lists.infradead.org; Fri, 18 Nov 2022 18:51:38 +0000 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 39AE72425; Fri, 18 Nov 2022 19:51:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1668797488; 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=YDoaHvyBqWrvft0gXJEgSIKrah/C9bAdp2KK5WyaSuo=; b=K0nxA0n3Dcsx4aBa3WKEFfgTjORaDsc+tBpmqcqFQm5KQEnA5lshxVjDAz47RlHJ4UkEt9 Ej73nTaKXeid1cdQT6+7/vLk10c8chS82RNAjE8H9IBNk5QT1zOmPfeaMYp5RupENvySx8 bsCw/nJo5md2u+I2IHSNbdSBMWc7G4HzA4S5+/6fnJwFFiTlDRrMrFwGIXkQ5USDw3UYHG Y2pmNJVplPAS0QUvPQdwFQAkrVGymLPe8EtTXmto/I8YeXtgFu4Z2VFFvrJCkSX1OvThTz 0OEnMq9ahyrKUAFOlS9zCtCVsXNu5UEllBjHwPdLK7a0B+1T6PyYqBu7lvgp7w== From: Michael Walle To: Jonathan Corbet , Srinivas Kandagatla , Miquel Raynal , Rob Herring , Frank Rowand Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Michael Walle Subject: [PATCH v3 06/18] nvmem: core: drop the removal of the cells in nvmem_add_cells() Date: Fri, 18 Nov 2022 19:51:06 +0100 Message-Id: <20221118185118.1190044-7-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221118185118.1190044-1-michael@walle.cc> References: <20221118185118.1190044-1-michael@walle.cc> MIME-Version: 1.0 X-Spam: Yes X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221118_105135_940711_CD64C2A2 X-CRM114-Status: GOOD ( 14.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If nvmem_add_cells() fails, the whole nvmem_register() will fail and the cells will then be removed anyway. This is a prepartion to introduce a nvmem_add_one_cell() which can then be used by nvmem_add_cells(). This is then the same to what nvmem_add_cells_from_table() and nvmem_add_cells_from_of() do. Signed-off-by: Michael Walle --- changes since v2: - none changes since v1: - none drivers/nvmem/core.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 24573e63e5a9..7c76e0e0072e 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -515,7 +515,7 @@ static int nvmem_add_cells(struct nvmem_device *nvmem, int ncells) { struct nvmem_cell_entry **cells; - int i, rval; + int i, rval = 0; cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL); if (!cells) @@ -525,28 +525,22 @@ static int nvmem_add_cells(struct nvmem_device *nvmem, cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL); if (!cells[i]) { rval = -ENOMEM; - goto err; + goto out; } rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, &info[i], cells[i]); if (rval) { kfree(cells[i]); - goto err; + goto out; } nvmem_cell_entry_add(cells[i]); } +out: /* remove tmp array */ kfree(cells); - return 0; -err: - while (i--) - nvmem_cell_entry_drop(cells[i]); - - kfree(cells); - return rval; }