Commit 90efc8b2 authored by Kamal Heib's avatar Kamal Heib Committed by Jason Gunthorpe

RDMA/core: Expose pkeys sysfs files only if pkey_tbl_len is set

Expose the pkeys sysfs files only if the pkey_tbl_len is set by the
providers.

Link: https://lore.kernel.org/r/20200714183414.61069-2-kamalheib1@gmail.comSigned-off-by: default avatarKamal Heib <kamalheib1@gmail.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 5f0b2a60
......@@ -58,7 +58,7 @@ struct ib_port {
struct ib_device *ibdev;
struct gid_attr_group *gid_attr_group;
struct attribute_group gid_group;
struct attribute_group pkey_group;
struct attribute_group *pkey_group;
struct attribute_group *pma_table;
struct attribute_group *hw_stats_ag;
struct rdma_hw_stats *hw_stats;
......@@ -681,11 +681,16 @@ static void ib_port_release(struct kobject *kobj)
kfree(p->gid_group.attrs);
}
if (p->pkey_group.attrs) {
for (i = 0; (a = p->pkey_group.attrs[i]); ++i)
kfree(a);
if (p->pkey_group) {
if (p->pkey_group->attrs) {
for (i = 0; (a = p->pkey_group->attrs[i]); ++i)
kfree(a);
kfree(p->pkey_group->attrs);
}
kfree(p->pkey_group.attrs);
kfree(p->pkey_group);
p->pkey_group = NULL;
}
kfree(p);
......@@ -1118,17 +1123,26 @@ static int add_port(struct ib_core_device *coredev, int port_num)
if (ret)
goto err_free_gid_type;
p->pkey_group.name = "pkeys";
p->pkey_group.attrs = alloc_group_attrs(show_port_pkey,
attr.pkey_tbl_len);
if (!p->pkey_group.attrs) {
ret = -ENOMEM;
goto err_remove_gid_type;
if (attr.pkey_tbl_len) {
p->pkey_group = kzalloc(sizeof(*p->pkey_group), GFP_KERNEL);
if (!p->pkey_group) {
ret = -ENOMEM;
goto err_remove_gid_type;
}
p->pkey_group->name = "pkeys";
p->pkey_group->attrs = alloc_group_attrs(show_port_pkey,
attr.pkey_tbl_len);
if (!p->pkey_group->attrs) {
ret = -ENOMEM;
goto err_free_pkey_group;
}
ret = sysfs_create_group(&p->kobj, p->pkey_group);
if (ret)
goto err_free_pkey;
}
ret = sysfs_create_group(&p->kobj, &p->pkey_group);
if (ret)
goto err_free_pkey;
if (device->ops.init_port && is_full_dev) {
ret = device->ops.init_port(device, port_num, &p->kobj);
......@@ -1150,14 +1164,20 @@ static int add_port(struct ib_core_device *coredev, int port_num)
return 0;
err_remove_pkey:
sysfs_remove_group(&p->kobj, &p->pkey_group);
if (p->pkey_group)
sysfs_remove_group(&p->kobj, p->pkey_group);
err_free_pkey:
for (i = 0; i < attr.pkey_tbl_len; ++i)
kfree(p->pkey_group.attrs[i]);
if (p->pkey_group) {
for (i = 0; i < attr.pkey_tbl_len; ++i)
kfree(p->pkey_group->attrs[i]);
kfree(p->pkey_group->attrs);
p->pkey_group->attrs = NULL;
}
kfree(p->pkey_group.attrs);
p->pkey_group.attrs = NULL;
err_free_pkey_group:
kfree(p->pkey_group);
err_remove_gid_type:
sysfs_remove_group(&p->gid_attr_group->kobj,
......@@ -1317,7 +1337,8 @@ void ib_free_port_attrs(struct ib_core_device *coredev)
if (port->pma_table)
sysfs_remove_group(p, port->pma_table);
sysfs_remove_group(p, &port->pkey_group);
if (port->pkey_group)
sysfs_remove_group(p, port->pkey_group);
sysfs_remove_group(p, &port->gid_group);
sysfs_remove_group(&port->gid_attr_group->kobj,
&port->gid_attr_group->ndev);
......
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