Whamcloud - gitweb
LU-9679 lodlov: use OBD_ALLOC_PTR_ARRAY() and others 54/38254/2
authorMr NeilBrown <neilb@suse.de>
Thu, 14 Nov 2019 03:20:01 +0000 (14:20 +1100)
committerOleg Drokin <green@whamcloud.com>
Wed, 20 May 2020 08:22:56 +0000 (08:22 +0000)
Use:
  OBD_ALLOC_PTR_ARRAY
  OBD_FREE_PTR_ARRAY
  OBD_ALLOC_PTR_ARRAY_LARGE
  OBD_FREE_PTR_ARRAY_LARGE

for allocating and freeing arrays in lod and lov.

Test-Parameters: trivial
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Ia782fc903761e21be982e4553ec40035c57f73f3
Reviewed-on: https://review.whamcloud.com/38254
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/lod/lod_dev.c
lustre/lod/lod_lov.c
lustre/lod/lod_object.c
lustre/lod/lod_qos.c
lustre/lov/lov_dev.c
lustre/lov/lov_obd.c
lustre/lov/lov_object.c

index 5091b7a..d6406c9 100644 (file)
@@ -1887,8 +1887,8 @@ static struct lu_device *lod_device_alloc(const struct lu_env *env,
 static void lod_avoid_guide_fini(struct lod_avoid_guide *lag)
 {
        if (lag->lag_oss_avoid_array)
-               OBD_FREE(lag->lag_oss_avoid_array,
-                        sizeof(u32) * lag->lag_oaa_size);
+               OBD_FREE_PTR_ARRAY(lag->lag_oss_avoid_array,
+                                  lag->lag_oaa_size);
        if (lag->lag_ost_avoid_bitmap)
                CFS_FREE_BITMAP(lag->lag_ost_avoid_bitmap);
 }
@@ -2037,8 +2037,8 @@ static void lod_key_fini(const struct lu_context *ctx,
                lod_free_def_comp_entries(&info->lti_def_striping);
 
        if (info->lti_comp_size > 0)
-               OBD_FREE(info->lti_comp_idx,
-                        info->lti_comp_size * sizeof(u32));
+               OBD_FREE_PTR_ARRAY(info->lti_comp_idx,
+                                  info->lti_comp_size);
 
        lod_avoid_guide_fini(&info->lti_avoid);
 
index d0a711e..a023959 100644 (file)
@@ -549,8 +549,7 @@ int lod_def_striping_comp_resize(struct lod_default_striping *lds, __u16 count)
 void lod_free_comp_entries(struct lod_object *lo)
 {
        if (lo->ldo_mirrors) {
-               OBD_FREE(lo->ldo_mirrors,
-                        sizeof(*lo->ldo_mirrors) * lo->ldo_mirror_count);
+               OBD_FREE_PTR_ARRAY(lo->ldo_mirrors, lo->ldo_mirror_count);
                lo->ldo_mirrors = NULL;
                lo->ldo_mirror_count = 0;
        }
@@ -569,8 +568,7 @@ int lod_alloc_comp_entries(struct lod_object *lo,
        LASSERT(lo->ldo_comp_cnt == 0 && lo->ldo_comp_entries == NULL);
 
        if (mirror_count > 0) {
-               OBD_ALLOC(lo->ldo_mirrors,
-                         sizeof(*lo->ldo_mirrors) * mirror_count);
+               OBD_ALLOC_PTR_ARRAY(lo->ldo_mirrors, mirror_count);
                if (!lo->ldo_mirrors)
                        return -ENOMEM;
 
@@ -580,8 +578,7 @@ int lod_alloc_comp_entries(struct lod_object *lo,
        OBD_ALLOC_LARGE(lo->ldo_comp_entries,
                        sizeof(*lo->ldo_comp_entries) * comp_count);
        if (lo->ldo_comp_entries == NULL) {
-               OBD_FREE(lo->ldo_mirrors,
-                        sizeof(*lo->ldo_mirrors) * mirror_count);
+               OBD_FREE_PTR_ARRAY(lo->ldo_mirrors, mirror_count);
                lo->ldo_mirror_count = 0;
                return -ENOMEM;
        }
@@ -1028,10 +1025,10 @@ int lod_initialize_objects(const struct lu_env *env, struct lod_object *lo,
        LASSERT(lod_comp->llc_stripe_size > 0);
 
        stripe_len = lod_comp->llc_stripe_count;
-       OBD_ALLOC(stripe, sizeof(stripe[0]) * stripe_len);
+       OBD_ALLOC_PTR_ARRAY(stripe, stripe_len);
        if (stripe == NULL)
                RETURN(-ENOMEM);
-       OBD_ALLOC(ost_indices, sizeof(*ost_indices) * stripe_len);
+       OBD_ALLOC_PTR_ARRAY(ost_indices, stripe_len);
        if (!ost_indices)
                GOTO(out, rc = -ENOMEM);
 
@@ -1077,11 +1074,10 @@ out:
                        if (stripe[i] != NULL)
                                dt_object_put(env, stripe[i]);
 
-               OBD_FREE(stripe, sizeof(stripe[0]) * stripe_len);
+               OBD_FREE_PTR_ARRAY(stripe, stripe_len);
                lod_comp->llc_stripe_count = 0;
                if (ost_indices)
-                       OBD_FREE(ost_indices,
-                                sizeof(*ost_indices) * stripe_len);
+                       OBD_FREE_PTR_ARRAY(ost_indices, stripe_len);
        } else {
                lod_comp->llc_stripe = stripe;
                lod_comp->llc_ost_indices = ost_indices;
index d38bca0..f14680c 100644 (file)
@@ -1818,8 +1818,7 @@ int lod_parse_dir_striping(const struct lu_env *env, struct lod_object *lo,
                RETURN(-EINVAL);
 
        LASSERT(lo->ldo_stripe == NULL);
-       OBD_ALLOC(stripe, sizeof(stripe[0]) *
-                 (le32_to_cpu(lmv1->lmv_stripe_count)));
+       OBD_ALLOC_PTR_ARRAY(stripe, le32_to_cpu(lmv1->lmv_stripe_count));
        if (stripe == NULL)
                RETURN(-ENOMEM);
 
@@ -2218,7 +2217,7 @@ static int lod_prep_md_striped_create(const struct lu_env *env,
 
        stripe_count = lo->ldo_dir_stripe_count;
 
-       OBD_ALLOC(stripes, sizeof(stripes[0]) * stripe_count);
+       OBD_ALLOC_PTR_ARRAY(stripes, stripe_count);
        if (!stripes)
                RETURN(-ENOMEM);
 
@@ -2242,7 +2241,7 @@ static int lod_prep_md_striped_create(const struct lu_env *env,
                int *idx_array;
                bool is_specific = false;
 
-               OBD_ALLOC(idx_array, sizeof(idx_array[0]) * stripe_count);
+               OBD_ALLOC_PTR_ARRAY(idx_array, stripe_count);
                if (!idx_array)
                        GOTO(out, rc = -ENOMEM);
 
@@ -2258,7 +2257,7 @@ static int lod_prep_md_striped_create(const struct lu_env *env,
                        lu_site2seq(lod2lu_dev(lod)->ld_site)->ss_node_id;
                rc = lod_mdt_alloc_specific(env, lo, stripes, idx_array,
                                            is_specific);
-               OBD_FREE(idx_array, sizeof(idx_array[0]) * stripe_count);
+               OBD_FREE_PTR_ARRAY(idx_array, stripe_count);
        }
 
        if (rc < 0)
@@ -2285,7 +2284,7 @@ out:
                dt_object_put(env, stripes[0]);
        for (i = 1; i < stripe_count; i++)
                LASSERT(!stripes[i]);
-       OBD_FREE(stripes, sizeof(stripes[0]) * stripe_count);
+       OBD_FREE_PTR_ARRAY(stripes, stripe_count);
 
        return rc;
 }
@@ -2743,7 +2742,7 @@ static int lod_declare_layout_add(const struct lu_env *env,
                RETURN(-EINVAL);
 
        array_cnt = lo->ldo_comp_cnt + comp_v1->lcm_entry_count;
-       OBD_ALLOC(comp_array, sizeof(*comp_array) * array_cnt);
+       OBD_ALLOC_PTR_ARRAY(comp_array, array_cnt);
        if (comp_array == NULL)
                RETURN(-ENOMEM);
 
@@ -2797,7 +2796,7 @@ static int lod_declare_layout_add(const struct lu_env *env,
                GOTO(error, rc);
        }
 
-       OBD_FREE(old_array, sizeof(*lod_comp) * old_array_cnt);
+       OBD_FREE_PTR_ARRAY(old_array, old_array_cnt);
 
        LASSERT(lo->ldo_mirror_count == 1);
        lo->ldo_mirrors[0].lme_end = array_cnt - 1;
@@ -2813,7 +2812,7 @@ error:
                        lod_comp->llc_pool = NULL;
                }
        }
-       OBD_FREE(comp_array, sizeof(*comp_array) * array_cnt);
+       OBD_FREE_PTR_ARRAY(comp_array, array_cnt);
        RETURN(rc);
 }
 
@@ -4202,7 +4201,7 @@ static int lod_layout_repeat_comp(const struct lu_env *env,
 
        CDEBUG(D_LAYOUT, "repeating component %d\n", index);
 
-       OBD_ALLOC(comp_array, sizeof(*comp_array) * new_cnt);
+       OBD_ALLOC_PTR_ARRAY(comp_array, new_cnt);
        if (comp_array == NULL)
                GOTO(out, rc = -ENOMEM);
 
@@ -4249,8 +4248,7 @@ static int lod_layout_repeat_comp(const struct lu_env *env,
                new_comp->llc_ostlist.op_array = op_array;
        }
 
-       OBD_FREE(lo->ldo_comp_entries,
-                sizeof(*comp_array) * lo->ldo_comp_cnt);
+       OBD_FREE_PTR_ARRAY(lo->ldo_comp_entries, lo->ldo_comp_cnt);
        lo->ldo_comp_entries = comp_array;
        lo->ldo_comp_cnt = new_cnt;
 
@@ -4264,7 +4262,7 @@ static int lod_layout_repeat_comp(const struct lu_env *env,
        EXIT;
 out:
        if (rc)
-               OBD_FREE(comp_array, sizeof(*comp_array) * new_cnt);
+               OBD_FREE_PTR_ARRAY(comp_array, new_cnt);
 
        return rc;
 }
@@ -4281,12 +4279,11 @@ static int lod_layout_data_init(struct lod_thread_info *info, __u32 comp_cnt)
                RETURN(0);
 
        if (info->lti_comp_size > 0) {
-               OBD_FREE(info->lti_comp_idx,
-                        info->lti_comp_size * sizeof(__u32));
+               OBD_FREE_PTR_ARRAY(info->lti_comp_idx, info->lti_comp_size);
                info->lti_comp_size = 0;
        }
 
-       OBD_ALLOC(info->lti_comp_idx, comp_cnt * sizeof(__u32));
+       OBD_ALLOC_PTR_ARRAY(info->lti_comp_idx, comp_cnt);
        if (!info->lti_comp_idx)
                RETURN(-ENOMEM);
 
@@ -4373,11 +4370,11 @@ static int lod_layout_del_prep_layout(const struct lu_env *env,
                        lu_object_put(env, &obj->do_lu);
                        lod_comp->llc_stripe[j] = NULL;
                }
-               OBD_FREE(lod_comp->llc_stripe, sizeof(*lod_comp->llc_stripe) *
-                                       lod_comp->llc_stripes_allocated);
+               OBD_FREE_PTR_ARRAY(lod_comp->llc_stripe,
+                                  lod_comp->llc_stripes_allocated);
                lod_comp->llc_stripe = NULL;
-               OBD_FREE(lod_comp->llc_ost_indices,
-                        sizeof(__u32) * lod_comp->llc_stripes_allocated);
+               OBD_FREE_PTR_ARRAY(lod_comp->llc_ost_indices,
+                                  lod_comp->llc_stripes_allocated);
                lod_comp->llc_ost_indices = NULL;
                lod_comp->llc_stripes_allocated = 0;
        }
@@ -4390,7 +4387,7 @@ static int lod_layout_del_prep_layout(const struct lu_env *env,
        if (info->lti_count > 0) {
                struct lod_layout_component *comp_array;
 
-               OBD_ALLOC(comp_array, sizeof(*comp_array) * info->lti_count);
+               OBD_ALLOC_PTR_ARRAY(comp_array, info->lti_count);
                if (comp_array == NULL)
                        GOTO(out, rc = -ENOMEM);
 
@@ -4400,8 +4397,7 @@ static int lod_layout_del_prep_layout(const struct lu_env *env,
                               sizeof(*comp_array));
                }
 
-               OBD_FREE(lo->ldo_comp_entries,
-                        sizeof(*comp_array) * lo->ldo_comp_cnt);
+               OBD_FREE_PTR_ARRAY(lo->ldo_comp_entries, lo->ldo_comp_cnt);
                lo->ldo_comp_entries = comp_array;
                lo->ldo_comp_cnt = info->lti_count;
        } else {
@@ -7719,8 +7715,7 @@ static int lod_dir_declare_layout_attach(const struct lu_env *env,
 
        dof->dof_type = DFT_DIR;
 
-       OBD_ALLOC(stripes,
-                 sizeof(*stripes) * (lo->ldo_dir_stripe_count + stripe_count));
+       OBD_ALLOC_PTR_ARRAY(stripes, (lo->ldo_dir_stripe_count + stripe_count));
        if (!stripes)
                RETURN(-ENOMEM);
 
@@ -7811,8 +7806,8 @@ static int lod_dir_declare_layout_attach(const struct lu_env *env,
        }
 
        if (lo->ldo_stripe)
-               OBD_FREE(lo->ldo_stripe,
-                        sizeof(*stripes) * lo->ldo_dir_stripes_allocated);
+               OBD_FREE_PTR_ARRAY(lo->ldo_stripe,
+                                  lo->ldo_dir_stripes_allocated);
        lo->ldo_stripe = stripes;
        lo->ldo_dir_migrate_offset = lo->ldo_dir_stripe_count;
        lo->ldo_dir_migrate_hash = le32_to_cpu(lmv->lmv_hash_type);
@@ -7831,8 +7826,7 @@ out:
        while (i < lo->ldo_dir_stripe_count + stripe_count && stripes[i])
                dt_object_put(env, stripes[i++]);
 
-       OBD_FREE(stripes,
-                sizeof(*stripes) * (stripe_count + lo->ldo_dir_stripe_count));
+       OBD_FREE_PTR_ARRAY(stripes, stripe_count + lo->ldo_dir_stripe_count);
        return rc;
 }
 
@@ -8148,8 +8142,7 @@ static int lod_dir_layout_detach(const struct lu_env *env,
                if (dto)
                        dt_object_put(env, dto);
        }
-       OBD_FREE(lo->ldo_stripe,
-                sizeof(struct dt_object *) * lo->ldo_dir_stripes_allocated);
+       OBD_FREE_PTR_ARRAY(lo->ldo_stripe, lo->ldo_dir_stripes_allocated);
        lo->ldo_stripe = NULL;
        lo->ldo_dir_stripes_allocated = 0;
        lo->ldo_dir_stripe_count = 0;
@@ -8633,13 +8626,11 @@ void lod_striping_free_nolock(const struct lu_env *env, struct lod_object *lo)
                                        lu_object_put(env,
                                               &lod_comp->llc_stripe[j]->do_lu);
                        }
-                       OBD_FREE(lod_comp->llc_stripe,
-                                sizeof(struct dt_object *) *
-                                lod_comp->llc_stripes_allocated);
+                       OBD_FREE_PTR_ARRAY(lod_comp->llc_stripe,
+                                          lod_comp->llc_stripes_allocated);
                        lod_comp->llc_stripe = NULL;
-                       OBD_FREE(lod_comp->llc_ost_indices,
-                                sizeof(__u32) *
-                                lod_comp->llc_stripes_allocated);
+                       OBD_FREE_PTR_ARRAY(lod_comp->llc_ost_indices,
+                                          lod_comp->llc_stripes_allocated);
                        lod_comp->llc_ost_indices = NULL;
                        lod_comp->llc_stripes_allocated = 0;
                }
index 249d3cf..b4f9f05 100644 (file)
@@ -2306,8 +2306,7 @@ int lod_prepare_avoidance(const struct lu_env *env, struct lod_object *lo)
        lag->lag_oaa_count = 0;
        if (lag->lag_oss_avoid_array &&
            lag->lag_oaa_size < lod->lod_ost_count) {
-               OBD_FREE(lag->lag_oss_avoid_array,
-                        sizeof(__u32) * lag->lag_oaa_size);
+               OBD_FREE_PTR_ARRAY(lag->lag_oss_avoid_array, lag->lag_oaa_size);
                lag->lag_oss_avoid_array = NULL;
                lag->lag_oaa_size = 0;
        }
@@ -2335,7 +2334,7 @@ int lod_prepare_avoidance(const struct lu_env *env, struct lod_object *lo)
                 * using OST count to allocate the array to store the OSS
                 * id.
                 */
-               OBD_ALLOC(new_oss, sizeof(*new_oss) * lod->lod_ost_count);
+               OBD_ALLOC_PTR_ARRAY(new_oss, lod->lod_ost_count);
                if (!new_oss) {
                        CFS_FREE_BITMAP(bitmap);
                        return -ENOMEM;
@@ -2494,10 +2493,10 @@ int lod_qos_prep_create(const struct lu_env *env, struct lod_object *lo,
                if (stripe_len == 0)
                        GOTO(out, rc = -ERANGE);
                lod_comp->llc_stripe_count = stripe_len;
-               OBD_ALLOC(stripe, sizeof(stripe[0]) * stripe_len);
+               OBD_ALLOC_PTR_ARRAY(stripe, stripe_len);
                if (stripe == NULL)
                        GOTO(out, rc = -ENOMEM);
-               OBD_ALLOC(ost_indices, sizeof(*ost_indices) * stripe_len);
+               OBD_ALLOC_PTR_ARRAY(ost_indices, stripe_len);
                if (!ost_indices)
                        GOTO(out, rc = -ENOMEM);
 
@@ -2576,10 +2575,9 @@ put_ldts:
 out:
        if (rc < 0) {
                if (stripe)
-                       OBD_FREE(stripe, sizeof(stripe[0]) * stripe_len);
+                       OBD_FREE_PTR_ARRAY(stripe, stripe_len);
                if (ost_indices)
-                       OBD_FREE(ost_indices,
-                                sizeof(*ost_indices) * stripe_len);
+                       OBD_FREE_PTR_ARRAY(ost_indices, stripe_len);
        }
        RETURN(rc);
 }
index 1faef7a..ca3c70f 100644 (file)
@@ -258,18 +258,16 @@ static struct lu_device *lov_device_free(const struct lu_env *env,
 
        cl_device_fini(lu2cl_dev(d));
        if (ld->ld_target) {
-               OBD_FREE(ld->ld_target, nr * sizeof ld->ld_target[0]);
+               OBD_FREE_PTR_ARRAY(ld->ld_target, nr);
                ld->ld_target = NULL;
        }
        if (ld->ld_md_tgts) {
-               OBD_FREE(ld->ld_md_tgts,
-                        sizeof(*ld->ld_md_tgts) * LOV_MDC_TGT_MAX);
+               OBD_FREE_PTR_ARRAY(ld->ld_md_tgts, LOV_MDC_TGT_MAX);
                ld->ld_md_tgts = NULL;
        }
        /* free array of MDCs */
        if (ld->ld_lov->lov_mdc_tgts) {
-               OBD_FREE(ld->ld_lov->lov_mdc_tgts,
-                        sizeof(*ld->ld_lov->lov_mdc_tgts) * LOV_MDC_TGT_MAX);
+               OBD_FREE_PTR_ARRAY(ld->ld_lov->lov_mdc_tgts, LOV_MDC_TGT_MAX);
                ld->ld_lov->lov_mdc_tgts = NULL;
        }
 
@@ -305,7 +303,7 @@ static int lov_expand_targets(const struct lu_env *env, struct lov_device *dev)
                struct lovsub_device **newd;
                const size_t sz = sizeof(newd[0]);
 
-               OBD_ALLOC(newd, tgt_size * sz);
+               OBD_ALLOC_PTR_ARRAY(newd, tgt_size);
                if (newd) {
                        if (sub_size > 0) {
                                memcpy(newd, dev->ld_target, sub_size * sz);
@@ -537,15 +535,14 @@ static struct lu_device *lov_device_alloc(const struct lu_env *env,
 
        /* Alloc MDC devices array */
        /* XXX: need dynamic allocation at some moment */
-       OBD_ALLOC(ld->ld_md_tgts, sizeof(*ld->ld_md_tgts) * LOV_MDC_TGT_MAX);
+       OBD_ALLOC_PTR_ARRAY(ld->ld_md_tgts, LOV_MDC_TGT_MAX);
        if (!ld->ld_md_tgts)
                GOTO(out, rc = -ENOMEM);
 
        ld->ld_md_tgts_nr = 0;
 
        ld->ld_lov = &obd->u.lov;
-       OBD_ALLOC(ld->ld_lov->lov_mdc_tgts,
-                 sizeof(*ld->ld_lov->lov_mdc_tgts) * LOV_MDC_TGT_MAX);
+       OBD_ALLOC_PTR_ARRAY(ld->ld_lov->lov_mdc_tgts, LOV_MDC_TGT_MAX);
        if (!ld->ld_lov->lov_mdc_tgts)
                GOTO(out_md_tgts, rc = -ENOMEM);
 
@@ -561,11 +558,10 @@ static struct lu_device *lov_device_alloc(const struct lu_env *env,
 out_site:
        lu_site_fini(&ld->ld_site);
 out_mdc_tgts:
-       OBD_FREE(ld->ld_lov->lov_mdc_tgts,
-                sizeof(*ld->ld_lov->lov_mdc_tgts) * LOV_MDC_TGT_MAX);
+       OBD_FREE_PTR_ARRAY(ld->ld_lov->lov_mdc_tgts, LOV_MDC_TGT_MAX);
        ld->ld_lov->lov_mdc_tgts = NULL;
 out_md_tgts:
-       OBD_FREE(ld->ld_md_tgts, sizeof(*ld->ld_md_tgts) * LOV_MDC_TGT_MAX);
+       OBD_FREE_PTR_ARRAY(ld->ld_md_tgts, LOV_MDC_TGT_MAX);
        ld->ld_md_tgts = NULL;
 out:
        OBD_FREE_PTR(ld);
index 2075312..e1eeceb 100644 (file)
@@ -510,36 +510,36 @@ static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
                RETURN(rc);
        }
 
-        if (index >= lov->lov_tgt_size) {
-                /* We need to reallocate the lov target array. */
-                struct lov_tgt_desc **newtgts, **old = NULL;
-                __u32 newsize, oldsize = 0;
-
-                newsize = max(lov->lov_tgt_size, (__u32)2);
-                while (newsize < index + 1)
-                        newsize = newsize << 1;
-                OBD_ALLOC(newtgts, sizeof(*newtgts) * newsize);
-                if (newtgts == NULL) {
+       if (index >= lov->lov_tgt_size) {
+               /* We need to reallocate the lov target array. */
+               struct lov_tgt_desc **newtgts, **old = NULL;
+               __u32 newsize, oldsize = 0;
+
+               newsize = max(lov->lov_tgt_size, 2U);
+               while (newsize < index + 1)
+                       newsize = newsize << 1;
+               OBD_ALLOC_PTR_ARRAY(newtgts, newsize);
+               if (newtgts == NULL) {
                        mutex_unlock(&lov->lov_lock);
-                        RETURN(-ENOMEM);
-                }
+                       RETURN(-ENOMEM);
+               }
 
-                if (lov->lov_tgt_size) {
-                        memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
-                               lov->lov_tgt_size);
-                        old = lov->lov_tgts;
-                        oldsize = lov->lov_tgt_size;
-                }
+               if (lov->lov_tgt_size) {
+                       memcpy(newtgts, lov->lov_tgts, sizeof(*newtgts) *
+                              lov->lov_tgt_size);
+                       old = lov->lov_tgts;
+                       oldsize = lov->lov_tgt_size;
+               }
 
                lov->lov_tgts = newtgts;
                lov->lov_tgt_size = newsize;
                smp_rmb();
                if (old)
-                       OBD_FREE(old, sizeof(*old) * oldsize);
+                       OBD_FREE_PTR_ARRAY(old, oldsize);
 
-                CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
-                       lov->lov_tgts, lov->lov_tgt_size);
-        }
+               CDEBUG(D_CONFIG, "tgts: %p size: %d\n",
+                      lov->lov_tgts, lov->lov_tgt_size);
+       }
 
         OBD_ALLOC_PTR(tgt);
         if (!tgt) {
@@ -825,10 +825,9 @@ static int lov_cleanup(struct obd_device *obd)
                        lov_del_target(obd, i, NULL, 0);
                }
                lov_tgts_putref(obd);
-                OBD_FREE(lov->lov_tgts, sizeof(*lov->lov_tgts) *
-                         lov->lov_tgt_size);
-                lov->lov_tgt_size = 0;
-        }
+               OBD_FREE_PTR_ARRAY(lov->lov_tgts, lov->lov_tgt_size);
+               lov->lov_tgt_size = 0;
+       }
 
        if (lov->lov_cache != NULL) {
                cl_cache_decref(lov->lov_cache);
index c41a853..0e39826 100644 (file)
@@ -216,7 +216,7 @@ static int lov_init_raid0(const struct lu_env *env, struct lov_device *dev,
        spin_lock_init(&r0->lo_sub_lock);
        r0->lo_nr = lse->lsme_stripe_count;
 
-       OBD_ALLOC_LARGE(r0->lo_sub, r0->lo_nr * sizeof(r0->lo_sub[0]));
+       OBD_ALLOC_PTR_ARRAY_LARGE(r0->lo_sub, r0->lo_nr);
        if (r0->lo_sub == NULL)
                GOTO(out, result = -ENOMEM);
 
@@ -335,7 +335,7 @@ static void lov_fini_raid0(const struct lu_env *env,
        struct lov_layout_raid0 *r0 = &lle->lle_raid0;
 
        if (r0->lo_sub != NULL) {
-               OBD_FREE_LARGE(r0->lo_sub, r0->lo_nr * sizeof r0->lo_sub[0]);
+               OBD_FREE_PTR_ARRAY_LARGE(r0->lo_sub, r0->lo_nr);
                r0->lo_sub = NULL;
        }
 }
@@ -646,12 +646,11 @@ static int lov_init_composite(const struct lu_env *env, struct lov_device *dev,
        if (equi(flr_state == LCM_FL_NONE, comp->lo_mirror_count > 1))
                RETURN(-EINVAL);
 
-       OBD_ALLOC(comp->lo_mirrors,
-                 comp->lo_mirror_count * sizeof(*comp->lo_mirrors));
+       OBD_ALLOC_PTR_ARRAY(comp->lo_mirrors, comp->lo_mirror_count);
        if (comp->lo_mirrors == NULL)
                RETURN(-ENOMEM);
 
-       OBD_ALLOC(comp->lo_entries, entry_count * sizeof(*comp->lo_entries));
+       OBD_ALLOC_PTR_ARRAY(comp->lo_entries, entry_count);
        if (comp->lo_entries == NULL)
                RETURN(-ENOMEM);
 
@@ -873,14 +872,12 @@ static void lov_fini_composite(const struct lu_env *env,
                        if (entry->lle_comp_ops)
                                entry->lle_comp_ops->lco_fini(env, entry);
 
-               OBD_FREE(comp->lo_entries,
-                        comp->lo_entry_count * sizeof(*comp->lo_entries));
+               OBD_FREE_PTR_ARRAY(comp->lo_entries, comp->lo_entry_count);
                comp->lo_entries = NULL;
        }
 
        if (comp->lo_mirrors != NULL) {
-               OBD_FREE(comp->lo_mirrors,
-                        comp->lo_mirror_count * sizeof(*comp->lo_mirrors));
+               OBD_FREE_PTR_ARRAY(comp->lo_mirrors, comp->lo_mirror_count);
                comp->lo_mirrors = NULL;
        }