Commit cad6d02a authored by Haggai Eran's avatar Haggai Eran Committed by Roland Dreier

IB/core: Fix port kobject deletion during error flow

When encountering an error during the add_port function, adding a port
to sysfs, the port kobject is freed without being deleted from sysfs.

Instead of freeing it directly, the patch uses kobject_put to release
the kobject and delete it.
Signed-off-by: default avatarHaggai Eran <haggaie@mellanox.com>
Signed-off-by: default avatarRoland Dreier <roland@purestorage.com>
parent 373c0ea1
...@@ -429,15 +429,19 @@ static void ib_port_release(struct kobject *kobj) ...@@ -429,15 +429,19 @@ static void ib_port_release(struct kobject *kobj)
struct attribute *a; struct attribute *a;
int i; int i;
for (i = 0; (a = p->gid_group.attrs[i]); ++i) if (p->gid_group.attrs) {
kfree(a); for (i = 0; (a = p->gid_group.attrs[i]); ++i)
kfree(a);
kfree(p->gid_group.attrs); kfree(p->gid_group.attrs);
}
for (i = 0; (a = p->pkey_group.attrs[i]); ++i) if (p->pkey_group.attrs) {
kfree(a); for (i = 0; (a = p->pkey_group.attrs[i]); ++i)
kfree(a);
kfree(p->pkey_group.attrs); kfree(p->pkey_group.attrs);
}
kfree(p); kfree(p);
} }
...@@ -536,8 +540,10 @@ static int add_port(struct ib_device *device, int port_num, ...@@ -536,8 +540,10 @@ static int add_port(struct ib_device *device, int port_num,
ret = kobject_init_and_add(&p->kobj, &port_type, ret = kobject_init_and_add(&p->kobj, &port_type,
device->ports_parent, device->ports_parent,
"%d", port_num); "%d", port_num);
if (ret) if (ret) {
goto err_put; kfree(p);
return ret;
}
ret = sysfs_create_group(&p->kobj, &pma_group); ret = sysfs_create_group(&p->kobj, &pma_group);
if (ret) if (ret)
...@@ -585,6 +591,7 @@ static int add_port(struct ib_device *device, int port_num, ...@@ -585,6 +591,7 @@ static int add_port(struct ib_device *device, int port_num,
kfree(p->pkey_group.attrs[i]); kfree(p->pkey_group.attrs[i]);
kfree(p->pkey_group.attrs); kfree(p->pkey_group.attrs);
p->pkey_group.attrs = NULL;
err_remove_gid: err_remove_gid:
sysfs_remove_group(&p->kobj, &p->gid_group); sysfs_remove_group(&p->kobj, &p->gid_group);
...@@ -594,12 +601,13 @@ static int add_port(struct ib_device *device, int port_num, ...@@ -594,12 +601,13 @@ static int add_port(struct ib_device *device, int port_num,
kfree(p->gid_group.attrs[i]); kfree(p->gid_group.attrs[i]);
kfree(p->gid_group.attrs); kfree(p->gid_group.attrs);
p->gid_group.attrs = NULL;
err_remove_pma: err_remove_pma:
sysfs_remove_group(&p->kobj, &pma_group); sysfs_remove_group(&p->kobj, &pma_group);
err_put: err_put:
kfree(p); kobject_put(&p->kobj);
return ret; return ret;
} }
......
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