Drivers: hv: vmbus: Fix memory leak in vmbus_add_channel_kobj
authorMiaoqian Lin <linmq006@gmail.com>
Thu, 3 Feb 2022 17:30:08 +0000 (01:30 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 23 Feb 2022 11:03:16 +0000 (12:03 +0100)
commitc377e2ba78d3fe9a1f0b4ec424e75f81da7e81e9
tree6b0f185bb51c9cf05ab41b3fb693ee07e1a31793
parent6936f02d14eda3668eda8714e323c32ab666ba42
Drivers: hv: vmbus: Fix memory leak in vmbus_add_channel_kobj

[ Upstream commit 8bc69f86328e87a0ffa79438430cc82f3aa6a194 ]

kobject_init_and_add() takes reference even when it fails.
According to the doc of kobject_init_and_add():

   If this function returns an error, kobject_put() must be called to
   properly clean up the memory associated with the object.

Fix memory leak by calling kobject_put().

Fixes: c2e5df616e1a ("vmbus: add per-channel sysfs info")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Reviewed-by: Juan Vazquez <juvazq@linux.microsoft.com>
Link: https://lore.kernel.org/r/20220203173008.43480-1-linmq006@gmail.com
Signed-off-by: Wei Liu <wei.liu@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hv/vmbus_drv.c