From patchwork Mon Feb 17 19:54:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 207288 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9F85C34028 for ; Mon, 17 Feb 2020 19:55:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7F29D215A4 for ; Mon, 17 Feb 2020 19:55:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="gs3t2/Ty" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729646AbgBQTyp (ORCPT ); Mon, 17 Feb 2020 14:54:45 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36240 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727332AbgBQTyn (ORCPT ); Mon, 17 Feb 2020 14:54:43 -0500 Received: by mail-wm1-f66.google.com with SMTP id p17so552030wma.1 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=EOxGaDwv7/qtifAPgZbHdJa1tw1N5Hsv51D8IhUh/G5ovjsb3WaaOpoxh+YC5q7Nm2 RL++mMBwhSU6G2o13KspT24+jve3SC27mrvHkDisetfCDC4grmuzz6r7MUvSogrqBIpl iFK7QCcwJyg/13LkLrHyGnob//DG0b2WuMGTHp45efobZYNI7NM1HZJ8PpXCj6opeHb1 UMyfEljgpfYXN2oWtZXPEngpSrhb7pTMGb8MLN3RTfA2dRc8EXJaG+s+3MqgkaRewzQt rhpbKaePlLrG8T+uhu3GWeNm3ld7rxtcBWnFZUSLTwahEuF7+mgfn7AkpSLHlZLoOQYp 991w== X-Gm-Message-State: APjAAAVeB/oURMcJlOU2o+3HN0mbRLkZ991luldKCHNY/gG8l0iN6QQa HCvytHeQ01DBDUQVIIpNx3kQyA== X-Google-Smtp-Source: APXvYqzCRYEvCvyjC143+OuW9Wo/mGyHqbMmxdGTb0RSKx1nDwE2TWGL9MQamtoIoyVcxmyNjrfDjg== 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 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@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); }