Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5084338ybv; Mon, 17 Feb 2020 11:56:08 -0800 (PST) X-Google-Smtp-Source: APXvYqwLsMZeEqlDt42KcheQ2fy5mRk/oKjwYbMrhmUYvUDT69PNOBgB3Ryylpd8zy5h/uo3x8Vt X-Received: by 2002:a05:6830:22e2:: with SMTP id t2mr13575830otc.129.1581969368692; Mon, 17 Feb 2020 11:56:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581969368; cv=none; d=google.com; s=arc-20160816; b=zhTEM7Aq/Mx04GKSInuRZ6SHNfKndN988wX5qIiksJXqEe0G2AH6iVAuAIvi4PzFqg /7Rx6Q8l6fV79q6TUjm2Vz1Kyf85l5m4e11HnDN5aZ8/hSgfqSVAUJBSlDc1QAYAAUtU E6qmxnno3RDuD2Zs/lz8IiVGt338zDNNMetM7czaqpH7aFEkqe5dqyqSjxCnezj/hQCc GHuNL36WsLkjSobR/O98zSM6+XwkHH1Jh4ezLDlzYDWxM9mCTMx/bm30vHYMafH7x90r PXjXQ7jLPuKzJchHW7sFUdz3+R4nGaz2ruoKzbwj+4ZMsDa1eM/9xC9EGt/a7r2abCfM DbcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BYR9M1clfYHE1v0ARZeaLz8iyf2HR4xKCefQlA8DsFQ=; b=imlO9F+V3RgP/YGMJjG0Yo8d8JDxuhUuK9qY+JuSq8YRqLmYiSoA8VicJNe5xloOz/ 3gZSGiu9oTUhSB16TtbW9J+O3JJzUKMGTTWNiL38Sjh6RKrXx1CApY/KTLW2gPsgzEwB 1Ib/sXCHYu3lKoJDmZB+nAHrZ/bK0yr7TmszMeKvYGSgMzxGumXdnPael5ipEoIIn4Cb BeLWneIAtITo9hIRhnvtFqLqj8Z3jJZmi27nc2r7tj5rSrN7OvjRWvaCAG/y353jw/23 aact8F52mRcMMxaaSgcdvJ6Df7PL1YFmslBah5azlloBc6wHIes1PSC9v2MtleUtTX7+ CGww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="gs3t2/Ty"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6si603883ota.19.2020.02.17.11.55.56; Mon, 17 Feb 2020 11:56:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="gs3t2/Ty"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729696AbgBQTyq (ORCPT + 99 others); Mon, 17 Feb 2020 14:54:46 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:40232 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729600AbgBQTyo (ORCPT ); Mon, 17 Feb 2020 14:54:44 -0500 Received: by mail-wm1-f65.google.com with SMTP id t14so525726wmi.5 for ; Mon, 17 Feb 2020 11:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BYR9M1clfYHE1v0ARZeaLz8iyf2HR4xKCefQlA8DsFQ=; b=gs3t2/TyF6gF+0zoSvNHpJqpWvhb+OJTbYK+Rimp36zPn+Um3KJI7jU6an+eaF7C1g 6bsumWdRMHjnuu8oDRtMjAmZNmF/iEZdH8FIQIDkZW0GoN1Ni5mJC/WdxAzKosceidc9 3KClzAWGMg9kM5UDMuCWqhF7Qya3RyFEi9tCZUhzudbH0PYxgQ3+LYPEgQWWA0OT+UrJ m1VtSJwQTkRE3jKrGldEeOzw/QHMImAEvgHNLITBFtM2+0TDCPKaWMdEZYXRfI/sL2nI lN+tYgD7vqesBkEHp6/BgDbCgcnE/c3uLWTbIAheHZ0gGv4fYRQ6leWLrsVe6x72HxBB RkHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BYR9M1clfYHE1v0ARZeaLz8iyf2HR4xKCefQlA8DsFQ=; b=dn7JnSiVctf6pPKS9hAkfOHkwrC4OQyOcjvS/1RQa6ntJIlIhTDo3J9Fm4G/FgbJAg lyPGWSrwgoxnEh/dPLJWcaG8cYCNkh2ypqEGXWDJPMKNFGoFOVG5qojoDi50vArkEZS1 gvxZ00JSLLmGJHKOYIVi5Yo2Hsb2CZNE8cuz1RR0ckxfW10rnVBi2pKaaoxXa77ECCkH XDFIIWplLnl5qUaZF+MzLRa/0ytarx972KpB6VBgvAMEz9+R4a9cY/oaDyM0uNTqb9HL VC3tiEFvbUxhOZp+C422TjC+sJurPyn6mOiLsJRtsHvAY/Gv+BbdOzQ8oPUdFJzVqUXX dT6g== X-Gm-Message-State: APjAAAUe5ndzSpODS+S/5qqIaZExA7QyAC7FnA+KweE4h5M+zC9abeMC 9JMA9LTeFsUFrMpEK5pVRa74aVWohLY= X-Received: by 2002:a1c:a553:: with SMTP id o80mr598696wme.94.1581969282023; Mon, 17 Feb 2020 11:54:42 -0800 (PST) Received: from debian-brgl.local (8.165.185.81.rev.sfr.net. [81.185.165.8]) by smtp.gmail.com with ESMTPSA id v5sm2679469wrv.86.2020.02.17.11.54.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 11:54:41 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Srinivas Kandagatla , Khouloud Touil Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/6] nvmem: fix memory leak in error path Date: Mon, 17 Feb 2020 20:54:31 +0100 Message-Id: <20200217195435.9309-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217195435.9309-1-brgl@bgdev.pl> References: <20200217195435.9309-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski We need to remove the ida mapping when returning from nvmem_register() with an error. Signed-off-by: Bartosz Golaszewski --- drivers/nvmem/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index ef326f243f36..b0be03d5f240 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -353,7 +353,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", GPIOD_OUT_HIGH); if (IS_ERR(nvmem->wp_gpio)) - return ERR_CAST(nvmem->wp_gpio); + goto err_ida_remove; kref_init(&nvmem->refcnt); @@ -430,6 +430,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) device_del(&nvmem->dev); err_put_device: put_device(&nvmem->dev); +err_ida_remove: + ida_simple_remove(&nvmem_ida, nvmem->id); return ERR_PTR(rval); } -- 2.25.0