net: ehea: fix possible memory leak in ehea_register_port()
authorYang Yingliang <yangyingliang@huawei.com>
Tue, 25 Oct 2022 13:00:11 +0000 (21:00 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Nov 2022 14:49:19 +0000 (23:49 +0900)
commitd7562f3305b5fe282a40bc59795201a5ae43f789
treef65206d795dba51f4eb150c5b3a966c47e556d32
parent636e16fa27f47cec5c97d1ecb52b03095fef15e0
net: ehea: fix possible memory leak in ehea_register_port()

[ Upstream commit 0e7ce23a917a9cc83ca3c779fbba836bca3bcf1e ]

If of_device_register() returns error, the of node and the
name allocated in dev_set_name() is leaked, call put_device()
to give up the reference that was set in device_initialize(),
so that of node is put in logical_port_release() and the name
is freed in kobject_cleanup().

Fixes: 1acf2318dd13 ("ehea: dynamic add / remove port")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221025130011.1071357-1-yangyingliang@huawei.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/ibm/ehea/ehea_main.c