From 8ec9fe0d55b1f5a7854dabe240f43e6cd5cb22ad Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Thu, 25 Feb 2021 10:57:19 +1100 Subject: [PATCH] LU-14289 libcfs: discard cfs_array_alloc() cfs_array_alloc() and _free() are used for precisely one array, and provide little value beyond open-coding the alloc and free. So discard these functions and alloc/free in the loops that already exist for setup and cleanup. Test-Parameters: trivial Signed-off-by: Mr NeilBrown Change-Id: I2a66be311dbba269b0b43c3a75f17ccc8e946538 Reviewed-on: https://review.whamcloud.com/41992 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Aurelien Degremont Reviewed-by: James Simmons Reviewed-by: Chris Horn Reviewed-by: Oleg Drokin --- libcfs/include/libcfs/libcfs_private.h | 7 ----- libcfs/libcfs/libcfs_mem.c | 52 ---------------------------------- lnet/lnet/lib-ptl.c | 17 ++++++----- 3 files changed, 10 insertions(+), 66 deletions(-) diff --git a/libcfs/include/libcfs/libcfs_private.h b/libcfs/include/libcfs/libcfs_private.h index 9c48a13..57f47ac 100644 --- a/libcfs/include/libcfs/libcfs_private.h +++ b/libcfs/include/libcfs/libcfs_private.h @@ -242,13 +242,6 @@ int libcfs_debug_cleanup(void); 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 diff --git a/libcfs/libcfs/libcfs_mem.c b/libcfs/libcfs/libcfs_mem.c index 15542bb..486ecca 100644 --- a/libcfs/libcfs/libcfs_mem.c +++ b/libcfs/libcfs/libcfs_mem.c @@ -120,58 +120,6 @@ cfs_percpt_number(void *vars) } 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] == NULL) - continue; - - LIBCFS_FREE(arr->va_ptrs[i], arr->va_size); - } - LIBCFS_FREE(arr, offsetof(struct cfs_var_array, - va_ptrs[arr->va_count])); -} -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; - - LIBCFS_ALLOC(arr, offsetof(struct cfs_var_array, va_ptrs[count])); - if (arr == NULL) - return NULL; - - arr->va_count = count; - arr->va_size = size; - - for (i = 0; i < count; i++) { - LIBCFS_ALLOC(arr->va_ptrs[i], size); - - if (arr->va_ptrs[i] == NULL) { - cfs_array_free((void *)&arr->va_ptrs[0]); - return NULL; - } - } - - return (void *)&arr->va_ptrs[0]; -} -EXPORT_SYMBOL(cfs_array_alloc); /* * This is opencoding of vfree_atomic from Linux kernel added in 4.10 with diff --git a/lnet/lnet/lib-ptl.c b/lnet/lnet/lib-ptl.c index abdd6ae..fab9699 100644 --- a/lnet/lnet/lib-ptl.c +++ b/lnet/lnet/lib-ptl.c @@ -828,6 +828,7 @@ lnet_ptl_setup(struct lnet_portal *ptl, int index) return -ENOMEM; } +#define PORTAL_SIZE (offsetof(struct lnet_portal, ptl_mt_maps[LNET_CPT_NUMBER])) void lnet_portals_destroy(void) { @@ -837,29 +838,31 @@ lnet_portals_destroy(void) 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]); + LIBCFS_FREE(the_lnet.ln_portals[i], PORTAL_SIZE); + } - cfs_array_free(the_lnet.ln_portals); + CFS_FREE_PTR_ARRAY(the_lnet.ln_portals, the_lnet.ln_nportals); the_lnet.ln_portals = NULL; } int lnet_portals_create(void) { - int size; int i; - size = offsetof(struct lnet_portal, ptl_mt_maps[LNET_CPT_NUMBER]); - the_lnet.ln_nportals = MAX_PORTALS; - the_lnet.ln_portals = cfs_array_alloc(the_lnet.ln_nportals, size); + CFS_ALLOC_PTR_ARRAY(the_lnet.ln_portals, the_lnet.ln_nportals); if (the_lnet.ln_portals == NULL) { CERROR("Failed to allocate portals table\n"); return -ENOMEM; } for (i = 0; i < the_lnet.ln_nportals; i++) { - if (lnet_ptl_setup(the_lnet.ln_portals[i], i)) { + LIBCFS_ALLOC(the_lnet.ln_portals[i], PORTAL_SIZE); + if (!the_lnet.ln_portals[i] || + lnet_ptl_setup(the_lnet.ln_portals[i], i)) { lnet_portals_destroy(); return -ENOMEM; } -- 1.8.3.1