]> git.karo-electronics.de Git - linux-beck.git/blobdiff - drivers/infiniband/core/user_mad.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/paulus/powerpc-merge
[linux-beck.git] / drivers / infiniband / core / user_mad.c
index fc5519a3de997e6592812326a8ba5f2334f38c29..97128e25f78bfd3b191536fcf854f877940abd0c 100644 (file)
@@ -64,18 +64,39 @@ enum {
        IB_UMAD_MINOR_BASE = 0
 };
 
+/*
+ * Our lifetime rules for these structs are the following: each time a
+ * device special file is opened, we look up the corresponding struct
+ * ib_umad_port by minor in the umad_port[] table while holding the
+ * port_lock.  If this lookup succeeds, we take a reference on the
+ * ib_umad_port's struct ib_umad_device while still holding the
+ * port_lock; if the lookup fails, we fail the open().  We drop these
+ * references in the corresponding close().
+ *
+ * In addition to references coming from open character devices, there
+ * is one more reference to each ib_umad_device representing the
+ * module's reference taken when allocating the ib_umad_device in
+ * ib_umad_add_one().
+ *
+ * When destroying an ib_umad_device, we clear all of its
+ * ib_umad_ports from umad_port[] while holding port_lock before
+ * dropping the module's reference to the ib_umad_device.  This is
+ * always safe because any open() calls will either succeed and obtain
+ * a reference before we clear the umad_port[] entries, or fail after
+ * we clear the umad_port[] entries.
+ */
+
 struct ib_umad_port {
-       int                    devnum;
-       struct cdev            dev;
-       struct class_device    class_dev;
+       struct cdev           *dev;
+       struct class_device   *class_dev;
 
-       int                    sm_devnum;
-       struct cdev            sm_dev;
-       struct class_device    sm_class_dev;
+       struct cdev           *sm_dev;
+       struct class_device   *sm_class_dev;
        struct semaphore       sm_sem;
 
        struct ib_device      *ib_dev;
        struct ib_umad_device *umad_dev;
+       int                    dev_num;
        u8                     port_num;
 };
 
@@ -99,17 +120,28 @@ struct ib_umad_packet {
        struct ib_mad_send_buf *msg;
        struct list_head   list;
        int                length;
-       DECLARE_PCI_UNMAP_ADDR(mapping)
        struct ib_user_mad mad;
 };
 
+static struct class *umad_class;
+
 static const dev_t base_dev = MKDEV(IB_UMAD_MAJOR, IB_UMAD_MINOR_BASE);
-static spinlock_t map_lock;
+
+static DEFINE_SPINLOCK(port_lock);
+static struct ib_umad_port *umad_port[IB_UMAD_MAX_PORTS];
 static DECLARE_BITMAP(dev_map, IB_UMAD_MAX_PORTS * 2);
 
 static void ib_umad_add_one(struct ib_device *device);
 static void ib_umad_remove_one(struct ib_device *device);
 
+static void ib_umad_release_dev(struct kref *ref)
+{
+       struct ib_umad_device *dev =
+               container_of(ref, struct ib_umad_device, ref);
+
+       kfree(dev);
+}
+
 static int queue_packet(struct ib_umad_file *file,
                        struct ib_mad_agent *agent,
                        struct ib_umad_packet *packet)
