Commit 900d07c1 authored by Parav Pandit's avatar Parav Pandit Committed by Jason Gunthorpe

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: default avatarParav Pandit <parav@mellanox.com>
Reviewed-by: default avatarJack Morgenstein <jackm@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 623d1543
......@@ -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 @@ static int __init ib_umad_init(void)
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,
......
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