[openib-general] [PATCH] Have ib_set_client_data return void
Roland Dreier
roland at topspin.com
Mon Sep 13 20:26:59 PDT 2004
Allocate client context sooner so that ib_set_client_data() can return void.
Index: infiniband/ulp/ipoib/ipoib_main.c
===================================================================
--- infiniband/ulp/ipoib/ipoib_main.c (revision 812)
+++ infiniband/ulp/ipoib/ipoib_main.c (revision 813)
@@ -733,6 +733,7 @@
}
static struct ib_client ipoib_client = {
+ .name = "ipoib",
.add = ipoib_add_one,
.remove = ipoib_remove_one
};
Index: infiniband/include/ib_verbs.h
===================================================================
--- infiniband/include/ib_verbs.h (revision 812)
+++ infiniband/include/ib_verbs.h (revision 813)
@@ -777,6 +777,7 @@
};
struct ib_client {
+ char *name;
void (*add) (struct ib_device *);
void (*remove)(struct ib_device *);
@@ -793,7 +794,7 @@
void ib_unregister_client(struct ib_client *client);
void *ib_get_client_data(struct ib_device *device, struct ib_client *client);
-int ib_set_client_data(struct ib_device *device, struct ib_client *client,
+void ib_set_client_data(struct ib_device *device, struct ib_client *client,
void *data);
int ib_register_event_handler (struct ib_event_handler *event_handler);
Index: infiniband/core/ib_device.c
===================================================================
--- infiniband/core/ib_device.c (revision 812)
+++ infiniband/core/ib_device.c (revision 813)
@@ -161,6 +161,28 @@
}
EXPORT_SYMBOL(ib_dealloc_device);
+static int add_client_context(struct ib_device *device, struct ib_client *client)
+{
+ struct ib_client_data *context;
+ unsigned long flags;
+
+ context = kmalloc(sizeof *context, GFP_KERNEL);
+ if (!context) {
+ printk(KERN_WARNING "Couldn't allocate client context for %s/%s\n",
+ device->name, client->name);
+ return -ENOMEM;
+ }
+
+ context->client = client;
+ context->data = NULL;
+
+ spin_lock_irqsave(&device->client_data_lock, flags);
+ list_add(&context->list, &device->client_data_list);
+ spin_unlock_irqrestore(&device->client_data_lock, flags);
+
+ return 0;
+}
+
int ib_register_device(struct ib_device *device)
{
struct ib_device_private *priv;
@@ -234,17 +256,10 @@
goto out_free_port;
}
- ret = ib_proc_setup(device, device->node_type == IB_NODE_SWITCH);
- if (ret) {
- printk(KERN_WARNING "Couldn't create /proc dir for %s\n",
- device->name);
- goto out_free_cache;
- }
-
if (ib_device_register_sysfs(device)) {
printk(KERN_WARNING "Couldn't register device %s with driver model\n",
device->name);
- goto out_proc;
+ goto out_free_cache;
}
list_add_tail(&device->core_list, &device_list);
@@ -255,16 +270,13 @@
struct ib_client *client;
list_for_each_entry(client, &client_list, list)
- if (client->add)
+ if (client->add && !add_client_context(device, client))
client->add(device);
}
up(&device_sem);
return 0;
- out_proc:
- ib_proc_cleanup(device);
-
out_free_cache:
ib_cache_cleanup(device);
@@ -302,7 +314,6 @@
kfree(context);
spin_unlock_irqrestore(&device->client_data_lock, flags);
- ib_proc_cleanup(device);
ib_cache_cleanup(device);
kfree(priv->port_data);
@@ -355,7 +366,7 @@
list_add_tail(&client->list, &client_list);
list_for_each_entry(device, &device_list, core_list)
- if (client->add)
+ if (client->add && !add_client_context(device, client))
client->add(device);
up(&device_sem);
@@ -408,34 +419,23 @@
}
EXPORT_SYMBOL(ib_get_client_data);
-int ib_set_client_data(struct ib_device *device, struct ib_client *client,
- void *data)
+void ib_set_client_data(struct ib_device *device, struct ib_client *client,
+ void *data)
{
struct ib_client_data *context;
- int ret = 0;
unsigned long flags;
spin_lock_irqsave(&device->client_data_lock, flags);
list_for_each_entry(context, &device->client_data_list, list)
if (context->client == client) {
context->data = data;
- spin_unlock_irqrestore(&device->client_data_lock, flags);
- return 0;
+ break;
}
spin_unlock_irqrestore(&device->client_data_lock, flags);
- context = kmalloc(sizeof *context, GFP_KERNEL);
- if (!context)
- return -ENOMEM;
- context->client = client;
- context->data = data;
-
- spin_lock_irqsave(&device->client_data_lock, flags);
- list_add(&context->list, &device->client_data_list);
- spin_unlock_irqrestore(&device->client_data_lock, flags);
-
- return 0;
+ printk(KERN_WARNING "No client context found for %s/%s\n",
+ device->name, client->name);
}
EXPORT_SYMBOL(ib_set_client_data);
Index: infiniband/core/mad_main.c
===================================================================
--- infiniband/core/mad_main.c (revision 812)
+++ infiniband/core/mad_main.c (revision 813)
@@ -328,6 +328,7 @@
}
static struct ib_client mad_client = {
+ .name = "mad",
.add = ib_mad_add_one,
.remove = ib_mad_remove_one
};
More information about the general
mailing list