Skip to content

Commit

Permalink
RDMA/core: Move device addition deletion to device.c
Browse files Browse the repository at this point in the history
Move core device addition and removal from sysfs.c to device.c as device.c
is more appropriate place for device management.

Signed-off-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
  • Loading branch information
Parav Pandit authored and Jason Gunthorpe committed Feb 16, 2019
1 parent 5767198 commit 5f8f549
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 2 additions & 0 deletions drivers/infiniband/core/core_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct pkey_index_qp_list {
struct list_head qp_list;
};

extern const struct attribute_group ib_dev_attr_group;

int ib_device_register_sysfs(struct ib_device *device);
void ib_device_unregister_sysfs(struct ib_device *device);
int ib_device_rename(struct ib_device *ibdev, const char *name);
Expand Down
11 changes: 10 additions & 1 deletion drivers/infiniband/core/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ struct ib_device *_ib_alloc_device(size_t size)
rdma_restrack_init(device);

device->dev.class = &ib_class;
device->groups[0] = &ib_dev_attr_group;
device->dev.groups = device->groups;
device_initialize(&device->dev);

INIT_LIST_HEAD(&device->event_handler_list);
Expand Down Expand Up @@ -766,11 +768,15 @@ int ib_register_device(struct ib_device *device, const char *name)

ib_device_register_rdmacg(device);

ret = device_add(&device->dev);
if (ret)
goto cg_cleanup;

ret = ib_device_register_sysfs(device);
if (ret) {
dev_warn(&device->dev,
"Couldn't register device with driver model\n");
goto cg_cleanup;
goto dev_cleanup;
}

ret = enable_device(device);
Expand All @@ -781,6 +787,8 @@ int ib_register_device(struct ib_device *device, const char *name)

sysfs_cleanup:
ib_device_unregister_sysfs(device);
dev_cleanup:
device_del(&device->dev);
cg_cleanup:
ib_device_unregister_rdmacg(device);
ib_cache_cleanup_one(device);
Expand All @@ -800,6 +808,7 @@ void ib_unregister_device(struct ib_device *device)
{
disable_device(device);
ib_device_unregister_sysfs(device);
device_del(&device->dev);
ib_device_unregister_rdmacg(device);
ib_cache_cleanup_one(device);
release_name(device);
Expand Down
14 changes: 2 additions & 12 deletions drivers/infiniband/core/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ static struct attribute *ib_dev_attrs[] = {
NULL,
};

static const struct attribute_group dev_attr_group = {
const struct attribute_group ib_dev_attr_group = {
.attrs = ib_dev_attrs,
};

Expand Down Expand Up @@ -1338,18 +1338,10 @@ int ib_device_register_sysfs(struct ib_device *device)
{
int ret;

device->groups[0] = &dev_attr_group;
device->dev.groups = device->groups;

ret = device_add(&device->dev);
ret = ib_setup_port_attrs(device);
if (ret)
return ret;

ret = ib_setup_port_attrs(device);
if (ret) {
device_del(&device->dev);
return ret;
}
if (device->ops.alloc_hw_stats)
setup_hw_stats(device, NULL, 0);

Expand All @@ -1363,6 +1355,4 @@ void ib_device_unregister_sysfs(struct ib_device *device)
kfree(device->hw_stats);

ib_free_port_attrs(device);
/* Balances with device_add */
device_del(&device->dev);
}

0 comments on commit 5f8f549

Please sign in to comment.