[lustre-devel] [PATCH 5/6] staging: lustre: Using macro DIV_ROUND_UP

Joe Perches joe at perches.com
Tue Feb 21 12:40:10 PST 2017


On Tue, 2017-02-21 at 23:16 +0530, simran singhal wrote:
> 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)
> )

Coccinelle scripts are great but please
inspect the results for appropriate style
and simplify the patch where possible.

> diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c
[]
> @@ -3136,8 +3136,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;

Unnecessary parentheses.

> diff --git 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));
>  }

Here too.



More information about the lustre-devel mailing list