summaryrefslogtreecommitdiff
path: root/drivers/infiniband
diff options
context:
space:
mode:
authorParav Pandit <parav@mellanox.com>2018-12-21 17:19:23 +0300
committerJason Gunthorpe <jgg@mellanox.com>2018-12-21 20:39:36 +0300
commit900d07c12d4ed0e2c237655b55383df8d2c715ff (patch)
treec81e07d8d0e76b3a9c121617d5da5a3fdc51d6aa /drivers/infiniband
parent623d154305c06c83924b8fd2afbfdeba3b396fb7 (diff)
downloadlinux-900d07c12d4ed0e2c237655b55383df8d2c715ff.tar.xz
IB/umad: Simplify and avoid dynamic allocation of class
Simplify code to have a static structure instance for umad class allocation. This will allow to have class attributes defined along with class registration in subsequent patch and allows more class methods definition similar to ib_core module. Signed-off-by: Parav Pandit <parav@mellanox.com> Reviewed-by: Jack Morgenstein <jackm@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r--drivers/infiniband/core/user_mad.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
index ee3b1f7482b6..52ebb1711d14 100644
--- a/drivers/infiniband/core/user_mad.c
+++ b/drivers/infiniband/core/user_mad.c
@@ -130,8 +130,6 @@ struct ib_umad_packet {
struct ib_user_mad mad;
};
-static struct class *umad_class;
-
static const dev_t base_umad_dev = MKDEV(IB_UMAD_MAJOR, IB_UMAD_MINOR_BASE);
static const dev_t base_issm_dev = MKDEV(IB_UMAD_MAJOR, IB_UMAD_MINOR_BASE) +
IB_UMAD_NUM_FIXED_MINOR;
@@ -1151,6 +1149,16 @@ static DEVICE_ATTR(port, S_IRUGO, show_port, NULL);
static CLASS_ATTR_STRING(abi_version, S_IRUGO,
__stringify(IB_USER_MAD_ABI_VERSION));
+static char *umad_devnode(struct device *dev, umode_t *mode)
+{
+ return kasprintf(GFP_KERNEL, "infiniband/%s", dev_name(dev));
+}
+
+static struct class umad_class = {
+ .name = "infiniband_mad",
+ .devnode = umad_devnode,
+};
+
static int ib_umad_init_port(struct ib_device *device, int port_num,
struct ib_umad_device *umad_dev,
struct ib_umad_port *port)
@@ -1184,7 +1192,7 @@ static int ib_umad_init_port(struct ib_device *device, int port_num,
if (cdev_add(&port->cdev, base_umad, 1))
goto err_cdev;
- port->dev = device_create(umad_class, device->dev.parent,
+ port->dev = device_create(&umad_class, device->dev.parent,
port->cdev.dev, port,
"umad%d", port->dev_num);
if (IS_ERR(port->dev))
@@ -1202,7 +1210,7 @@ static int ib_umad_init_port(struct ib_device *device, int port_num,
if (cdev_add(&port->sm_cdev, base_issm, 1))
goto err_sm_cdev;
- port->sm_dev = device_create(umad_class, device->dev.parent,
+ port->sm_dev = device_create(&umad_class, device->dev.parent,
port->sm_cdev.dev, port,
"issm%d", port->dev_num);
if (IS_ERR(port->sm_dev))
@@ -1216,13 +1224,13 @@ static int ib_umad_init_port(struct ib_device *device, int port_num,
return 0;
err_sm_dev:
- device_destroy(umad_class, port->sm_cdev.dev);
+ device_destroy(&umad_class, port->sm_cdev.dev);
err_sm_cdev:
cdev_del(&port->sm_cdev);
err_dev:
- device_destroy(umad_class, port->cdev.dev);
+ device_destroy(&umad_class, port->cdev.dev);
err_cdev:
cdev_del(&port->cdev);
@@ -1239,8 +1247,8 @@ static void ib_umad_kill_port(struct ib_umad_port *port)
dev_set_drvdata(port->dev, NULL);
dev_set_drvdata(port->sm_dev, NULL);
- device_destroy(umad_class, port->cdev.dev);
- device_destroy(umad_class, port->sm_cdev.dev);
+ device_destroy(&umad_class, port->cdev.dev);
+ device_destroy(&umad_class, port->sm_cdev.dev);
cdev_del(&port->cdev);
cdev_del(&port->sm_cdev);
@@ -1327,11 +1335,6 @@ static void ib_umad_remove_one(struct ib_device *device, void *client_data)
kobject_put(&umad_dev->kobj);
}
-static char *umad_devnode(struct device *dev, umode_t *mode)
-{
- return kasprintf(GFP_KERNEL, "infiniband/%s", dev_name(dev));
-}
-
static int __init ib_umad_init(void)
{
int ret;
@@ -1353,16 +1356,13 @@ static int __init ib_umad_init(void)
}
dynamic_issm_dev = dynamic_umad_dev + IB_UMAD_NUM_DYNAMIC_MINOR;
- umad_class = class_create(THIS_MODULE, "infiniband_mad");
- if (IS_ERR(umad_class)) {
- ret = PTR_ERR(umad_class);
+ ret = class_register(&umad_class);
+ if (ret) {
pr_err("couldn't create class infiniband_mad\n");
goto out_chrdev;
}
- umad_class->devnode = umad_devnode;
-
- ret = class_create_file(umad_class, &class_attr_abi_version.attr);
+ ret = class_create_file(&umad_class, &class_attr_abi_version.attr);
if (ret) {
pr_err("couldn't create abi_version attribute\n");
goto out_class;
@@ -1377,7 +1377,7 @@ static int __init ib_umad_init(void)
return 0;
out_class:
- class_destroy(umad_class);
+ class_unregister(&umad_class);
out_chrdev:
unregister_chrdev_region(dynamic_umad_dev,
@@ -1394,7 +1394,7 @@ out:
static void __exit ib_umad_cleanup(void)
{
ib_unregister_client(&umad_client);
- class_destroy(umad_class);
+ class_unregister(&umad_class);
unregister_chrdev_region(base_umad_dev,
IB_UMAD_NUM_FIXED_MINOR * 2);
unregister_chrdev_region(dynamic_umad_dev,