Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7968116rwb; Tue, 6 Dec 2022 12:10:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf7etEIKwuEdyesaG9e9xEPaYuaScbFRxJ8Zgz85KeHtbNS3F+EcOweQGaNzvUSXrroaNKlK X-Received: by 2002:a17:90b:290:b0:219:2b00:8d23 with SMTP id az16-20020a17090b029000b002192b008d23mr49899678pjb.167.1670357414907; Tue, 06 Dec 2022 12:10:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670357414; cv=none; d=google.com; s=arc-20160816; b=DOLGhfN4w23eYWy8rFM3DHzAmoRn+Jb4Jufu9TpdmGvY/OwI5junDAQr0hrq6uOp6o 5JGxfFnUE9hQgOINWhmUiau2ezYLuHLw1HR8raYJJ3Zla+XbBGGN9H2enFL7N9ejC0km G8f14/EJR/ImAwZ0xExn+CnTNyPbEfN4GYpKXv/LWmcNDJbFsXsvoNVL7tedDVRcv8vF 8dAHsh1jAgeOWbpz798Rf+UM4FZZEP9E7hnZma223IkfJgd5gAI9Y80Qq9/vvwkkLGDL 7JQCB3PnHI7AK1gxPWCsBWUusb9+7yE6GAIIJXe30SZeri0Aaz80x7hVuckCKkdbI12l cWng== 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=mvTkfYS/F5bhxjZrXTlkPXrK+rtGefsDiAak505Ve5I=; b=ZnWCe8wk+uvcMIVlZKfI+demAmtaFgL7Wq/emyJs/q0Nx/1WNQ/k00yucQx6Ijb7DF m3lZ5e1uKcAzmejYgXNso2fo5hzqzSpZ3D703Dn9GtFrt5GwRwcYmxL2DJ1WhqUq3PmY gx3ApCa44hkLu3mZSOW/5IgwGv/e0KeiX9i+PCwEbAxzrwsKZmCZ111dZxdu3I1LIy1w 9BFvA5guPUYNT6sf1qs2L7C5hdXy5CQ/La2RsCgzj2btTjfmSuXXwQR/va8rPCJ4MkMQ oukin7M3SCyxwiOlMrxhlJuULY/H6lVleiIz5DDBC4EiV3vAZg7C23kPhX76ab/h2wHB epxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=opmIFnOx; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j193-20020a638bca000000b00477bf2ebf14si18316119pge.266.2022.12.06.12.10.04; Tue, 06 Dec 2022 12:10:14 -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=opmIFnOx; 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 S229875AbiLFUIc (ORCPT + 78 others); Tue, 6 Dec 2022 15:08:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229718AbiLFUHz (ORCPT ); Tue, 6 Dec 2022 15:07:55 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB66C13DEE; 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 63FB43B39; 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=1670357270; 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=mvTkfYS/F5bhxjZrXTlkPXrK+rtGefsDiAak505Ve5I=; b=opmIFnOxHWQg0pmLwLLkrxg6RJTvYGzaJg6JawH8Qi4UGjW5MBsazUYQrHZW/DXBTnn2tq kAPYGcC6FhZA/GYC3fT6VL2tg9SkTyQUXn/FvX95xIzu48RfERGNithitZ5pp6rHYnZ1XO dKF/RGFhhjXQpREAv18gyflhb60KHzTe7t4BHMAxK+mLxNdbn2ZRnt26GDqwf1sDpFtLsM srt8hj2Nkhpz1iUxL3TL42Tqbkc80+eMrCA5o2H+smHMnJbqoXgdshfa4CRdatudLUz6+o IllbFKKUaK3GIj9NbN3MdzDzmU8zmOjQsXEzH4DzumDHh4MAFZ4d/qbTh7axQA== 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 09/21] nvmem: core: fix cell removal on error Date: Tue, 6 Dec 2022 21:07:28 +0100 Message-Id: <20221206200740.3567551-10-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 Content-Transfer-Encoding: 8bit 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 nvmem_add_cells() could return an error after some cells are already added to the provider. In this case, the added cells are not removed. Remove any registered cells if nvmem_add_cells() fails. Signed-off-by: Michael Walle --- changes since v4: - new patch drivers/nvmem/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 7c76e0e0072e..70c3d0a20d0d 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -851,7 +851,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (config->cells) { rval = nvmem_add_cells(nvmem, config->cells, config->ncells); if (rval) - goto err_teardown_compat; + goto err_remove_cells; } rval = nvmem_add_cells_from_table(nvmem); @@ -868,7 +868,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) err_remove_cells: nvmem_device_remove_all_cells(nvmem); -err_teardown_compat: if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); err_device_del: -- 2.30.2