The construct
LIBCFS_ALLOC(var, sizeof(*var));
is more obviously correct than
LIBCFS_ALLOC(var, sizeof(struct something));
and is preferred upstream (where it is actually kzalloc
or similar of course).
When it is that simple, and there is no multiplier for
the size,
CFS_ALLOC_PTR(var);
is even better.
The same logic applies to OBD_ALLOC(), LIBCFS_FREE(),
and OBD_FREE().
So convert allocations and frees that use sizeof(struct..)
to use one of the simpler constructs.
In mgs_write_log_mdt0, uuid is better declared as a
"struct obd_uuid *" which is a struct that contain a 'char'
array.
Test-Parameters: trivial
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: I8cd97c75241bbb87d15cc6b7c9ac2a7d6184d700
Reviewed-on: https://review.whamcloud.com/36661
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
14 files changed:
pool->po_size * sizeof(struct kib_tx));
out:
kiblnd_fini_pool(pool);
pool->po_size * sizeof(struct kib_tx));
out:
kiblnd_fini_pool(pool);
- LIBCFS_FREE(tpo, sizeof(struct kib_tx_pool));
}
static int kiblnd_tx_pool_size(struct lnet_ni *ni, int ncpts)
}
static int kiblnd_tx_pool_size(struct lnet_ni *ni, int ncpts)
npg = (size * IBLND_MSG_SIZE + PAGE_SIZE - 1) / PAGE_SIZE;
if (kiblnd_alloc_pages(&tpo->tpo_tx_pages, ps->ps_cpt, npg) != 0) {
CERROR("Can't allocate tx pages: %d\n", npg);
npg = (size * IBLND_MSG_SIZE + PAGE_SIZE - 1) / PAGE_SIZE;
if (kiblnd_alloc_pages(&tpo->tpo_tx_pages, ps->ps_cpt, npg) != 0) {
CERROR("Can't allocate tx pages: %d\n", npg);
- LIBCFS_FREE(tpo, sizeof(struct kib_tx_pool));
return -ENOMEM;
if (count != 0) {
return -ENOMEM;
if (count != 0) {
- LIBCFS_ALLOC(eq->eq_events, count * sizeof(struct lnet_event));
+ LIBCFS_ALLOC(eq->eq_events, count * sizeof(*eq->eq_events));
if (eq->eq_events == NULL)
goto failed;
/* NB allocator has set all event sequence numbers to 0,
if (eq->eq_events == NULL)
goto failed;
/* NB allocator has set all event sequence numbers to 0,
failed:
if (eq->eq_events != NULL)
failed:
if (eq->eq_events != NULL)
- LIBCFS_FREE(eq->eq_events, count * sizeof(struct lnet_event));
+ LIBCFS_FREE(eq->eq_events, count * sizeof(*eq->eq_events));
if (eq->eq_refs != NULL)
cfs_percpt_free(eq->eq_refs);
if (eq->eq_refs != NULL)
cfs_percpt_free(eq->eq_refs);
lnet_res_unlock(LNET_LOCK_EX);
if (events != NULL)
lnet_res_unlock(LNET_LOCK_EX);
if (events != NULL)
- LIBCFS_FREE(events, size * sizeof(struct lnet_event));
+ LIBCFS_FREE(events, size * sizeof(*events));
if (refs != NULL)
cfs_percpt_free(refs);
if (refs != NULL)
cfs_percpt_free(refs);
- LIBCFS_ALLOC(addrrange, sizeof(struct addrrange));
+ CFS_ALLOC_PTR(addrrange);
if (addrrange == NULL)
return -ENOMEM;
list_add_tail(&addrrange->ar_link, &nidrange->nr_addrranges);
if (addrrange == NULL)
return -ENOMEM;
list_add_tail(&addrrange->ar_link, &nidrange->nr_addrranges);
- LIBCFS_ALLOC(nr, sizeof(struct nidrange));
if (nr == NULL)
return NULL;
list_add_tail(&nr->nr_link, nidlist);
if (nr == NULL)
return NULL;
list_add_tail(&nr->nr_link, nidlist);
cfs_expr_list_free_list(&ar->ar_numaddr_ranges);
list_del(&ar->ar_link);
cfs_expr_list_free_list(&ar->ar_numaddr_ranges);
list_del(&ar->ar_link);
- LIBCFS_FREE(ar, sizeof(struct addrrange));
nr = list_entry(pos, struct nidrange, nr_link);
free_addrranges(&nr->nr_addrranges);
list_del(pos);
nr = list_entry(pos, struct nidrange, nr_link);
free_addrranges(&nr->nr_addrranges);
list_del(pos);
- LIBCFS_FREE(nr, sizeof(struct nidrange));
}
}
EXPORT_SYMBOL(cfs_free_nidlist);
}
}
EXPORT_SYMBOL(cfs_free_nidlist);
}
/* non-verbose query */
}
/* non-verbose query */
- LIBCFS_ALLOC(gentp, sizeof(struct lstcon_ndlist_ent));
if (gentp == NULL) {
CERROR("Can't allocate ndlist_ent\n");
lstcon_group_decref(grp);
if (gentp == NULL) {
CERROR("Can't allocate ndlist_ent\n");
lstcon_group_decref(grp);
rc = copy_to_user(gents_p, gentp,
sizeof(struct lstcon_ndlist_ent)) ? -EFAULT : 0;
rc = copy_to_user(gents_p, gentp,
sizeof(struct lstcon_ndlist_ent)) ? -EFAULT : 0;
- LIBCFS_FREE(gentp, sizeof(struct lstcon_ndlist_ent));
lstcon_group_decref(grp);
lstcon_group_decref(grp);
}
/* non-verbose query */
}
/* non-verbose query */
- LIBCFS_ALLOC(entp, sizeof(struct lstcon_test_batch_ent));
if (entp == NULL)
return -ENOMEM;
if (entp == NULL)
return -ENOMEM;
rc = copy_to_user(ent_up, entp,
sizeof(struct lstcon_test_batch_ent)) ? -EFAULT : 0;
rc = copy_to_user(ent_up, entp,
sizeof(struct lstcon_test_batch_ent)) ? -EFAULT : 0;
- LIBCFS_FREE(entp, sizeof(struct lstcon_test_batch_ent));
else
count = lmv4->lmv_stripe_count;
else
count = lmv4->lmv_stripe_count;
- OBD_ALLOC_LARGE(lslr, sizeof(struct lfsck_slave_lmv_rec) * count);
+ OBD_ALLOC_LARGE(lslr, sizeof(*lslr) * count);
if (lslr == NULL) {
OBD_FREE_PTR(llu);
if (lslr == NULL) {
OBD_FREE_PTR(llu);
{
struct pcc_match_fname *fname;
{
struct pcc_match_fname *fname;
- OBD_ALLOC(fname, sizeof(struct pcc_match_fname));
if (fname == NULL)
return -ENOMEM;
OBD_ALLOC(fname->pmf_name, id->ls_len + 1);
if (fname->pmf_name == NULL) {
if (fname == NULL)
return -ENOMEM;
OBD_ALLOC(fname->pmf_name, id->ls_len + 1);
if (fname->pmf_name == NULL) {
- OBD_FREE(fname, sizeof(struct pcc_match_fname));
struct cfs_lstr field;
int rc = 0;
struct cfs_lstr field;
int rc = 0;
- OBD_ALLOC(expr, sizeof(struct pcc_expression));
if (expr == NULL)
return -ENOMEM;
if (expr == NULL)
return -ENOMEM;
struct cfs_lstr expr;
int rc = 0;
struct cfs_lstr expr;
int rc = 0;
- OBD_ALLOC(conjunction, sizeof(struct pcc_conjunction));
+ OBD_ALLOC_PTR(conjunction);
if (conjunction == NULL)
return -ENOMEM;
if (conjunction == NULL)
return -ENOMEM;
lu_object_put(env, &obj->do_lu);
lod_comp->llc_stripe[j] = NULL;
}
lu_object_put(env, &obj->do_lu);
lod_comp->llc_stripe[j] = NULL;
}
- OBD_FREE(lod_comp->llc_stripe, sizeof(struct dt_object *) *
+ OBD_FREE(lod_comp->llc_stripe, sizeof(*lod_comp->llc_stripe) *
lod_comp->llc_stripes_allocated);
lod_comp->llc_stripe = NULL;
OBD_FREE(lod_comp->llc_ost_indices,
lod_comp->llc_stripes_allocated);
lod_comp->llc_stripe = NULL;
OBD_FREE(lod_comp->llc_ost_indices,
{
char *log = mti->mti_svname;
struct llog_handle *llh = NULL;
{
char *log = mti->mti_svname;
struct llog_handle *llh = NULL;
+ struct obd_uuid *uuid;
+ char *lovname;
char mdt_index[6];
char *ptr = mti->mti_params;
int rc = 0, failout = 0;
ENTRY;
char mdt_index[6];
char *ptr = mti->mti_params;
int rc = 0, failout = 0;
ENTRY;
- OBD_ALLOC(uuid, sizeof(struct obd_uuid));
if (uuid == NULL)
RETURN(-ENOMEM);
if (uuid == NULL)
RETURN(-ENOMEM);
/* add MDT itself */
/* FIXME this whole fn should be a single journal transaction */
/* add MDT itself */
/* FIXME this whole fn should be a single journal transaction */
- sprintf(uuid, "%s_UUID", log);
+ sprintf(uuid->uuid, "%s_UUID", log);
rc = record_marker(env, llh, fsdb, CM_START, log, "add mdt");
if (rc)
GOTO(out_lod, rc);
rc = record_marker(env, llh, fsdb, CM_START, log, "add mdt");
if (rc)
GOTO(out_lod, rc);
- rc = record_attach(env, llh, log, LUSTRE_MDT_NAME, uuid);
+ rc = record_attach(env, llh, log, LUSTRE_MDT_NAME, uuid->uuid);
if (rc)
GOTO(out_end, rc);
rc = record_mount_opt(env, llh, log, lovname, NULL);
if (rc)
GOTO(out_end, rc);
if (rc)
GOTO(out_end, rc);
rc = record_mount_opt(env, llh, log, lovname, NULL);
if (rc)
GOTO(out_end, rc);
- rc = record_setup(env, llh, log, uuid, mdt_index, lovname,
+ rc = record_setup(env, llh, log, uuid->uuid, mdt_index, lovname,
failout ? "n" : "f");
if (rc)
GOTO(out_end, rc);
failout ? "n" : "f");
if (rc)
GOTO(out_end, rc);
out_lod:
name_destroy(&lovname);
out_free:
out_lod:
name_destroy(&lovname);
out_free:
- OBD_FREE(uuid, sizeof(struct obd_uuid));
apc = npages = batch >> PAGE_SHIFT;
tot_pages = count >> PAGE_SHIFT;
apc = npages = batch >> PAGE_SHIFT;
tot_pages = count >> PAGE_SHIFT;
- OBD_ALLOC_LARGE(lnb, apc * sizeof(struct niobuf_local));
+ OBD_ALLOC_LARGE(lnb, apc * sizeof(*lnb));
if (!lnb)
RETURN(-ENOMEM);
if (!lnb)
RETURN(-ENOMEM);
- OBD_FREE_LARGE(lnb, apc * sizeof(struct niobuf_local));
+ OBD_FREE_LARGE(lnb, apc * sizeof(*lnb));
- OBD_ALLOC(batch, nr_saved * sizeof(struct ofd_object *));
+ OBD_ALLOC(batch, nr_saved * sizeof(*batch));
if (batch == NULL)
RETURN(-ENOMEM);
if (batch == NULL)
RETURN(-ENOMEM);
continue;
ofd_object_put(env, fo);
}
continue;
ofd_object_put(env, fo);
}
- OBD_FREE(batch, nr_saved * sizeof(struct ofd_object *));
+ OBD_FREE(batch, nr_saved * sizeof(*batch));
CDEBUG((objects == 0 && rc == 0) ? D_ERROR : D_OTHER,
"created %d/%d objects: %d\n", objects, nr_saved, rc);
CDEBUG((objects == 0 && rc == 0) ? D_ERROR : D_OTHER,
"created %d/%d objects: %d\n", objects, nr_saved, rc);
open:
LASSERT((count & (count - 1)) == 0);
o->od_oi_count = count;
open:
LASSERT((count & (count - 1)) == 0);
o->od_oi_count = count;
- OBD_ALLOC(o->od_oi_table, sizeof(struct osd_oi *) * count);
+ OBD_ALLOC(o->od_oi_table, sizeof(*o->od_oi_table) * count);
if (o->od_oi_table == NULL)
GOTO(out, rc = -ENOMEM);
if (o->od_oi_table == NULL)
GOTO(out, rc = -ENOMEM);
{
struct ptlrpc_request_pool *pool;
{
struct ptlrpc_request_pool *pool;
- OBD_ALLOC(pool, sizeof(struct ptlrpc_request_pool));
list_for_each_entry_safe(jobid, n, jobid_list, tj_linkage) {
OBD_FREE(jobid->tj_id, strlen(jobid->tj_id) + 1);
list_del(&jobid->tj_linkage);
list_for_each_entry_safe(jobid, n, jobid_list, tj_linkage) {
OBD_FREE(jobid->tj_id, strlen(jobid->tj_id) + 1);
list_del(&jobid->tj_linkage);
- OBD_FREE(jobid, sizeof(struct nrs_tbf_jobid));
struct nrs_tbf_jobid *jobid;
char *ptr;
struct nrs_tbf_jobid *jobid;
char *ptr;
- OBD_ALLOC(jobid, sizeof(struct nrs_tbf_jobid));
if (jobid == NULL)
return -ENOMEM;
OBD_ALLOC(jobid->tj_id, id->ls_len + 1);
if (jobid->tj_id == NULL) {
if (jobid == NULL)
return -ENOMEM;
OBD_ALLOC(jobid->tj_id, id->ls_len + 1);
if (jobid->tj_id == NULL) {
- OBD_FREE(jobid, sizeof(struct nrs_tbf_jobid));
struct cfs_lstr field;
int rc = 0;
struct cfs_lstr field;
int rc = 0;
- OBD_ALLOC(expr, sizeof(struct nrs_tbf_expression));
if (expr == NULL)
return -ENOMEM;
if (expr == NULL)
return -ENOMEM;
struct cfs_lstr expr;
int rc = 0;
struct cfs_lstr expr;
int rc = 0;
- OBD_ALLOC(conjunction, sizeof(struct nrs_tbf_conjunction));
+ OBD_ALLOC_PTR(conjunction);
if (conjunction == NULL)
return -ENOMEM;
if (conjunction == NULL)
return -ENOMEM;
orr = (struct out_read_reply *)update_result->our_data;
nbufs = (size + OUT_BULK_BUFFER_SIZE - 1) / OUT_BULK_BUFFER_SIZE;
orr = (struct out_read_reply *)update_result->our_data;
nbufs = (size + OUT_BULK_BUFFER_SIZE - 1) / OUT_BULK_BUFFER_SIZE;
- OBD_ALLOC(rdbuf, sizeof(struct lu_rdbuf) +
- nbufs * sizeof(rdbuf->rb_bufs[0]));
+ OBD_ALLOC(rdbuf, sizeof(*rdbuf) + nbufs * sizeof(rdbuf->rb_bufs[0]));
if (rdbuf == NULL)
GOTO(out, rc = -ENOMEM);
if (rdbuf == NULL)
GOTO(out, rc = -ENOMEM);
rdbuf->rb_bufs[i].lb_len);
}
}
rdbuf->rb_bufs[i].lb_len);
}
}
- OBD_FREE(rdbuf, sizeof(struct lu_rdbuf) +
+ OBD_FREE(rdbuf, sizeof(*rdbuf) +
nbufs * sizeof(rdbuf->rb_bufs[0]));
out:
/* Insert read buffer */
nbufs * sizeof(rdbuf->rb_bufs[0]));
out:
/* Insert read buffer */