Whamcloud - gitweb
LU-9679 ptlrpc: use OBD_ALLOC_PTR_ARRAY() and FREE 53/38253/2
authorMr NeilBrown <neilb@suse.de>
Thu, 14 Nov 2019 03:20:01 +0000 (14:20 +1100)
committerOleg Drokin <green@whamcloud.com>
Wed, 27 May 2020 05:03:38 +0000 (05:03 +0000)
Use:
  OBD_ALLOC_PTR_ARRAY
  OBD_FREE_PTR_ARRAY

for allocating and freeing arrays in ptlrpc.

Test-Parameters: trivial
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Ic0323ce4d50d5ced3ac6e529f7477cc4779478e6
Reviewed-on: https://review.whamcloud.com/38253
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
lustre/ptlrpc/lproc_ptlrpc.c
lustre/ptlrpc/nodemap_storage.c
lustre/ptlrpc/ptlrpcd.c
lustre/ptlrpc/sec_bulk.c
lustre/ptlrpc/sec_config.c
lustre/ptlrpc/service.c

index ce7d386..ee5e8c3 100644 (file)
@@ -559,7 +559,7 @@ static int ptlrpc_lprocfs_nrs_seq_show(struct seq_file *m, void *n)
        num_pols = svc->srv_parts[0]->scp_nrs_reg.nrs_num_pols;
        spin_unlock(&nrs->nrs_lock);
 
        num_pols = svc->srv_parts[0]->scp_nrs_reg.nrs_num_pols;
        spin_unlock(&nrs->nrs_lock);
 
-       OBD_ALLOC(infos, num_pols * sizeof(*infos));
+       OBD_ALLOC_PTR_ARRAY(infos, num_pols);
        if (infos == NULL)
                GOTO(out, rc = -ENOMEM);
 again:
        if (infos == NULL)
                GOTO(out, rc = -ENOMEM);
 again:
@@ -681,7 +681,7 @@ again:
 
 out:
        if (infos)
 
 out:
        if (infos)
-               OBD_FREE(infos, num_pols * sizeof(*infos));
+               OBD_FREE_PTR_ARRAY(infos, num_pols);
 
        mutex_unlock(&nrs_core.nrs_mutex);
 
 
        mutex_unlock(&nrs_core.nrs_mutex);
 
index 6790ee8..e22ea72 100644 (file)
@@ -1488,7 +1488,7 @@ int nodemap_get_config_req(struct obd_device *mgs_obd,
               body->mcb_name, rdpg.rp_count);
 
        /* allocate pages to store the containers */
               body->mcb_name, rdpg.rp_count);
 
        /* allocate pages to store the containers */
-       OBD_ALLOC(rdpg.rp_pages, sizeof(*rdpg.rp_pages) * rdpg.rp_npages);
+       OBD_ALLOC_PTR_ARRAY(rdpg.rp_pages, rdpg.rp_npages);
        if (rdpg.rp_pages == NULL)
                RETURN(-ENOMEM);
        for (i = 0; i < rdpg.rp_npages; i++) {
        if (rdpg.rp_pages == NULL)
                RETURN(-ENOMEM);
        for (i = 0; i < rdpg.rp_npages; i++) {
@@ -1539,8 +1539,7 @@ out:
                for (i = 0; i < rdpg.rp_npages; i++)
                        if (rdpg.rp_pages[i] != NULL)
                                __free_page(rdpg.rp_pages[i]);
                for (i = 0; i < rdpg.rp_npages; i++)
                        if (rdpg.rp_pages[i] != NULL)
                                __free_page(rdpg.rp_pages[i]);
-               OBD_FREE(rdpg.rp_pages,
-                        rdpg.rp_npages * sizeof(rdpg.rp_pages[0]));
+               OBD_FREE_PTR_ARRAY(rdpg.rp_pages, rdpg.rp_npages);
        }
        return rc;
 }
        }
        return rc;
 }
index 6e6045b..b3a06a5 100644 (file)
@@ -693,8 +693,7 @@ out:
        if (pc->pc_npartners > 0) {
                LASSERT(pc->pc_partners != NULL);
 
        if (pc->pc_npartners > 0) {
                LASSERT(pc->pc_partners != NULL);
 
-               OBD_FREE(pc->pc_partners,
-                        sizeof(struct ptlrpcd_ctl *) * pc->pc_npartners);
+               OBD_FREE_PTR_ARRAY(pc->pc_partners, pc->pc_npartners);
                pc->pc_partners = NULL;
        }
        pc->pc_npartners = 0;
                pc->pc_partners = NULL;
        }
        pc->pc_npartners = 0;
@@ -721,7 +720,7 @@ static void ptlrpcd_fini(void)
                        OBD_FREE(ptlrpcds[i], ptlrpcds[i]->pd_size);
                        ptlrpcds[i] = NULL;
                }
                        OBD_FREE(ptlrpcds[i], ptlrpcds[i]->pd_size);
                        ptlrpcds[i] = NULL;
                }
