Pull bugzilla-7897 into release branch
[sfrench/cifs-2.6.git] / drivers / infiniband / core / device.c
index 5a6e44976405bd06a37ffa0204668ce33cbafaf8..7fabb425b033a2de2243d50b24164937c0e99e49 100644 (file)
 #include <linux/module.h>
 #include <linux/string.h>
 #include <linux/errno.h>
+#include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/init.h>
-
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 
 #include "core_priv.h"
 
@@ -57,13 +57,13 @@ static LIST_HEAD(device_list);
 static LIST_HEAD(client_list);
 
 /*
- * device_sem protects access to both device_list and client_list.
+ * device_mutex protects access to both device_list and client_list.
  * There's no real point to using multiple locks or something fancier
  * like an rwsem: we always access both lists, and we're always
  * modifying one list or the other list.  In any case this is not a
  * hot path so there's no point in trying to optimize.
  */
-static DECLARE_MUTEX(device_sem);
+static DEFINE_MUTEX(device_mutex);
 
 static int ib_device_check_mandatory(struct ib_device *device)
 {
@@ -94,7 +94,7 @@ static int ib_device_check_mandatory(struct ib_device *device)
        };
        int i;
 
-       for (i = 0; i < sizeof mandatory_table / sizeof mandatory_table[0]; ++i) {
+       for (i = 0; i < ARRAY_SIZE(mandatory_table); ++i) {
                if (!*(void **) ((void *) device + mandatory_table[i].offset)) {
                        printk(KERN_WARNING "Device %s is missing mandatory function %s\n",
                               device->name, mandatory_table[i].name);
@@ -161,17 +161,9 @@ static int alloc_name(char *name)
  */
 struct ib_device *ib_alloc_device(size_t size)
 {
-       void *dev;
-
        BUG_ON(size < sizeof (struct ib_device));
 
-       dev = kmalloc(size, GFP_KERNEL);
-       if (!dev)
-               return NULL;
-
-       memset(dev, 0, size);
-
-       return dev;
+       return kzalloc(size, GFP_KERNEL);
 }
 EXPORT_SYMBOL(ib_alloc_device);
 
@@ -229,7 +221,7 @@ int ib_register_device(struct ib_device *device)
 {
        int ret;
 
-       down(&device_sem);
+       mutex_lock(&device_mutex);
 
        if (strchr(device->name, '%')) {
                ret = alloc_name(device->name);
@@ -267,7 +259,7 @@ int ib_register_device(struct ib_device *device)
        }
 
  out:
-       up(&device_sem);
+       mutex_unlock(&device_mutex);
        return ret;
 }
 EXPORT_SYMBOL(ib_register_device);
@@ -284,7 +276,7 @@ void ib_unregister_device(struct ib_device *device)
        struct ib_client_data *context, *tmp;
        unsigned long flags;
 
-       down(&device_sem);
+       mutex_lock(&device_mutex);
 
        list_for_each_entry_reverse(client, &client_list, list)
                if (client->remove)
@@ -292,7 +284,7 @@ void ib_unregister_device(struct ib_device *device)
 
        list_del(&device->core_list);
 
-       up(&device_sem);
+       mutex_unlock(&device_mutex);
 
        spin_lock_irqsave(&device->client_data_lock, flags);
        list_for_each_entry_safe(context, tmp, &device->client_data_list, list)
@@ -320,14 +312,14 @@ int ib_register_client(struct ib_client *client)
 {
        struct ib_device *device;
 
-       down(&device_sem);
+       mutex_lock(&device_mutex);
 
        list_add_tail(&client->list, &client_list);
        list_for_each_entry(device, &device_list, core_list)
                if (client->add && !add_client_context(device, client))
                        client->add(device);
 
-       up(&device_sem);
+       mutex_unlock(&device_mutex);
 
        return 0;
 }
@@ -347,7 +339,7 @@ void ib_unregister_client(struct ib_client *client)
        struct ib_device *device;
        unsigned long flags;
 
-       down(&device_sem);
+       mutex_lock(&device_mutex);
 
        list_for_each_entry(device, &device_list, core_list) {
                if (client->remove)
@@ -363,7 +355,7 @@ void ib_unregister_client(struct ib_client *client)
        }
        list_del(&client->list);
 
-       up(&device_sem);
+       mutex_unlock(&device_mutex);
 }
 EXPORT_SYMBOL(ib_unregister_client);
 
@@ -394,7 +386,7 @@ void *ib_get_client_data(struct ib_device *device, struct ib_client *client)
 EXPORT_SYMBOL(ib_get_client_data);
 
 /**
- * ib_set_client_data - Get IB client context
+ * ib_set_client_data - Set IB client context
  * @device:Device to set context for
  * @client:Client to set context for
  * @data:Context to set
@@ -514,7 +506,7 @@ int ib_query_port(struct ib_device *device,
                  u8 port_num,
                  struct ib_port_attr *port_attr)
 {
-       if (device->node_type == IB_NODE_SWITCH) {
+       if (device->node_type == RDMA_NODE_IB_SWITCH) {
                if (port_num)
                        return -EINVAL;
        } else if (port_num < 1 || port_num > device->phys_port_cnt)
@@ -589,7 +581,7 @@ int ib_modify_port(struct ib_device *device,
                   u8 port_num, int port_modify_mask,
                   struct ib_port_modify *port_modify)
 {
-       if (device->node_type == IB_NODE_SWITCH) {
+       if (device->node_type == RDMA_NODE_IB_SWITCH) {
                if (port_num)
                        return -EINVAL;
        } else if (port_num < 1 || port_num > device->phys_port_cnt)