Commit 0b8e125e authored by Qiushi Wu's avatar Qiushi Wu Committed by Jason Gunthorpe

RDMA/core: Fix several reference count leaks.

kobject_init_and_add() takes reference even when it fails.  If this
function returns an error, kobject_put() must be called to properly clean
up the memory associated with the object. Previous
commit b8eb7183 ("net-sysfs: Fix reference count leak in
rx|netdev_queue_add_kobject") fixed a similar problem.

Link: https://lore.kernel.org/r/20200528030231.9082-1-wu000273@umn.eduSigned-off-by: default avatarQiushi Wu <wu000273@umn.edu>
Reviewed-by: default avatarJason Gunthorpe <jgg@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent bcafcdfd
...@@ -1058,8 +1058,7 @@ static int add_port(struct ib_core_device *coredev, int port_num) ...@@ -1058,8 +1058,7 @@ static int add_port(struct ib_core_device *coredev, int port_num)
coredev->ports_kobj, coredev->ports_kobj,
"%d", port_num); "%d", port_num);
if (ret) { if (ret) {
kfree(p); goto err_put;
return ret;
} }
p->gid_attr_group = kzalloc(sizeof(*p->gid_attr_group), GFP_KERNEL); p->gid_attr_group = kzalloc(sizeof(*p->gid_attr_group), GFP_KERNEL);
...@@ -1072,8 +1071,7 @@ static int add_port(struct ib_core_device *coredev, int port_num) ...@@ -1072,8 +1071,7 @@ static int add_port(struct ib_core_device *coredev, int port_num)
ret = kobject_init_and_add(&p->gid_attr_group->kobj, &gid_attr_type, ret = kobject_init_and_add(&p->gid_attr_group->kobj, &gid_attr_type,
&p->kobj, "gid_attrs"); &p->kobj, "gid_attrs");
if (ret) { if (ret) {
kfree(p->gid_attr_group); goto err_put_gid_attrs;
goto err_put;
} }
if (device->ops.process_mad && is_full_dev) { if (device->ops.process_mad && is_full_dev) {
...@@ -1404,8 +1402,10 @@ int ib_port_register_module_stat(struct ib_device *device, u8 port_num, ...@@ -1404,8 +1402,10 @@ int ib_port_register_module_stat(struct ib_device *device, u8 port_num,
ret = kobject_init_and_add(kobj, ktype, &port->kobj, "%s", ret = kobject_init_and_add(kobj, ktype, &port->kobj, "%s",
name); name);
if (ret) if (ret) {
kobject_put(kobj);
return ret; return ret;
}
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment