Commit 69e9fbb4 authored by Roland Dreier's avatar Roland Dreier

IB/mthca: Clean up mthca array index mask

Define a constant MTHCA_ARRAY_MASK to replace repeated uses of
(PAGE_SIZE / sizeof (void *) - 1) in mthca array code.
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent bf74c747
...@@ -108,14 +108,15 @@ void mthca_alloc_cleanup(struct mthca_alloc *alloc) ...@@ -108,14 +108,15 @@ void mthca_alloc_cleanup(struct mthca_alloc *alloc)
* serialize access to the array. * serialize access to the array.
*/ */
#define MTHCA_ARRAY_MASK (PAGE_SIZE / sizeof (void *) - 1)
void *mthca_array_get(struct mthca_array *array, int index) void *mthca_array_get(struct mthca_array *array, int index)
{ {
int p = (index * sizeof (void *)) >> PAGE_SHIFT; int p = (index * sizeof (void *)) >> PAGE_SHIFT;
if (array->page_list[p].page) { if (array->page_list[p].page)
int i = index & (PAGE_SIZE / sizeof (void *) - 1); return array->page_list[p].page[index & MTHCA_ARRAY_MASK];
return array->page_list[p].page[i]; else
} else
return NULL; return NULL;
} }
...@@ -130,8 +131,7 @@ int mthca_array_set(struct mthca_array *array, int index, void *value) ...@@ -130,8 +131,7 @@ int mthca_array_set(struct mthca_array *array, int index, void *value)
if (!array->page_list[p].page) if (!array->page_list[p].page)
return -ENOMEM; return -ENOMEM;
array->page_list[p].page[index & (PAGE_SIZE / sizeof (void *) - 1)] = array->page_list[p].page[index & MTHCA_ARRAY_MASK] = value;
value;
++array->page_list[p].used; ++array->page_list[p].used;
return 0; return 0;
...@@ -145,8 +145,7 @@ void mthca_array_clear(struct mthca_array *array, int index) ...@@ -145,8 +145,7 @@ void mthca_array_clear(struct mthca_array *array, int index)
free_page((unsigned long) array->page_list[p].page); free_page((unsigned long) array->page_list[p].page);
array->page_list[p].page = NULL; array->page_list[p].page = NULL;
} else } else
array->page_list[p].page[index & (PAGE_SIZE / array->page_list[p].page[index & MTHCA_ARRAY_MASK] = NULL;
sizeof (void *) - 1)] = NULL;
if (array->page_list[p].used < 0) if (array->page_list[p].used < 0)
pr_debug("Array %p index %d page %d with ref count %d < 0\n", pr_debug("Array %p index %d page %d with ref count %d < 0\n",
......
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