staging: rdma: hfi1: Use DIV_ROUND_UP
PATCH 1/1 staging: rdma: hfi1: Use DIV_ROUND_UP
The kernel.h macro DIV_ROUND_UP performs the computation (((n) + (d) - 1) /(d)) but is perhaps more readable.
The Coccinelle script used is as follows:
// <smpl>
@@
expression n,d;
@@
(
- (n + d - 1) / d
+ DIV_ROUND_UP(n,d)
|
- (n + (d - 1)) / d
+ DIV_ROUND_UP(n,d)
)
@@
expression n,d;
@@
- DIV_ROUND_UP((n),d)
+ DIV_ROUND_UP(n,d)
@@
expression n,d;
@@
- DIV_ROUND_UP(n,(d))
+ DIV_ROUND_UP(n,d)
// </smpl>
--- drivers/staging/rdma/hfi1/mr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rdma/hfi1/mr.c +3 -3
@@ -70,7 +70,7 @@ static int init_mregion(struct hfi1_mregion *mr, struct ib_pd *pd,int m, i =0 ;int rval =0 ; - m = (count +HFI1_SEGSZ -1 ) /HFI1_SEGSZ ; + m =DIV_ROUND_UP (count,HFI1_SEGSZ );for (; i < m; i++) { mr->map[i] =kzalloc (sizeof (*mr->map[0 ]),GFP_KERNEL );if (!mr->map[i])
@@ -159,7 +159,7 @@ static struct hfi1_mr *alloc_mr(int count, struct ib_pd *pd)int m;/* Allocate struct plus pointers to first level page tables. */ - m = (count +HFI1_SEGSZ -1 ) /HFI1_SEGSZ ; + m =DIV_ROUND_UP (count,HFI1_SEGSZ ); mr =kzalloc (sizeof (*mr) + m *sizeof (mr->mr.map[0 ]),GFP_KERNEL );if (!mr) goto bail;
@@ -333,7 +333,7 @@ struct ib_fmr *hfi1_alloc_fmr(struct ib_pd *pd, int mr_access_flags,int rval = -ENOMEM ;/* Allocate struct plus pointers to first level page tables. */ - m = (fmr_attr->max_pages +HFI1_SEGSZ -1 ) /HFI1_SEGSZ ; + m =DIV_ROUND_UP (fmr_attr->max_pages,HFI1_SEGSZ ); fmr =kzalloc (sizeof (*fmr) + m *sizeof (fmr->mr.map[0 ]),GFP_KERNEL );if (!fmr) goto bail;
Signature · 1 line
1.9.1
Quoted 5 lines · Amitoj Kaur Chawla
The
kernel.hmacroDIV_ROUND_UPperforms the computation (((n) + (d) - 1) /(d)) but is perhaps more readable.The Coccinelle script used is as follows:
Quoted 11 lines
// <smpl>
@@
expression n,d;
@@
(
- (n + d - 1) / d
+DIV_ROUND_UP(n,d)
|
- (n + (d - 1)) / d
+DIV_ROUND_UP(n,d)
)
If you put parentheses around n and d in the above rules, then you won't need the two rules that come after.
julia
Quoted 58 lines
@@
expression n,d;
@@
- DIV_ROUND_UP((n),d)
+DIV_ROUND_UP(n,d)
@@
expression n,d;
@@
- DIV_ROUND_UP(n,(d))
+DIV_ROUND_UP(n,d)
// </smpl>Signed-off-by Amitoj Kaur Chawla <[email protected]>--- drivers/staging/rdma/hfi1/mr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/staging/rdma/hfi1/mr.c +3
-4@@ -70,7 +70,7 @@ static int init_mregion(struct hfi1_mregion *mr, struct ib_pd *pd,int m, i =0 ;int rval =0 ; - m = (count +HFI1_SEGSZ -1 ) /HFI1_SEGSZ ; + m =DIV_ROUND_UP (count,HFI1_SEGSZ );for (; i < m; i++) { mr->map[i] =kzalloc (sizeof (*mr->map[0 ]),GFP_KERNEL );if (!mr->map[i])@@ -159,7 +159,7 @@ static struct hfi1_mr *alloc_mr(int count, struct ib_pd *pd)int m;/* Allocate struct plus pointers to first level page tables. */ - m = (count +HFI1_SEGSZ -1 ) /HFI1_SEGSZ ; + m =DIV_ROUND_UP (count,HFI1_SEGSZ ); mr =kzalloc (sizeof (*mr) + m *sizeof (mr->mr.map[0 ]),GFP_KERNEL );if (!mr) goto bail;@@ -333,7 +333,7 @@ struct ib_fmr *hfi1_alloc_fmr(struct ib_pd *pd, int mr_access_flags,int rval = -ENOMEM ;/* Allocate struct plus pointers to first level page tables. */ - m = (fmr_attr->max_pages +HFI1_SEGSZ -1 ) /HFI1_SEGSZ ; + m =DIV_ROUND_UP (fmr_attr->max_pages,HFI1_SEGSZ ); fmr =kzalloc (sizeof (*fmr) + m *sizeof (fmr->mr.map[0 ]),GFP_KERNEL );if (!fmr) goto bail; --1.9.1
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160220082827.GA14902%40amitoj-Inspiron-3542.
For more options, visit https://groups.google.com/d/optout.
Quoted 12 lines · Julia Lawall
Quoted 11 lines
// <smpl>
@@
expression n,d;
@@
(
- (n + d - 1) / d
+DIV_ROUND_UP(n,d)
|
- (n + (d - 1)) / d
+DIV_ROUND_UP(n,d)
)
Quoted 4 lines
If you put parentheses around n and d in the above rules, then you won't need the two rules that come after.
julia
Like this?
// <smpl>
@@
expression n,d;
@@
(
- ((n) + d - 1) / (d)
+ DIV_ROUND_UP(n,d)
|
- ((n) + (d - 1)) / (d)
+ DIV_ROUND_UP(n,d)
)
// </smpl>
Amitoj
Quoted 20 lines · Amitoj Kaur Chawla
Quoted 12 lines · Julia Lawall
Quoted 11 lines
// <smpl>
@@
expression n,d;
@@
(
- (n + d - 1) / d
+DIV_ROUND_UP(n,d)
|
- (n + (d - 1)) / d
+DIV_ROUND_UP(n,d)
)Quoted 4 lines
If you put parentheses around n and d in the above rules, then you won't need the two rules that come after.
julia
Like this?
Quoted 12 lines
// <smpl>
@@
expression n,d;
@@
(
- ((n) + d - 1) / (d)
+DIV_ROUND_UP(n,d)
|
- ((n) + (d - 1)) / (d)
+DIV_ROUND_UP(n,d)
)
// </smpl>
Yes.
julia
Quoted 10 lines
Amitoj
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CA%2B5yK5HpAQVmcOMtyto_qdU%3DsMtrTHodKqX-54GzsZkMrJx-pQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Quoted 5 lines · Julia Lawall
Yes.
julia
Next time I try this, I'll use this modified semantic patch.
Thanks,
Amitoj