-               OBD_FREE(ptlrpcds, sizeof(ptlrpcds[0]) * ptlrpcds_num);
+               OBD_FREE_PTR_ARRAY(ptlrpcds, ptlrpcds_num);
        }
        ptlrpcds_num = 0;
 
        }
        ptlrpcds_num = 0;
 
@@ -730,7 +729,7 @@ static void ptlrpcd_fini(void)
 
        if (ptlrpcds_cpt_idx != NULL) {
                ncpts = cfs_cpt_number(cfs_cpt_tab);
 
        if (ptlrpcds_cpt_idx != NULL) {
                ncpts = cfs_cpt_number(cfs_cpt_tab);
-               OBD_FREE(ptlrpcds_cpt_idx, ncpts * sizeof(ptlrpcds_cpt_idx[0]));
+               OBD_FREE_PTR_ARRAY(ptlrpcds_cpt_idx, ncpts);
                ptlrpcds_cpt_idx = NULL;
        }
 
                ptlrpcds_cpt_idx = NULL;
        }
 
index 66032b1..870f76a 100644 (file)
@@ -432,7 +432,7 @@ static int enc_pools_add_pages(int npages)
        page_pools.epp_st_grows++;
 
        npools = npages_to_npools(npages);
        page_pools.epp_st_grows++;
 
        npools = npages_to_npools(npages);
-       OBD_ALLOC(pools, npools * sizeof(*pools));
+       OBD_ALLOC_PTR_ARRAY(pools, npools);
        if (pools == NULL)
                goto out;
 
        if (pools == NULL)
                goto out;
 
@@ -458,7 +458,7 @@ static int enc_pools_add_pages(int npages)
 
 out_pools:
        enc_pools_cleanup(pools, npools);
 
 out_pools:
        enc_pools_cleanup(pools, npools);
