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);
}
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);
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;
}
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;
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;
}
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);
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;
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);
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);
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);
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)
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;
}
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);
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;
lod_comp->llc_pool = NULL;
}
}
- OBD_FREE(comp_array, sizeof(*comp_array) * array_cnt);
+ OBD_FREE_PTR_ARRAY(comp_array, array_cnt);
RETURN(rc);
}
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);
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;
EXIT;
out:
if (rc)
- OBD_FREE(comp_array, sizeof(*comp_array) * new_cnt);
+ OBD_FREE_PTR_ARRAY(comp_array, new_cnt);
return rc;
}
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);
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;
}
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);
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 {
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);
}
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);
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;
}
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;
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;
}
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;
}
* 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;
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);
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);
}
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;
}
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);
/* 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);
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);
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) {
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);
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);
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;
}
}
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);
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;
}