[openib-general] [PATCH] SDP: use linux/list.h for hca port list
Tom Duffy
tduffy at sun.com
Thu Jul 14 15:30:12 PDT 2005
This patch changes the NULL terminated port list in the sdp hca object
to a Linux list_head. It also removes the sdev_hca *next member from
the sdev_hca struct as this is never used, AFAICT.
Signed-off-by: Tom Duffy <tduffy at sun.com>
Index: drivers/infiniband/ulp/sdp/sdp_conn.c
===================================================================
--- drivers/infiniband/ulp/sdp/sdp_conn.c (revision 2861)
+++ drivers/infiniband/ulp/sdp/sdp_conn.c (working copy)
@@ -994,10 +974,10 @@ int sdp_conn_alloc_ib(struct sdp_sock *c
{
struct ib_qp_init_attr *init_attr;
struct ib_qp_attr *qp_attr;
- struct sdev_hca_port *port = NULL;
- struct sdev_hca *hca = NULL;
+ struct sdev_hca_port *port;
+ struct sdev_hca *hca;
int attr_mask = 0;
- int result;
+ int result = 0;
/*
* look up correct HCA and port
@@ -1006,11 +986,13 @@ int sdp_conn_alloc_ib(struct sdp_sock *c
if (!hca)
return -ERANGE;
- for (port = hca->port_list; port; port = port->next)
- if (hw_port == port->index)
+ list_for_each_entry(port, &hca->port_list, list)
+ if (hw_port == port->index) {
+ result = 1;
break;
+ }
- if (!port)
+ if (!result)
return -ERANGE;
/*
* allocate creation parameters
@@ -1740,14 +1722,14 @@ int sdp_proc_dump_device(char *buffer, i
static void sdp_device_init_one(struct ib_device *device)
{
struct ib_fmr_pool_param fmr_param_s;
- struct sdev_hca_port *port;
+ struct sdev_hca_port *port, *tmp;
struct sdev_hca *hca;
int result;
int port_count;
/*
* allocate per-HCA structure
*/
- hca = kmalloc(sizeof(struct sdev_hca), GFP_KERNEL);
+ hca = kmalloc(sizeof *hca, GFP_KERNEL);
if (!hca) {
sdp_warn("Error allocating HCA <%s> memory.", device->name);
return;
@@ -1755,12 +1737,10 @@ static void sdp_device_init_one(struct i
/*
* init and insert into list.
*/
- memset(hca, 0, sizeof(struct sdev_hca));
+ memset(hca, 0, sizeof *hca);
- hca->fmr_pool = NULL;
- hca->mem_h = NULL;
- hca->pd = NULL;
- hca->ca = device;
+ hca->ca = device;
+ INIT_LIST_HEAD(&hca->port_list);
/*
* protection domain
*/
@@ -1798,17 +1778,15 @@ static void sdp_device_init_one(struct i
* create SDP memory pool
*/
hca->fmr_pool = ib_create_fmr_pool(hca->pd, &fmr_param_s);
- if (IS_ERR(hca->fmr_pool)) {
- sdp_warn("Warning, could not creating HCA <%s> FMR pool <%ld>",
+ if (IS_ERR(hca->fmr_pool))
+ sdp_warn("Warning, could not create HCA <%s> FMR pool <%ld>",
device->name, PTR_ERR(hca->fmr_pool));
- }
+
/*
* port allocation
*/
- for (port_count = 0;
- port_count < device->phys_port_cnt;
- port_count++) {
- port = kmalloc(sizeof(struct sdev_hca_port), GFP_KERNEL);
+ for (port_count = 0; port_count < device->phys_port_cnt; port_count++) {
+ port = kmalloc(sizeof *port, GFP_KERNEL);
if (!port) {
sdp_warn("Error allocating HCA <%s> port <%d:%d>",
device->name, port_count,
@@ -1817,11 +1795,10 @@ static void sdp_device_init_one(struct i
goto error;
}
- memset(port, 0, sizeof(struct sdev_hca_port));
+ memset(port, 0, sizeof *port);
- port->index = port_count + 1;
- port->next = hca->port_list;
- hca->port_list = port;
+ port->index = port_count + 1;
+ list_add(&port->list, &hca->port_list);
result = ib_query_gid(hca->ca,
port->index,
@@ -1840,11 +1817,8 @@ static void sdp_device_init_one(struct i
return;
error:
- while (hca->port_list) {
- port = hca->port_list;
- hca->port_list = port->next;
- port->next = NULL;
-
+ list_for_each_entry_safe(port, tmp, &hca->port_list, list) {
+ list_del(&port->list);
kfree(port);
}
@@ -1865,7 +1839,7 @@ error:
*/
static void sdp_device_remove_one(struct ib_device *device)
{
- struct sdev_hca_port *port;
+ struct sdev_hca_port *port, *tmp;
struct sdev_hca *hca;
hca = ib_get_client_data(device, &sdp_client);
@@ -1875,11 +1849,8 @@ static void sdp_device_remove_one(struct
return;
}
- while (hca->port_list) {
- port = hca->port_list;
- hca->port_list = port->next;
- port->next = NULL;
-
+ list_for_each_entry_safe(port, tmp, &hca->port_list, list) {
+ list_del(&port->list);
kfree(port);
}
Index: drivers/infiniband/ulp/sdp/sdp_dev.h
===================================================================
--- drivers/infiniband/ulp/sdp/sdp_dev.h (revision 2861)
+++ drivers/infiniband/ulp/sdp/sdp_dev.h (working copy)
@@ -150,7 +150,7 @@
struct sdev_hca_port {
u8 index; /* port ID */
union ib_gid gid; /* port GID */
- struct sdev_hca_port *next; /* next port in the list */
+ struct list_head list;
};
struct sdev_hca {
@@ -160,8 +160,7 @@ struct sdev_hca {
u32 l_key; /* local key */
u32 r_key; /* remote key */
struct ib_fmr_pool *fmr_pool; /* fast memory for Zcopy */
- struct sdev_hca_port *port_list; /* ports on this HCA */
- struct sdev_hca *next; /* next HCA in the list */
+ struct list_head port_list; /* ports on this HCA */
};
struct sdev_root {
More information about the general
mailing list