From fce3444aeae22edc2bb6100888be8039a6e9bb5b Mon Sep 17 00:00:00 2001 From: simran singhal Date: Wed, 22 Feb 2017 15:02:04 +0530 Subject: [PATCH] staging: lustre: Using macro DIV_ROUND_UP The macro DIV_ROUND_UP performs the computation (((n) + (d) - 1) /(d)). It clarifies the divisor calculations. This occurence was detected using the coccinelle script: @@ expression e1; expression e2; @@ ( - ((e1) + e2 - 1) / (e2) + DIV_ROUND_UP(e1,e2) | - ((e1) + (e2 - 1)) / (e2) + DIV_ROUND_UP(e1,e2) ) Signed-off-by: simran singhal Signed-off-by: Greg Kroah-Hartman --- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 2 +- drivers/staging/lustre/lnet/selftest/conrpc.c | 11 ++++------- drivers/staging/lustre/lustre/ptlrpc/client.c | 3 +-- drivers/staging/lustre/lustre/ptlrpc/niobuf.c | 2 +- drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c | 2 +- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c index 0618b79..6f73454 100644 --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c @@ -2037,7 +2037,7 @@ static int kiblnd_create_tx_pool(struct kib_poolset *ps, int size, tpo->tpo_tx_descs = NULL; tpo->tpo_tx_pages = NULL; - npg = (size * IBLND_MSG_SIZE + PAGE_SIZE - 1) / PAGE_SIZE; + npg = DIV_ROUND_UP(size * IBLND_MSG_SIZE, PAGE_SIZE); if (kiblnd_alloc_pages(&tpo->tpo_tx_pages, ps->ps_cpt, npg)) { CERROR("Can't allocate tx pages: %d\n", npg); LIBCFS_FREE(tpo, sizeof(*tpo)); diff --git a/drivers/staging/lustre/lnet/selftest/conrpc.c b/drivers/staging/lustre/lnet/selftest/conrpc.c index c6a683b..680a559 100644 --- a/drivers/staging/lustre/lnet/selftest/conrpc.c +++ b/drivers/staging/lustre/lnet/selftest/conrpc.c @@ -785,8 +785,7 @@ lstcon_bulkrpc_v0_prep(struct lst_test_bulk_param *param, struct test_bulk_req *brq = &req->tsr_u.bulk_v0; brq->blk_opc = param->blk_opc; - brq->blk_npg = (param->blk_size + PAGE_SIZE - 1) / - PAGE_SIZE; + brq->blk_npg = DIV_ROUND_UP(param->blk_size, PAGE_SIZE); brq->blk_flags = param->blk_flags; return 0; @@ -833,11 +832,9 @@ lstcon_testrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats, trq = &(*crpc)->crp_rpc->crpc_reqstmsg.msg_body.tes_reqst; if (transop == LST_TRANS_TSBSRVADD) { - int ndist = (sgrp->grp_nnode + test->tes_dist - 1) / - test->tes_dist; - int nspan = (dgrp->grp_nnode + test->tes_span - 1) / - test->tes_span; - int nmax = (ndist + nspan - 1) / nspan; + int ndist = DIV_ROUND_UP(sgrp->grp_nnode, test->tes_dist); + int nspan = DIV_ROUND_UP(dgrp->grp_nnode, test->tes_span); + int nmax = DIV_ROUND_UP(ndist, nspan); trq->tsr_ndest = 0; trq->tsr_loop = nmax * test->tes_dist * test->tes_concur; diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c index 04a98a08..45b9aec 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/client.c +++ b/drivers/staging/lustre/lustre/ptlrpc/client.c @@ -3144,8 +3144,7 @@ void ptlrpc_set_bulk_mbits(struct ptlrpc_request *req) * that server can infer the number of bulks that were prepared, * see LU-1431 */ - req->rq_mbits += ((bd->bd_iov_count + LNET_MAX_IOV - 1) / - LNET_MAX_IOV) - 1; + req->rq_mbits += DIV_ROUND_UP(bd->bd_iov_count, LNET_MAX_IOV) - 1; } /** diff --git a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c index b870184..352f614 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c +++ b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c @@ -142,7 +142,7 @@ static int ptlrpc_register_bulk(struct ptlrpc_request *req) LASSERT(desc->bd_cbid.cbid_fn == client_bulk_callback); LASSERT(desc->bd_cbid.cbid_arg == desc); - total_md = (desc->bd_iov_count + LNET_MAX_IOV - 1) / LNET_MAX_IOV; + total_md = DIV_ROUND_UP(desc->bd_iov_count, LNET_MAX_IOV); /* rq_mbits is matchbits of the final bulk */ mbits = req->rq_mbits - total_md + 1; diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c index 2fe9085..128838a 100644 --- a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c +++ b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c @@ -272,7 +272,7 @@ static unsigned long enc_pools_shrink_scan(struct shrinker *s, static inline int npages_to_npools(unsigned long npages) { - return (int)((npages + PAGES_PER_POOL - 1) / PAGES_PER_POOL); + return (int)DIV_ROUND_UP(npages, PAGES_PER_POOL); } /* -- 2.7.4