use DIV_ROUND_UP helper macro for calculations
Subsystems (2)
cover use DIV_ROUND_UP helper macro for calculations
This patchset is replace open coded divisor calculations with the DIV_ROUND_UP kernel macro for better readability.
Wu Bo (2):
crypto: af_alg - use DIV_ROUND_UP helper macro for calculations
fs: direct-io: use DIV_ROUND_UP helper macro for calculations
crypto/af_alg.c | 2 +- fs/direct-io.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/2 crypto: af_alg - use DIV_ROUND_UP helper macro for calculations
From: Wu Bo <[email protected]>
Replace open coded divisor calculations with the DIV_ROUND_UP kernel macro for better readability.
--- crypto/af_alg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/af_alg.c +1 -1
@@ -411,7 +411,7 @@ int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len)if (n <0 )return n; - npages = (off + n +PAGE_SIZE -1 ) >>PAGE_SHIFT ; + npages =DIV_ROUND_UP (off + n,PAGE_SIZE );if (WARN_ON (npages ==0 ))return -EINVAL ;/* Add one extra for linking */
Signature · 1 line
1.8.3.1
Re: [PATCH 1/2] crypto: af_alg - use DIV_ROUND_UP helper macro for calculations
Wu Bo <[email protected]> a écrit :
Quoted 15 lines
From: Wu Bo <[email protected]>
Replace open coded divisor calculations with the
DIV_ROUND_UPkernel macro for better readability.Signed-off-by Wu Bo <[email protected]>--- crypto/af_alg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)crypto/af_alg.c +0
-0
crypto/af_alg.c int af_alg_make_sg(struct af_alg_sgl *sgl, · line 415
Quoted 6 lines
crypto/af_alg.c +1
-1@@ -411,7 +411,7 @@ int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len) if (n < 0) return n; - npages = (off + n + PAGE_SIZE - 1) >> PAGE_SHIFT; + npages = DIV_ROUND_UP(off + n, PAGE_SIZE);
You should use PFN_UP()
Quoted 5 lines
crypto/af_alg.c +0
-0if (WARN_ON (npages ==0 ))return -EINVAL ;/* Add one extra for linking */
--
1.8.3.1
Re: [PATCH 1/2] crypto: af_alg - use DIV_ROUND_UP helper macro for calculations
Quoted 21 lines · Christophe Leroy
Wu Bo <[email protected]> a écrit :
Quoted 19 lines
From: Wu Bo <[email protected]>
Replace open coded divisor calculations with the
DIV_ROUND_UPkernel macro for better readability.Signed-off-by Wu Bo <[email protected]>--- crypto/af_alg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)crypto/af_alg.c +0
-0@@ -411,7 +411,7 @@ int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len) if (n < 0) return n;
Quoted 4 lines
crypto/af_alg.c int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len) · line 414
Quoted 2 lines
crypto/af_alg.c +1
-1- npages = (off + n +PAGE_SIZE -1 ) >>PAGE_SHIFT ; + npages =DIV_ROUND_UP (off + n,PAGE_SIZE );You should use
PFN_UP()
No. We are not using pfns here - we're converting a byte count to a page count.
Besides, "PFN_UP" is a horrible, awful api. It does not decribe what it does and anyone who is not a mm developer will look at it and ask "what <the ....> does this do?" and have to go looking for it's definition to determine what it does. Yes, that's exactyl what I've just done, and I really wish I didn't because, well, it just reinforces how much we suck at APIs...
OTOH, what DIV_ROUND_UP() does is obvious, widely understood, self documenting and easy to determine if the usage is correct, which indeed this is.
The lesson: do not use whacky obscure, out of context macros when a simple, obvious, widely known macro will give the same result and make the code easier to understand.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Herbert Xu
maintainerRe: [PATCH 1/2] crypto: af_alg - use DIV_ROUND_UP helper macro for calculations
In reply to Wu BoQuoted 9 lines · Wu Bo
From: Wu Bo <[email protected]>
Replace open coded divisor calculations with the
DIV_ROUND_UPkernel macro for better readability.Signed-off-by Wu Bo <[email protected]>--- crypto/af_alg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
PATCH 2/2 fs: direct-io: use DIV_ROUND_UP helper macro for calculations
In reply to Wu BoFrom: Wu Bo <[email protected]>
Replace open coded divisor calculations with the DIV_ROUND_UP kernel macro for better readability.
--- fs/direct-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/direct-io.c +1 -1
@@ -195,7 +195,7 @@ static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio)iov_iter_advance (sdio->iter, ret); ret += sdio->from; sdio->head =0 ; - sdio->tail = (ret +PAGE_SIZE -1 ) /PAGE_SIZE ; + sdio->tail =DIV_ROUND_UP (ret,PAGE_SIZE ); sdio->to = ((ret -1 ) & (PAGE_SIZE -1 )) +1 ;return 0 ; }
Signature · 1 line
1.8.3.1
Re: [PATCH 2/2] fs: direct-io: use DIV_ROUND_UP helper macro for calculations
Wu Bo <[email protected]> a écrit :
Quoted 15 lines
From: Wu Bo <[email protected]>
Replace open coded divisor calculations with the
DIV_ROUND_UPkernel macro for better readability.Signed-off-by Wu Bo <[email protected]>--- fs/direct-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/direct-io.c +0
-0
fs/direct-io.c static inline int dio_refill_pages(struct dio · line 199
Quoted 6 lines
fs/direct-io.c +1
-1@@ -195,7 +195,7 @@ static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio)iov_iter_advance (sdio->iter, ret); ret += sdio->from; sdio->head =0 ; - sdio->tail = (ret +PAGE_SIZE -1 ) /PAGE_SIZE ; + sdio->tail =DIV_ROUND_UP (ret,PAGE_SIZE );
Use PFN_UP() instead.
Quoted 5 lines
fs/direct-io.c +0
-0sdio->to = ((ret -1 ) & (PAGE_SIZE -1 )) +1 ;return 0 ;}
--
1.8.3.1
Wu Bo <[email protected]> a écrit :
Quoted 2 lines
This patchset is replace open coded divisor calculations with the
DIV_ROUND_UPkernel macro for better readability.
We call it a series not a patchset.
PFN_UP() from pfn.h should be used instead of DIV_ROUND_UP() I believe.
Quoted 11 lines
Wu Bo (2):
crypto:af_alg- useDIV_ROUND_UPhelper macro for calculations
fs: direct-io: useDIV_ROUND_UPhelper macro for calculationscrypto/af_alg.c | 2 +- fs/direct-io.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)--
1.8.3.1