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)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 27 Oct 2022 10:51:41 +0000 (12:51 +0200)
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>
drivers/net/ethernet/ibm/ehea/ehea_main.c

index 294bdbbeacc335ff261d85b5c2c17faf2497f87c..b4aff59b3eb4fdd6182b8ceee6be4e1b11b15648 100644 (file)
@@ -2900,6 +2900,7 @@ static struct device *ehea_register_port(struct ehea_port *port,
        ret = of_device_register(&port->ofdev);
        if (ret) {
                pr_err("failed to register device. ret=%d\n", ret);
+               put_device(&port->ofdev.dev);
                goto out;
        }