Whamcloud - gitweb
LU-14289 libcfs: discard cfs_array_alloc() 92/41992/2
authorMr NeilBrown <neilb@suse.de>
Wed, 24 Feb 2021 23:57:19 +0000 (10:57 +1100)
committerOleg Drokin <green@whamcloud.com>
Tue, 30 Mar 2021 04:16:50 +0000 (04:16 +0000)
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 <neilb@suse.de>
Change-Id: I2a66be311dbba269b0b43c3a75f17ccc8e946538
Reviewed-on: https://review.whamcloud.com/41992
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Aurelien Degremont <degremoa@amazon.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/include/libcfs/libcfs_private.h
libcfs/libcfs/libcfs_mem.c
lnet/lnet/lib-ptl.c

index 9c48a13..57f47ac 100644 (file)
@@ -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
index 15542bb..486ecca 100644 (file)
@@ -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
index abdd6ae..fab9699 100644 (file)
@@ -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;
                }