@@ -145,15 +177,12 @@ static void send_handler(struct ib_mad_agent *agent,
        ib_free_send_mad(packet->msg);
 
        if (send_wc->status == IB_WC_RESP_TIMEOUT_ERR) {
-               timeout = kmalloc(sizeof *timeout + sizeof (struct ib_mad_hdr),
-                                 GFP_KERNEL);
+               timeout = kzalloc(sizeof *timeout + IB_MGMT_MAD_HDR, GFP_KERNEL);
                if (!timeout)
                        goto out;
 
-               memset(timeout, 0, sizeof *timeout + sizeof (struct ib_mad_hdr));
-
-               timeout->length = sizeof (struct ib_mad_hdr);
-               timeout->mad.hdr.id = packet->mad.hdr.id;
+               timeout->length         = IB_MGMT_MAD_HDR;
+               timeout->mad.hdr.id     = packet->mad.hdr.id;
                timeout->mad.hdr.status = ETIMEDOUT;
                memcpy(timeout->mad.data, packet->mad.data,
                       sizeof (struct ib_mad_hdr));
@@ -176,11 +205,10 @@ static void recv_handler(struct ib_mad_agent *agent,
                goto out;
 
        length = mad_recv_wc->mad_len;
-       packet = kmalloc(sizeof *packet + length, GFP_KERNEL);
+       packet = kzalloc(sizeof *packet + length, GFP_KERNEL);
        if (!packet)
                goto out;
 
-       memset(packet, 0, sizeof *packet + length);
        packet->length = length;
 
        ib_coalesce_recv_mad(mad_recv_wc, packet->mad.data);
@@ -246,7 +274,7 @@ static ssize_t ib_umad_read(struct file *filp, char __user *buf,
                else
                        ret = -ENOSPC;
        } else if (copy_to_user(buf, &packet->mad,
-                             packet->length + sizeof (struct ib_user_mad)))
+                               packet->length + sizeof (struct ib_user_mad)))
                ret = -EFAULT;
        else
                ret = packet->length + sizeof (struct ib_user_mad);
@@ -271,22 +299,19 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
        struct ib_rmpp_mad *rmpp_mad;
        u8 method;
        __be64 *tid;
-       int ret, length, hdr_len, rmpp_hdr_size;
+       int ret, length, hdr_len, copy_offset;
        int rmpp_active = 0;
 
        if (count < sizeof (struct ib_user_mad))
                return -EINVAL;
 
        length = count - sizeof (struct ib_user_mad);
-       packet = kmalloc(sizeof *packet + sizeof(struct ib_mad_hdr) +
-                        sizeof (struct ib_rmpp_hdr), GFP_KERNEL);
+       packet = kmalloc(sizeof *packet + IB_MGMT_RMPP_HDR, GFP_KERNEL);
        if (!packet)
                return -ENOMEM;
 
        if (copy_from_user(&packet->mad, buf,
-                           sizeof (struct ib_user_mad) +
-                           sizeof (struct ib_mad_hdr) +
-                           sizeof (struct ib_rmpp_hdr))) {
+                           sizeof (struct ib_user_mad) + IB_MGMT_RMPP_HDR)) {
                ret = -EFAULT;
                goto err;
        }
@@ -297,8 +322,6 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
                goto err;
        }
 
-       packet->length = length;
-
        down_read(&file->agent_mutex);
 
        agent = file->agent[packet->mad.hdr.id];
@@ -345,12 +368,10 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
                        goto err_ah;
                }
                rmpp_active = 1;
