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 065C179C0 for ; Wed, 30 Nov 2022 18:47:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 519DCC433C1; Wed, 30 Nov 2022 18:47:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1669834028; bh=58rhLA38/wHS6um87sVoJxvO6c4cciQP3Dl2E2Tw0n8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yV9Y231fGNz+vNlzVAcDGWpbneel9C/PS4ncdt/m2LrZL4W83FCyo4bOrJ5T7UZbP tUKcdSoKD5CBYhi1vf0SMoo1ZgcuVBJJ58iZSlUTApEmjVXA7TY34LTf/jqF78LQQC BOG1syBIpf+r5lMz67Y8bqAmPbA2xUV44qih489I= 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 6.0 102/289] Drivers: hv: vmbus: fix possible memory leak in vmbus_device_register() Date: Wed, 30 Nov 2022 19:21:27 +0100 Message-Id: <20221130180546.452776464@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221130180544.105550592@linuxfoundation.org> References: <20221130180544.105550592@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 3c833ea60db6..939ccf921e71 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2083,6 +2083,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