-       OBD_FREE(pools, npools * sizeof(*pools));
+       OBD_FREE_PTR_ARRAY(pools, npools);
 out:
        if (rc) {
                page_pools.epp_st_grow_fails++;
 out:
        if (rc) {
                page_pools.epp_st_grow_fails++;
index 920a1d2..630994a 100644 (file)
@@ -237,14 +237,13 @@ EXPORT_SYMBOL(sptlrpc_parse_rule);
 
 void sptlrpc_rule_set_free(struct sptlrpc_rule_set *rset)
 {
 
 void sptlrpc_rule_set_free(struct sptlrpc_rule_set *rset)
 {
-        LASSERT(rset->srs_nslot ||
-                (rset->srs_nrule == 0 && rset->srs_rules == NULL));
+       LASSERT(rset->srs_nslot ||
+               (rset->srs_nrule == 0 && rset->srs_rules == NULL));
 
 
-        if (rset->srs_nslot) {
-                OBD_FREE(rset->srs_rules,
-                         rset->srs_nslot * sizeof(*rset->srs_rules));
-                sptlrpc_rule_set_init(rset);
-        }
+       if (rset->srs_nslot) {
+               OBD_FREE_PTR_ARRAY(rset->srs_rules, rset->srs_nslot);
+               sptlrpc_rule_set_init(rset);
+       }
 }
 EXPORT_SYMBOL(sptlrpc_rule_set_free);
 
 }
 EXPORT_SYMBOL(sptlrpc_rule_set_free);
 
@@ -263,19 +262,18 @@ int sptlrpc_rule_set_expand(struct sptlrpc_rule_set *rset)
 
        nslot = rset->srs_nslot + 8;
 
 
        nslot = rset->srs_nslot + 8;
 
-        /* better use realloc() if available */
-        OBD_ALLOC(rules, nslot * sizeof(*rset->srs_rules));
-        if (rules == NULL)
-                return -ENOMEM;
+       /* better use realloc() if available */
+       OBD_ALLOC_PTR_ARRAY(rules, nslot);
+       if (rules == NULL)
+               return -ENOMEM;
 
 
-        if (rset->srs_nrule) {
-                LASSERT(rset->srs_nslot && rset->srs_rules);
-                memcpy(rules, rset->srs_rules,
-                       rset->srs_nrule * sizeof(*rset->srs_rules));
+       if (rset->srs_nrule) {
+               LASSERT(rset->srs_nslot && rset->srs_rules);
+               memcpy(rules, rset->srs_rules,
+                      rset->srs_nrule * sizeof(*rset->srs_rules));
 
 
-                OBD_FREE(rset->srs_rules,
-                         rset->srs_nslot * sizeof(*rset->srs_rules));
-        }
+               OBD_FREE_PTR_ARRAY(rset->srs_rules, rset->srs_nslot);
+       }
 
         rset->srs_rules = rules;
         rset->srs_nslot = nslot;
 
         rset->srs_rules = rules;
         rset->srs_nslot = nslot;
index 1bd8fae..f5d11fd 100644 (file)
@@ -684,13 +684,12 @@ static int ptlrpc_service_part_init(struct ptlrpc_service *svc,
 
  failed:
        if (array->paa_reqs_count != NULL) {
 
  failed:
        if (array->paa_reqs_count != NULL) {
-               OBD_FREE(array->paa_reqs_count, sizeof(__u32) * size);
+               OBD_FREE_PTR_ARRAY(array->paa_reqs_count, size);
                array->paa_reqs_count = NULL;
        }
 
        if (array->paa_reqs_array != NULL) {
                array->paa_reqs_count = NULL;
        }
 
        if (array->paa_reqs_array != NULL) {
-               OBD_FREE(array->paa_reqs_array,
-                        sizeof(struct list_head) * array->paa_size);
+               OBD_FREE_PTR_ARRAY(array->paa_reqs_array, array->paa_size);
                array->paa_reqs_array = NULL;
        }
 
                array->paa_reqs_array = NULL;
        }
 
@@ -755,7 +754,7 @@ struct ptlrpc_service *ptlrpc_register_service(struct ptlrpc_service_conf *conf,
                                CERROR("%s: failed to parse CPT array %s: %d\n",
                                       conf->psc_name, cconf->cc_pattern, rc);
                                if (cpts != NULL)
                                CERROR("%s: failed to parse CPT array %s: %d\n",
                                       conf->psc_name, cconf->cc_pattern, rc);
                                if (cpts != NULL)
-                                       OBD_FREE(cpts, sizeof(*cpts) * ncpts);
+                                       OBD_FREE_PTR_ARRAY(cpts, ncpts);
                                RETURN(ERR_PTR(rc < 0 ? rc : -EINVAL));
                        }
                        ncpts = rc;
                                RETURN(ERR_PTR(rc < 0 ? rc : -EINVAL));
                        }
                        ncpts = rc;
@@ -765,7 +764,7 @@ struct ptlrpc_service *ptlrpc_register_service(struct ptlrpc_service_conf *conf,
        OBD_ALLOC(service, offsetof(struct ptlrpc_service, srv_parts[ncpts]));
        if (service == NULL) {
                if (cpts != NULL)
        OBD_ALLOC(service, offsetof(struct ptlrpc_service, srv_parts[ncpts]));
        if (service == NULL) {
                if (cpts != NULL)
-                       OBD_FREE(cpts, sizeof(*cpts) * ncpts);
+                       OBD_FREE_PTR_ARRAY(cpts, ncpts);
                RETURN(ERR_PTR(-ENOMEM));
        }
 
                RETURN(ERR_PTR(-ENOMEM));
        }
 
@@ -3348,10 +3347,8 @@ void ptlrpc_hr_fini(void)
        ptlrpc_stop_hr_threads();
 
        cfs_percpt_for_each(hrp, cpt, ptlrpc_hr.hr_partitions) {
        ptlrpc_stop_hr_threads();
 
        cfs_percpt_for_each(hrp, cpt, ptlrpc_hr.hr_partitions) {
-               if (hrp->hrp_thrs != NULL) {
-                       OBD_FREE(hrp->hrp_thrs,
-                                hrp->hrp_nthrs * sizeof(hrp->hrp_thrs[0]));
-               }
+               if (hrp->hrp_thrs)
+                       OBD_FREE_PTR_ARRAY(hrp->hrp_thrs, hrp->hrp_nthrs);
        }
 
        cfs_percpt_free(ptlrpc_hr.hr_partitions);
        }
 
        cfs_percpt_free(ptlrpc_hr.hr_partitions);
@@ -3544,14 +3541,14 @@ ptlrpc_service_free(struct ptlrpc_service *svc)
                array = &svcpt->scp_at_array;
 
                if (array->paa_reqs_array != NULL) {
                array = &svcpt->scp_at_array;
 
                if (array->paa_reqs_array != NULL) {
-                       OBD_FREE(array->paa_reqs_array,
-                                sizeof(struct list_head) * array->paa_size);
+                       OBD_FREE_PTR_ARRAY(array->paa_reqs_array,
+                                          array->paa_size);
                        array->paa_reqs_array = NULL;
                }
 
                if (array->paa_reqs_count != NULL) {
                        array->paa_reqs_array = NULL;
                }
 
                if (array->paa_reqs_count != NULL) {
-                       OBD_FREE(array->paa_reqs_count,
-                                sizeof(__u32) * array->paa_size);
+                       OBD_FREE_PTR_ARRAY(array->paa_reqs_count,
+                                          array->paa_size);
                        array->paa_reqs_count = NULL;
                }
        }
                        array->paa_reqs_count = NULL;
                }
        }