From patchwork Tue Jan 3 16:59:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 13087857 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 E60CFC4708D for ; Tue, 3 Jan 2023 18:26:15 +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:Date:Message-Id:MIME-Version:Subject:Cc :To:From:References:In-Reply-To:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zSU+jcXV4l2NvUlTQXMTS7CsxUCUZH3NHiVktuIUB4A=; b=a4KySmczxpYzFD BaOEf1jpyJ9kdbLWHH8ARrRPYatd5KqdRqJZC4qqyheXSZ9ILTXbOWXfyq+tpuj/sBVPgQFtDiE+X XBHXZi1EkjvA1h0TTOJhGD2LzUo4z6jg7xXuoUmXN9sv9FO6cFp3Lt+lXP7Xsn9I2bQ8H0WqGBNPS FKxmAtSmpKU6a3SOqkwnhH/8RLHHhFy7lzHawlU5lyOdUC7Dfi3NnoNhQDid5vfPuyPEnumFkfOXc OtG3tkT8aCUcAB/V+D9vglqvXa18EOb7i11rch+7CwcC71G5LvwFO6A40prvBIz6jpOPUs+FWRUY7 swmcidRiwmsPFbg5JkYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pClxV-003qgo-AM; Tue, 03 Jan 2023 18:24:23 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pCkdK-003Aue-2o for linux-arm-kernel@lists.infradead.org; Tue, 03 Jan 2023 16:59:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZS5H2asUTLZlbBEYJrrAV+i8ORfv/vUr4mwUuUH/Xa4=; b=u0FP7KO7xgXz/q1vqsICXY31OM nDIij8oKF/E3R0qNscFrCaRYqUMysaVqsCwQTNOmKL3Cgvk57s7EqYOGNkVugAMnYh9T5khmIqofQ 7W4tMPkyYz4TU3oqGZd6LhN2u/U7cd/xa2j2CnCUDBQqJXU7KEJ7JaHSnPp19GK3ohsCAPW24A/hb MU//WZZowbzKQdORkN0AH03mo+D6PEHyntsfZHr6/3pLYT8eV/u+gkwanHt7pNWK010jCMdwo3Qw/ 3Qh6bCteN03nxKE82MSpUS7X52sjCaMS3leR5xxk5uHaIrFoN7qMJVkYAIus25xDtwPhAVdKxI4q5 yuF63Fgg==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:32796 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pCkdG-0005c7-Vh; Tue, 03 Jan 2023 16:59:22 +0000 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.94.2) (envelope-from ) id 1pCkdG-004huq-0l; Tue, 03 Jan 2023 16:59:22 +0000 In-Reply-To: References: From: "Russell King (Oracle)" To: Srinivas Kandagatla Cc: Bartosz Golaszewski , Gaosheng Cui , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Maxime Ripard , Hector Martin Subject: [PATCH v3 2/5] nvmem: core: initialise nvmem->id early Bartosz Golaszewski ,Gaosheng Cui ,Greg Kroah-Hartman ,linux-arm-kernel@lists.infradead.org,linux-kernel@vger.kernel.org,Maxime Ripard , Hector Martin MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Tue, 03 Jan 2023 16:59:22 +0000 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230103_085926_232323_D5A15B53 X-CRM114-Status: GOOD ( 10.97 ) 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 The error path for wp_gpio attempts to free the IDA nvmem->id, but this has yet to be assigned, so will always be zero - leaking the ID allocated by ida_alloc(). Fix this by moving the initialisation of nvmem->id earlier. Fixes: f7d8d7dcd978 ("nvmem: fix memory leak in error path") Signed-off-by: Russell King (Oracle) --- drivers/nvmem/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index bf11e0c36d60..c1a40d9c3825 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -770,6 +770,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) return ERR_PTR(rval); } + nvmem->id = rval; + if (config->wp_gpio) nvmem->wp_gpio = config->wp_gpio; else if (!config->ignore_wp) @@ -785,7 +787,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) kref_init(&nvmem->refcnt); INIT_LIST_HEAD(&nvmem->cells); - nvmem->id = rval; nvmem->owner = config->owner; if (!nvmem->owner && config->dev->driver) nvmem->owner = config->dev->driver->owner;