+               copy_offset = IB_MGMT_RMPP_HDR;
        } else {
-               if (length > sizeof (struct ib_mad)) {
-                       ret = -EINVAL;
-                       goto err_ah;
-               }
                hdr_len = IB_MGMT_MAD_HDR;
+               copy_offset = IB_MGMT_MAD_HDR;
        }
 
        packet->msg = ib_create_send_mad(agent,
@@ -368,28 +389,14 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
        packet->msg->retries    = packet->mad.hdr.retries;
        packet->msg->context[0] = packet;
 
-       if (!rmpp_active) {
-               /* Copy message from user into send buffer */
-               if (copy_from_user(packet->msg->mad,
-                                  buf + sizeof (struct ib_user_mad), length)) {
-                       ret = -EFAULT;
-                       goto err_msg;
-               }
-       } else {
-               rmpp_hdr_size = sizeof (struct ib_mad_hdr) +
-                               sizeof (struct ib_rmpp_hdr);
-
-               /* Only copy MAD headers (RMPP header in place) */
-               memcpy(packet->msg->mad, packet->mad.data,
-                      sizeof (struct ib_mad_hdr));
-
-               /* Now, copy rest of message from user into send buffer */
-               if (copy_from_user(((struct ib_rmpp_mad *) packet->msg->mad)->data,
-                                  buf + sizeof (struct ib_user_mad) + rmpp_hdr_size,
-                                  length - rmpp_hdr_size)) {
-                       ret = -EFAULT;
-                       goto err_msg;
-               }
+       /* Copy MAD headers (RMPP header in place) */
+       memcpy(packet->msg->mad, packet->mad.data, IB_MGMT_MAD_HDR);
+       /* Now, copy rest of message from user into send buffer */
+       if (copy_from_user(packet->msg->mad + copy_offset,
+                          buf + sizeof (struct ib_user_mad) + copy_offset,
+                          length - copy_offset)) {
+               ret = -EFAULT;
+               goto err_msg;
        }
 
        /*
@@ -398,12 +405,12 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
         * transaction ID matches the agent being used to send the
         * MAD.
         */
-       method = ((struct ib_mad_hdr *) packet->msg)->method;
+       method = ((struct ib_mad_hdr *) packet->msg->mad)->method;
 
        if (!(method & IB_MGMT_METHOD_RESP)       &&
            method != IB_MGMT_METHOD_TRAP_REPRESS &&
            method != IB_MGMT_METHOD_SEND) {
-               tid = &((struct ib_mad_hdr *) packet->msg)->tid;
+               tid = &((struct ib_mad_hdr *) packet->msg->mad)->tid;
                *tid = cpu_to_be64(((u64) agent->hi_tid) << 32 |
                                   (be64_to_cpup(tid) & 0xffffffff));
        }
@@ -414,7 +421,7 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
 
        up_read(&file->agent_mutex);
 
-       return sizeof (struct ib_user_mad_hdr) + packet->length;
+       return count;
 
 err_msg:
        ib_free_send_mad(packet->msg);
@@ -560,15 +567,23 @@ static long ib_umad_ioctl(struct file *filp, unsigned int cmd,
 
 static int ib_umad_open(struct inode *inode, struct file *filp)
 {
-       struct ib_umad_port *port =
-               container_of(inode->i_cdev, struct ib_umad_port, dev);
+       struct ib_umad_port *port;
        struct ib_umad_file *file;
 
-       file = kmalloc(sizeof *file, GFP_KERNEL);
-       if (!file)
-               return -ENOMEM;
+       spin_lock(&port_lock);
+       port = umad_port[iminor(inode) - IB_UMAD_MINOR_BASE];
+       if (port)
+               kref_get(&port->umad_dev->ref);
+       spin_unlock(&port_lock);
 
-       memset(file, 0, sizeof *file);
+       if (!port)
+               return -ENXIO;
+
+       file = kzalloc(sizeof *file, GFP_KERNEL);
+       if (!file) {
+               kref_put(&port->umad_dev->ref, ib_umad_release_dev);
+               return -ENOMEM;
+       }
 
        spin_lock_init(&file->recv_lock);
        init_rwsem(&file->agent_mutex);
@@ -584,6 +599,7 @@ static int ib_umad_open(struct inode *inode, struct file *filp)
 static int ib_umad_close(struct inode *inode, struct file *filp)
 {
        struct ib_umad_file *file = filp->private_data;
+       struct ib_umad_device *dev = file->port->umad_dev;
        struct ib_umad_packet *packet, *tmp;
        int i;
 
@@ -598,6 +614,8 @@ static int ib_umad_close(struct inode *inode, struct file *filp)
 
        kfree(file);
 
+       kref_put(&dev->ref, ib_umad_release_dev);
+
        return 0;
 }
 
@@ -614,30 +632,46 @@ static struct file_operations umad_fops = {
 
 static int ib_umad_sm_open(struct inode *inode, struct file *filp)
 {
-       struct ib_umad_port *port =
-               container_of(inode->i_cdev, struct ib_umad_port, sm_dev);
+       struct ib_umad_port *port;
        struct ib_port_modify props = {
                .set_port_cap_mask = IB_PORT_SM
        };
        int ret;
 
+       spin_lock(&port_lock);
+       port = umad_port[iminor(inode) - IB_UMAD_MINOR_BASE - IB_UMAD_MAX_PORTS];
+       if (port)
+               kref_get(&port->umad_dev->ref);
+       spin_unlock(&port_lock);
+
+       if (!port)
+               return -ENXIO;
+
        if (filp->f_flags & O_NONBLOCK) {
-               if (down_trylock(&port->sm_sem))
-                       return -EAGAIN;
+               if (down_trylock(&port->sm_sem)) {
+                       ret = -EAGAIN;
+                       goto fail;
+               }
        } else {
-               if (down_interruptible(&port->sm_sem))
-                       return -ERESTARTSYS;
+               if (down_interruptible(&port->sm_sem)) {
+                       ret = -ERESTARTSYS;
+                       goto fail;
+               }
        }
 
        ret = ib_modify_port(port->ib_dev, port->port_num, 0, &props);
        if (ret) {
                up(&port->sm_sem);
-               return ret;
+               goto fail;
        }
 
        filp->private_data = port;
 
        return 0;
+
+fail:
+       kref_put(&port->umad_dev->ref, ib_umad_release_dev);
+       return ret;
 }
 
 static int ib_umad_sm_close(struct inode *inode, struct file *filp)
@@ -651,6 +685,8 @@ static int ib_umad_sm_close(struct inode *inode, struct file *filp)
        ret = ib_modify_port(port->ib_dev, port->port_num, 0, &props);
        up(&port->sm_sem);
 
+       kref_put(&port->umad_dev->ref, ib_umad_release_dev);
+
        return ret;
 }
 
@@ -670,6 +706,9 @@ static ssize_t show_ibdev(struct class_device *class_dev, char *buf)
 {
        struct ib_umad_port *port = class_get_devdata(class_dev);
 
+       if (!port)
+               return -ENODEV;
+
        return sprintf(buf, "%s\n", port->ib_dev->name);
 }
 static CLASS_DEVICE_ATTR(ibdev, S_IRUGO, show_ibdev, NULL);
@@ -678,38 +717,13 @@ static ssize_t show_port(struct class_device *class_dev, char *buf)
 {
        struct ib_umad_port *port = class_get_devdata(class_dev);
 
+       if (!port)
+               return -ENODEV;
+
        return sprintf(buf, "%d\n", port->port_num);
 }
 static CLASS_DEVICE_ATTR(port, S_IRUGO, show_port, NULL);
 
-static void ib_umad_release_dev(struct kref *ref)
-{
-       struct ib_umad_device *dev =
-               container_of(ref, struct ib_umad_device, ref);
-
-       kfree(dev);
-}
-
-static void ib_umad_release_port(struct class_device *class_dev)
-{
-       struct ib_umad_port *port = class_get_devdata(class_dev);
-
-       if (class_dev == &port->class_dev) {
-               cdev_del(&port->dev);
-               clear_bit(port->devnum, dev_map);
-       } else {
-               cdev_del(&port->sm_dev);
-               clear_bit(port->sm_devnum, dev_map);
-       }
-
-       kref_put(&port->umad_dev->ref, ib_umad_release_dev);
-}
-
-static struct class umad_class = {
-       .name    = "infiniband_mad",
-       .release = ib_umad_release_port
-};
-
 static ssize_t show_abi_version(struct class *class, char *buf)
 {
        return sprintf(buf, "%d\n", IB_USER_MAD_ABI_VERSION);
@@ -719,89 +733,102 @@ static CLASS_ATTR(abi_version, S_IRUGO, show_abi_version, NULL);
 static int ib_umad_init_port(struct ib_device *device, int port_num,
                             struct ib_umad_port *port)
 {
-       spin_lock(&map_lock);
-       port->devnum = find_first_zero_bit(dev_map, IB_UMAD_MAX_PORTS);
-       if (port->devnum >= IB_UMAD_MAX_PORTS) {
-               spin_unlock(&map_lock);
+       spin_lock(&port_lock);
+       port->dev_num = find_first_zero_bit(dev_map, IB_UMAD_MAX_PORTS);
+       if (port->dev_num >= IB_UMAD_MAX_PORTS) {
+               spin_unlock(&port_lock);
                return -1;
        }
-       port->sm_devnum = find_next_zero_bit(dev_map, IB_UMAD_MAX_PORTS * 2, IB_UMAD_MAX_PORTS);
-       if (port->sm_devnum >= IB_UMAD_MAX_PORTS * 2) {
-               spin_unlock(&map_lock);
-               return -1;
-       }
-       set_bit(port->devnum, dev_map);
-       set_bit(port->sm_devnum, dev_map);
-       spin_unlock(&map_lock);
+       set_bit(port->dev_num, dev_map);
+       spin_unlock(&port_lock);
 
        port->ib_dev   = device;
        port->port_num = port_num;
        init_MUTEX(&port->sm_sem);
 
-       cdev_init(&port->dev, &umad_fops);
-       port->dev.owner = THIS_MODULE;
-       kobject_set_name(&port->dev.kobj, "umad%d", port->devnum);
-       if (cdev_add(&port->dev, base_dev + port->devnum, 1))
+       port->dev = cdev_alloc();
+       if (!port->dev)
                return -1;
-
-       port->class_dev.class = &umad_class;
-       port->class_dev.dev   = device->dma_device;
-       port->class_dev.devt  = port->dev.dev;
-
-       snprintf(port->class_dev.class_id, BUS_ID_SIZE, "umad%d", port->devnum);
-
-       if (class_device_register(&port->class_dev))
+       port->dev->owner = THIS_MODULE;
+       port->dev->ops   = &umad_fops;
+       kobject_set_name(&port->dev->kobj, "umad%d", port->dev_num);
+       if (cdev_add(port->dev, base_dev + port->dev_num, 1))
                goto err_cdev;
 
-       class_set_devdata(&port->class_dev, port);
-       kref_get(&port->umad_dev->ref);
+       port->class_dev = class_device_create(umad_class, NULL, port->dev->dev,
+                                             device->dma_device,
+                                             "umad%d", port->dev_num);
+       if (IS_ERR(port->class_dev))
+               goto err_cdev;
 
-       if (class_device_create_file(&port->class_dev, &class_device_attr_ibdev))
+       if (class_device_create_file(port->class_dev, &class_device_attr_ibdev))
                goto err_class;
-       if (class_device_create_file(&port->class_dev, &class_device_attr_port))
+       if (class_device_create_file(port->class_dev, &class_device_attr_port))
                goto err_class;
 
-       cdev_init(&port->sm_dev, &umad_sm_fops);
-       port->sm_dev.owner = THIS_MODULE;
-       kobject_set_name(&port->dev.kobj, "issm%d", port->sm_devnum - IB_UMAD_MAX_PORTS);
-       if (cdev_add(&port->sm_dev, base_dev + port->sm_devnum, 1))
-               return -1;
-
-       port->sm_class_dev.class = &umad_class;
-       port->sm_class_dev.dev   = device->dma_device;
-       port->sm_class_dev.devt  = port->sm_dev.dev;
-
-       snprintf(port->sm_class_dev.class_id, BUS_ID_SIZE, "issm%d", port->sm_devnum - IB_UMAD_MAX_PORTS);
+       port->sm_dev = cdev_alloc();
+       if (!port->sm_dev)
+               goto err_class;
+       port->sm_dev->owner = THIS_MODULE;
+       port->sm_dev->ops   = &umad_sm_fops;
+       kobject_set_name(&port->dev->kobj, "issm%d", port->dev_num);
+       if (cdev_add(port->sm_dev, base_dev + port->dev_num + IB_UMAD_MAX_PORTS, 1))
+               goto err_sm_cdev;
 
-       if (class_device_register(&port->sm_class_dev))
+       port->sm_class_dev = class_device_create(umad_class, NULL, port->sm_dev->dev,
+                                                device->dma_device,
+                                                "issm%d", port->dev_num);
+       if (IS_ERR(port->sm_class_dev))
                goto err_sm_cdev;
 
-       class_set_devdata(&port->sm_class_dev, port);
-       kref_get(&port->umad_dev->ref);
+       class_set_devdata(port->class_dev,    port);
+       class_set_devdata(port->sm_class_dev, port);
 
-       if (class_device_create_file(&port->sm_class_dev, &class_device_attr_ibdev))
+       if (class_device_create_file(port->sm_class_dev, &class_device_attr_ibdev))
                goto err_sm_class;
-       if (class_device_create_file(&port->sm_class_dev, &class_device_attr_port))
+       if (class_device_create_file(port->sm_class_dev, &class_device_attr_port))
                goto err_sm_class;
 
+       spin_lock(&port_lock);
+       umad_port[port->dev_num] = port;
+       spin_unlock(&port_lock);
+
        return 0;
 
 err_sm_class:
-       class_device_unregister(&port->sm_class_dev);
+       class_device_destroy(umad_class, port->sm_dev->dev);
 
 err_sm_cdev:
-       cdev_del(&port->sm_dev);
+       cdev_del(port->sm_dev);
 
 err_class:
-       class_device_unregister(&port->class_dev);
+       class_device_destroy(umad_class, port->dev->dev);
 
 err_cdev:
-       cdev_del(&port->dev);
-       clear_bit(port->devnum, dev_map);
+       cdev_del(port->dev);
+       clear_bit(port->dev_num, dev_map);
 
        return -1;
 }
 
+static void ib_umad_kill_port(struct ib_umad_port *port)
+{
+       class_set_devdata(port->class_dev,    NULL);
+       class_set_devdata(port->sm_class_dev, NULL);
+
+       class_device_destroy(umad_class, port->dev->dev);
+       class_device_destroy(umad_class, port->sm_dev->dev);
+
+       cdev_del(port->dev);
+       cdev_del(port->sm_dev);
+
+       spin_lock(&port_lock);
+       umad_port[port->dev_num] = NULL;
+       spin_unlock(&port_lock);
+
+       clear_bit(port->dev_num, dev_map);
+}
+
 static void ib_umad_add_one(struct ib_device *device)
 {
        struct ib_umad_device *umad_dev;
@@ -814,15 +841,12 @@ static void ib_umad_add_one(struct ib_device *device)
                e = device->phys_port_cnt;
        }
 
-       umad_dev = kmalloc(sizeof *umad_dev +
+       umad_dev = kzalloc(sizeof *umad_dev +
                           (e - s + 1) * sizeof (struct ib_umad_port),
                           GFP_KERNEL);
        if (!umad_dev)
                return;
 
-       memset(umad_dev, 0, sizeof *umad_dev +
-              (e - s + 1) * sizeof (struct ib_umad_port));
-
        kref_init(&umad_dev->ref);
 
        umad_dev->start_port = s;
@@ -840,10 +864,8 @@ static void ib_umad_add_one(struct ib_device *device)
        return;
 
 err:
-       while (--i >= s) {
-               class_device_unregister(&umad_dev->port[i - s].class_dev);
-               class_device_unregister(&umad_dev->port[i - s].sm_class_dev);
-       }
+       while (--i >= s)
+               ib_umad_kill_port(&umad_dev->port[i]);
 
        kref_put(&umad_dev->ref, ib_umad_release_dev);
 }
@@ -856,10 +878,8 @@ static void ib_umad_remove_one(struct ib_device *device)
        if (!umad_dev)
                return;
 
-       for (i = 0; i <= umad_dev->end_port - umad_dev->start_port; ++i) {
-               class_device_unregister(&umad_dev->port[i].class_dev);
-               class_device_unregister(&umad_dev->port[i].sm_class_dev);
-       }
+       for (i = 0; i <= umad_dev->end_port - umad_dev->start_port; ++i)
+               ib_umad_kill_port(&umad_dev->port[i]);
 
        kref_put(&umad_dev->ref, ib_umad_release_dev);
 }
@@ -868,8 +888,6 @@ static int __init ib_umad_init(void)
 {
        int ret;
 
-       spin_lock_init(&map_lock);
-
        ret = register_chrdev_region(base_dev, IB_UMAD_MAX_PORTS * 2,
                                     "infiniband_mad");
        if (ret) {
@@ -877,13 +895,14 @@ static int __init ib_umad_init(void)
                goto out;
        }
 
-       ret = class_register(&umad_class);
-       if (ret) {
+       umad_class = class_create(THIS_MODULE, "infiniband_mad");
+       if (IS_ERR(umad_class)) {
+               ret = PTR_ERR(umad_class);
                printk(KERN_ERR "user_mad: couldn't create class infiniband_mad\n");
                goto out_chrdev;
        }
 
-       ret = class_create_file(&umad_class, &class_attr_abi_version);
+       ret = class_create_file(umad_class, &class_attr_abi_version);
        if (ret) {
                printk(KERN_ERR "user_mad: couldn't create abi_version attribute\n");
                goto out_class;
@@ -898,7 +917,7 @@ static int __init ib_umad_init(void)
        return 0;
 
 out_class:
-       class_unregister(&umad_class);
+       class_destroy(umad_class);
 
 out_chrdev:
        unregister_chrdev_region(base_dev, IB_UMAD_MAX_PORTS * 2);
@@ -910,7 +929,7 @@ out:
 static void __exit ib_umad_cleanup(void)
 {
        ib_unregister_client(&umad_client);
-       class_unregister(&umad_class);
+       class_destroy(umad_class);
        unregister_chrdev_region(base_dev, IB_UMAD_MAX_PORTS * 2);
 }