@@ -105,13 +105,6 @@
int libcfs_debug_clear_buffer(void);
int libcfs_debug_mark_buffer(const char *text);
-/*
- * allocate a variable array, returned value is an array of pointers.
- * Caller can specify length of array by count.
- */
-void *cfs_array_alloc(int count, unsigned int size);
-void cfs_array_free(void *vars);
-
#define LASSERT_ATOMIC_ENABLED (1)
#if LASSERT_ATOMIC_ENABLED
@@ -117,55 +117,3 @@ struct cfs_var_array {
return arr->va_count;
}
EXPORT_SYMBOL(cfs_percpt_number);
-
-/*
- * free variable array, see more detail in cfs_array_alloc
- */
-void
-cfs_array_free(void *vars)
-{
- struct cfs_var_array *arr;
- int i;
-
- arr = container_of(vars, struct cfs_var_array, va_ptrs[0]);
-
- for (i = 0; i < arr->va_count; i++) {
- if (!arr->va_ptrs[i])
- continue;
-
- kvfree(arr->va_ptrs[i]);
- }
- kvfree(arr);
-}
-EXPORT_SYMBOL(cfs_array_free);
-
-/*
- * allocate a variable array, returned value is an array of pointers.
- * Caller can specify length of array by @count, @size is size of each
- * memory block in array.
- */
-void *
-cfs_array_alloc(int count, unsigned int size)
-{
- struct cfs_var_array *arr;
- int i;
-
- arr = kvmalloc(offsetof(struct cfs_var_array, va_ptrs[count]), GFP_KERNEL);
- if (!arr)
- return NULL;
-
- arr->va_count = count;
- arr->va_size = size;
-
- for (i = 0; i < count; i++) {
- arr->va_ptrs[i] = kvzalloc(size, GFP_KERNEL);
-
- if (!arr->va_ptrs[i]) {
- cfs_array_free((void *)&arr->va_ptrs[0]);
- return NULL;
- }
- }
-
- return (void *)&arr->va_ptrs[0];
-}
-EXPORT_SYMBOL(cfs_array_alloc);
@@ -830,6 +830,7 @@ struct list_head *
return -ENOMEM;
}
+#define PORTAL_SIZE (offsetof(struct lnet_portal, ptl_mt_maps[LNET_CPT_NUMBER]))
void
lnet_portals_destroy(void)
{
@@ -839,9 +840,12 @@ struct list_head *
return;
for (i = 0; i < the_lnet.ln_nportals; i++)
- lnet_ptl_cleanup(the_lnet.ln_portals[i]);
+ if (the_lnet.ln_portals[i]) {
+ lnet_ptl_cleanup(the_lnet.ln_portals[i]);
+ kfree(the_lnet.ln_portals[i]);
+ }
- cfs_array_free(the_lnet.ln_portals);
+ kvfree(the_lnet.ln_portals);
the_lnet.ln_portals = NULL;
the_lnet.ln_nportals = 0;
}
@@ -849,12 +853,11 @@ struct list_head *
int
lnet_portals_create(void)
{
- int size;
int i;
- size = offsetof(struct lnet_portal, ptl_mt_maps[LNET_CPT_NUMBER]);
-
- the_lnet.ln_portals = cfs_array_alloc(MAX_PORTALS, size);
+ the_lnet.ln_portals = kvmalloc_array(MAX_PORTALS,
+ sizeof(*the_lnet.ln_portals),
+ GFP_KERNEL);
if (!the_lnet.ln_portals) {
CERROR("Failed to allocate portals table\n");
return -ENOMEM;
@@ -862,7 +865,9 @@ struct list_head *
the_lnet.ln_nportals = MAX_PORTALS;
for (i = 0; i < the_lnet.ln_nportals; i++) {
- if (lnet_ptl_setup(the_lnet.ln_portals[i], i)) {
+ the_lnet.ln_portals[i] = kzalloc(PORTAL_SIZE, GFP_KERNEL);
+ if (!the_lnet.ln_portals[i] ||
+ lnet_ptl_setup(the_lnet.ln_portals[i], i)) {
lnet_portals_destroy();
return -ENOMEM;
}