From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C618F17731 for ; Wed, 9 Aug 2023 11:06:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45354C433C7; Wed, 9 Aug 2023 11:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1691579165; bh=C7wbw4ld1mLUGb/sr/ZejqoY62a8lzqk/jSj2qfiQpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LjrIwGr20iw1LjIQecWXj+nv8k2Jor2kX0EFBFzlfk7yVRVdqC3rN1+2t4HsnfMET wfdBISek/+LK8xu6TiM+DMcWvxnuu5nks/A4BFKt+dFZAztLGi0Pc9f3qKY9vGntha 2GUX6cjnF8sL7S6l0Lz6BtTYNIrWrfo81hyZOn4c= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yang Yingliang , Dave Jiang , Jon Mason , Sasha Levin Subject: [PATCH 4.14 098/204] NTB: ntb_transport: fix possible memory leak while device_register() fails Date: Wed, 9 Aug 2023 12:40:36 +0200 Message-ID: <20230809103645.913053731@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230809103642.552405807@linuxfoundation.org> References: <20230809103642.552405807@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Yang Yingliang [ Upstream commit 8623ccbfc55d962e19a3537652803676ad7acb90 ] If device_register() returns error, the name allocated by dev_set_name() need be freed. As comment of device_register() says, it should use put_device() to give up the reference in the error path. So fix this by calling put_device(), then the name can be freed in kobject_cleanup(), and client_dev is freed in ntb_transport_client_release(). Fixes: fce8a7bb5b4b ("PCI-Express Non-Transparent Bridge Support") Signed-off-by: Yang Yingliang Reviewed-by: Dave Jiang Signed-off-by: Jon Mason Signed-off-by: Sasha Levin --- drivers/ntb/ntb_transport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c index 18339b7e88a46..a58ced5d60433 100644 --- a/drivers/ntb/ntb_transport.c +++ b/drivers/ntb/ntb_transport.c @@ -395,7 +395,7 @@ int ntb_transport_register_client_dev(char *device_name) rc = device_register(dev); if (rc) { - kfree(client_dev); + put_device(dev); goto err; } -- 2.39.2