Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp481854ybv; Thu, 20 Feb 2020 02:02:08 -0800 (PST) X-Google-Smtp-Source: APXvYqydLqA01ZFdjCinAZdrzsgLjy8sZ6A2zzFM4npT4fbpHYuKaPT1N1n5kmINN+1YZwnHBUz+ X-Received: by 2002:a9d:f26:: with SMTP id 35mr21671617ott.31.1582192927754; Thu, 20 Feb 2020 02:02:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582192927; cv=none; d=google.com; s=arc-20160816; b=dorct4xixbeb6JpqI3P4r7X+/+VHpzZxMSmR/vo0E4gyzOygkgoGzhd1I6zIpfoMbd 1wdTplKjNyXV1zqo38kF8+LEjA8RBRuaZhdnHHJoQtB2c2J/BSesxlBmodYqm69DEzdL Vq1ManO9jY1Z1R7oau7g3O4uM2H0CytqJQIcpefty72WJWOm9Fiw8N3vkOk42L4qMCjO PsDZNktF7Jo3TzUH8tElvOR5N9xDXOPMS6TXOY18hko3SYYx1AeetqaruZdt44MYJry7 RHJiPoEdc+BUCtYrUBqKRB3WuhQyepy1QatwOgjUHqQctaQ+15hYuWXWuNfI7gx+DYKA QufQ== 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=Tb5z2UeOLZl/UqO+U9twmLjCGpyhePDzuQ8mmkofF+4=; b=nYyVK9vXh7wCHNZIfFDnqaf4xWwPQdNRFkSy3mCVBppN886CQSvQvWlzhXR7rCwiPv DK79smgFPu2cGhmG+FsZjmq0IanOLPowcPKqE/UT4fICfnzVtPwcGEeu80F7O5n4qA0F vfKxNBonkmlWN4ftgHIR+aXDadtyzcMUsG3EUPe+/75Nh3pyJSq4QcKkHp6tQGLEEBsh VPjXk+xpScp05cdWPG4Nl5b5RLa7MuQAgmcYZydTMovtibvCCWRQRwUkuwrQd6aJPyCs GOqWij0BYMJM9dFMPMqa0USxUXFl+CFAjOFB56iq6VAd8QK5yLK/Z/EyqJSYUv9DkOkr iy5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=wzgL+FZr; 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 t128si9974554oie.176.2020.02.20.02.01.56; Thu, 20 Feb 2020 02:02:07 -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=wzgL+FZr; 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 S1727794AbgBTKBu (ORCPT + 99 others); Thu, 20 Feb 2020 05:01:50 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50310 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726801AbgBTKBt (ORCPT ); Thu, 20 Feb 2020 05:01:49 -0500 Received: by mail-wm1-f68.google.com with SMTP id a5so1316224wmb.0 for ; Thu, 20 Feb 2020 02:01:47 -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=Tb5z2UeOLZl/UqO+U9twmLjCGpyhePDzuQ8mmkofF+4=; b=wzgL+FZrc/X+hzZaF7lsn0YjEKYkeepxbRUqFbY9Zuc606QNHiesAFPsYD9Xxt+yZl SPBY4XkW/FfQcIvxmma6uJss/8oIaVkzApUSRkJm/JAb5s+KPtsn59hl+QQPRdIWnmF4 U5BO+JM99SUUZy2CZG5B8NH04hBL1LIFBNejeo11Z831wsS7Kvxi/TG65UXiPwoH13wO fJyIIbSPRb3MtgwU8+b3vTSaxrZQQwxK5P8Vw75xJ6LosdFx/TbcjBe2eVnh+VRXt30P xFFo93zGWPSmBBoSq/v358GAMQo1S7mdUwpBDNQVjasa5Jlur6rEA6ncf9gB0UIibDPe URhg== 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=Tb5z2UeOLZl/UqO+U9twmLjCGpyhePDzuQ8mmkofF+4=; b=CtCi+794cUZ2tSL7bCBlVN+lC/7A3RZnr0IjUe7JA60E7TOsdfuciJhhz5kFUmXFkR DQ0gZj6Zdzg4gCXnliqLK/N4DbFvfYZSPyrmohiFZS0aLT6YmbYDlqUt8Sz6fB7KKiGR VTA9KOxNYGIHVNKoFu6svKHp6hsRHMlbLdX97sesVwWeCSuTjdngNyujA5YpPfYVRlNe z6616czJWycJvKTNbHxJizOUgQrdY7pNG/y4h1Y6v2pXnT4T7lVG0GVbkdFNtIpEGH0E rC4sMQuvmOMj3kSgNu3y4kQ/Oeu0WUl9gh7MiJqSknoIIr4Od5tyEw5z53FNizz7//Yy sYaA== X-Gm-Message-State: APjAAAV46KM96zKS6yKQB8BGOKvqcf2r/rZFGQKSI18KG2zh5zFosFSP 2J8NMeKHFg+X7bhKQkhi1OZXbA== X-Received: by 2002:a1c:1fd0:: with SMTP id f199mr3399912wmf.113.1582192906765; Thu, 20 Feb 2020 02:01:46 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-188-94.w2-15.abo.wanadoo.fr. [2.15.37.94]) by smtp.gmail.com with ESMTPSA id z1sm3663496wmf.42.2020.02.20.02.01.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 02:01:46 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Srinivas Kandagatla , Khouloud Touil , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 1/4] nvmem: fix memory leak in error path Date: Thu, 20 Feb 2020 11:01:38 +0100 Message-Id: <20200220100141.5905-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200220100141.5905-1-brgl@bgdev.pl> References: <20200220100141.5905-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 free the ida mapping and nvmem struct if the write-protect GPIO lookup fails. Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin") Signed-off-by: Bartosz Golaszewski --- drivers/nvmem/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 503da67dde06..948c7ebce340 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -353,8 +353,11 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) else nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", GPIOD_OUT_HIGH); - if (IS_ERR(nvmem->wp_gpio)) + if (IS_ERR(nvmem->wp_gpio)) { + ida_simple_remove(&nvmem_ida, nvmem->id); + kfree(nvmem); return ERR_CAST(nvmem->wp_gpio); + } kref_init(&nvmem->refcnt); INIT_LIST_HEAD(&nvmem->cells); -- 2.25.0