Commit 5f8f5499 authored by Parav Pandit's avatar Parav Pandit Committed by Jason Gunthorpe

RDMA/core: Move device addition deletion to device.c

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: default avatarParav Pandit <parav@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 5767198a
...@@ -54,6 +54,8 @@ struct pkey_index_qp_list { ...@@ -54,6 +54,8 @@ struct pkey_index_qp_list {
struct list_head 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); int ib_device_register_sysfs(struct ib_device *device);
void ib_device_unregister_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); int ib_device_rename(struct ib_device *ibdev, const char *name);
......
...@@ -341,6 +341,8 @@ struct ib_device *_ib_alloc_device(size_t size) ...@@ -341,6 +341,8 @@ struct ib_device *_ib_alloc_device(size_t size)
rdma_restrack_init(device); rdma_restrack_init(device);
device->dev.class = &ib_class; device->dev.class = &ib_class;
device->groups[0] = &ib_dev_attr_group;
device->dev.groups = device->groups;
device_initialize(&device->dev); device_initialize(&device->dev);
INIT_LIST_HEAD(&device->event_handler_list); INIT_LIST_HEAD(&device->event_handler_list);
...@@ -766,11 +768,15 @@ int ib_register_device(struct ib_device *device, const char *name) ...@@ -766,11 +768,15 @@ int ib_register_device(struct ib_device *device, const char *name)
ib_device_register_rdmacg(device); ib_device_register_rdmacg(device);
ret = device_add(&device->dev);
if (ret)
goto cg_cleanup;
ret = ib_device_register_sysfs(device); ret = ib_device_register_sysfs(device);
if (ret) { if (ret) {
dev_warn(&device->dev, dev_warn(&device->dev,
"Couldn't register device with driver model\n"); "Couldn't register device with driver model\n");
goto cg_cleanup; goto dev_cleanup;
} }
ret = enable_device(device); ret = enable_device(device);
...@@ -781,6 +787,8 @@ int ib_register_device(struct ib_device *device, const char *name) ...@@ -781,6 +787,8 @@ int ib_register_device(struct ib_device *device, const char *name)
sysfs_cleanup: sysfs_cleanup:
ib_device_unregister_sysfs(device); ib_device_unregister_sysfs(device);
dev_cleanup:
device_del(&device->dev);
cg_cleanup: cg_cleanup:
ib_device_unregister_rdmacg(device); ib_device_unregister_rdmacg(device);
ib_cache_cleanup_one(device); ib_cache_cleanup_one(device);
...@@ -800,6 +808,7 @@ void ib_unregister_device(struct ib_device *device) ...@@ -800,6 +808,7 @@ void ib_unregister_device(struct ib_device *device)
{ {
disable_device(device); disable_device(device);
ib_device_unregister_sysfs(device); ib_device_unregister_sysfs(device);
device_del(&device->dev);
ib_device_unregister_rdmacg(device); ib_device_unregister_rdmacg(device);
ib_cache_cleanup_one(device); ib_cache_cleanup_one(device);
release_name(device); release_name(device);
......
...@@ -1275,7 +1275,7 @@ static struct attribute *ib_dev_attrs[] = { ...@@ -1275,7 +1275,7 @@ static struct attribute *ib_dev_attrs[] = {
NULL, NULL,
}; };
static const struct attribute_group dev_attr_group = { const struct attribute_group ib_dev_attr_group = {
.attrs = ib_dev_attrs, .attrs = ib_dev_attrs,
}; };
...@@ -1338,18 +1338,10 @@ int ib_device_register_sysfs(struct ib_device *device) ...@@ -1338,18 +1338,10 @@ int ib_device_register_sysfs(struct ib_device *device)
{ {
int ret; int ret;
device->groups[0] = &dev_attr_group; ret = ib_setup_port_attrs(device);
device->dev.groups = device->groups;
ret = device_add(&device->dev);
if (ret) if (ret)
return ret; return ret;
ret = ib_setup_port_attrs(device);
if (ret) {
device_del(&device->dev);
return ret;
}
if (device->ops.alloc_hw_stats) if (device->ops.alloc_hw_stats)
setup_hw_stats(device, NULL, 0); setup_hw_stats(device, NULL, 0);
...@@ -1363,6 +1355,4 @@ void ib_device_unregister_sysfs(struct ib_device *device) ...@@ -1363,6 +1355,4 @@ void ib_device_unregister_sysfs(struct ib_device *device)
kfree(device->hw_stats); kfree(device->hw_stats);
ib_free_port_attrs(device); ib_free_port_attrs(device);
/* Balances with device_add */
device_del(&device->dev);
} }
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