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 55AE115C82 for ; Mon, 5 Dec 2022 19:18:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB942C433D6; Mon, 5 Dec 2022 19:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1670267919; bh=mb3XrAhHEBZckT2Jd0mcHkveYzNavx7VJ29yZVpckoY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y0kJDW8C8DeAY0OB15oeJ49aeSMr/VUvmOtTb4aHPuGec+27IDEb6J4UKGiSP/wuL ff6/oNijr7ztSVjiaViVu1DKVnEV81ZD9I5kkSCa787CIciR17Q5vwTgZrE91gKl4J CcKm1deu7tDgMCkqJUwiGMNxBgpIuSzUWxhHi/N4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yang Yingliang , Michael Kelley , Wei Liu , Sasha Levin Subject: [PATCH 4.19 021/105] Drivers: hv: vmbus: fix possible memory leak in vmbus_device_register() Date: Mon, 5 Dec 2022 20:08:53 +0100 Message-Id: <20221205190803.866585767@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221205190803.124472741@linuxfoundation.org> References: <20221205190803.124472741@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 25c94b051592c010abe92c85b0485f1faedc83f3 ] If device_register() returns error in vmbus_device_register(), the name allocated by dev_set_name() must 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(). Fixes: 09d50ff8a233 ("Staging: hv: make the Hyper-V virtual bus code build") Signed-off-by: Yang Yingliang Reviewed-by: Michael Kelley Link: https://lore.kernel.org/r/20221119081135.1564691-3-yangyingliang@huawei.com Signed-off-by: Wei Liu Signed-off-by: Sasha Levin --- drivers/hv/vmbus_drv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 9cbe0b00ebf7..a2a304e7d10c 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1634,6 +1634,7 @@ int vmbus_device_register(struct hv_device *child_device_obj) ret = device_register(&child_device_obj->device); if (ret) { pr_err("Unable to register child device\n"); + put_device(&child_device_obj->device); return ret; } -- 2.35.1