* [PATCH 0/2] use DIV_ROUND_UP helper macro for calculations @ 2021-05-25 8:15 Wu Bo 2021-05-25 8:15 ` [PATCH 1/2] crypto: af_alg - " Wu Bo ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Wu Bo @ 2021-05-25 8:15 UTC (permalink / raw) To: viro, herbert, davem, linux-fsdevel, linux-crypto, linux-kernel Cc: linfeilong, wubo40 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(-) -- 1.8.3.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] crypto: af_alg - use DIV_ROUND_UP helper macro for calculations 2021-05-25 8:15 [PATCH 0/2] use DIV_ROUND_UP helper macro for calculations Wu Bo @ 2021-05-25 8:15 ` Wu Bo 2021-05-25 8:37 ` Christophe Leroy 2021-06-03 12:30 ` Herbert Xu 2021-05-25 8:15 ` [PATCH 2/2] fs: direct-io: " Wu Bo 2021-05-25 8:41 ` [PATCH 0/2] " Christophe Leroy 2 siblings, 2 replies; 8+ messages in thread From: Wu Bo @ 2021-05-25 8:15 UTC (permalink / raw) To: viro, herbert, davem, linux-fsdevel, linux-crypto, linux-kernel Cc: linfeilong, wubo40 From: Wu Bo <wubo40@huawei.com> Replace open coded divisor calculations with the DIV_ROUND_UP kernel macro for better readability. Signed-off-by: Wu Bo <wubo40@huawei.com> --- crypto/af_alg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 18cc82d..8bd288d 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c @@ -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 */ -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] crypto: af_alg - use DIV_ROUND_UP helper macro for calculations 2021-05-25 8:15 ` [PATCH 1/2] crypto: af_alg - " Wu Bo @ 2021-05-25 8:37 ` Christophe Leroy 2021-05-26 8:31 ` Dave Chinner 2021-06-03 12:30 ` Herbert Xu 1 sibling, 1 reply; 8+ messages in thread From: Christophe Leroy @ 2021-05-25 8:37 UTC (permalink / raw) To: Wu Bo Cc: linfeilong, linux-kernel, linux-crypto, linux-fsdevel, davem, herbert, viro Wu Bo <wubo40@huawei.com> a écrit : > From: Wu Bo <wubo40@huawei.com> > > Replace open coded divisor calculations with the DIV_ROUND_UP kernel > macro for better readability. > > Signed-off-by: Wu Bo <wubo40@huawei.com> > --- > crypto/af_alg.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/crypto/af_alg.c b/crypto/af_alg.c > index 18cc82d..8bd288d 100644 > --- a/crypto/af_alg.c > +++ b/crypto/af_alg.c > @@ -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() > if (WARN_ON(npages == 0)) > return -EINVAL; > /* Add one extra for linking */ > -- > 1.8.3.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] crypto: af_alg - use DIV_ROUND_UP helper macro for calculations 2021-05-25 8:37 ` Christophe Leroy @ 2021-05-26 8:31 ` Dave Chinner 0 siblings, 0 replies; 8+ messages in thread From: Dave Chinner @ 2021-05-26 8:31 UTC (permalink / raw) To: Christophe Leroy Cc: Wu Bo, linfeilong, linux-kernel, linux-crypto, linux-fsdevel, davem, herbert, viro On Tue, May 25, 2021 at 10:37:44AM +0200, Christophe Leroy wrote: > Wu Bo <wubo40@huawei.com> a écrit : > > > From: Wu Bo <wubo40@huawei.com> > > > > Replace open coded divisor calculations with the DIV_ROUND_UP kernel > > macro for better readability. > > > > Signed-off-by: Wu Bo <wubo40@huawei.com> > > --- > > crypto/af_alg.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/crypto/af_alg.c b/crypto/af_alg.c > > index 18cc82d..8bd288d 100644 > > --- a/crypto/af_alg.c > > +++ b/crypto/af_alg.c > > @@ -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() 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. -- Dave Chinner david@fromorbit.com ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] crypto: af_alg - use DIV_ROUND_UP helper macro for calculations 2021-05-25 8:15 ` [PATCH 1/2] crypto: af_alg - " Wu Bo 2021-05-25 8:37 ` Christophe Leroy @ 2021-06-03 12:30 ` Herbert Xu 1 sibling, 0 replies; 8+ messages in thread From: Herbert Xu @ 2021-06-03 12:30 UTC (permalink / raw) To: Wu Bo; +Cc: viro, davem, linux-fsdevel, linux-crypto, linux-kernel, linfeilong On Tue, May 25, 2021 at 04:15:19PM +0800, Wu Bo wrote: > From: Wu Bo <wubo40@huawei.com> > > Replace open coded divisor calculations with the DIV_ROUND_UP kernel > macro for better readability. > > Signed-off-by: Wu Bo <wubo40@huawei.com> > --- > crypto/af_alg.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Patch applied. Thanks. -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] fs: direct-io: use DIV_ROUND_UP helper macro for calculations 2021-05-25 8:15 [PATCH 0/2] use DIV_ROUND_UP helper macro for calculations Wu Bo 2021-05-25 8:15 ` [PATCH 1/2] crypto: af_alg - " Wu Bo @ 2021-05-25 8:15 ` Wu Bo 2021-05-25 8:38 ` Christophe Leroy 2021-05-25 8:41 ` [PATCH 0/2] " Christophe Leroy 2 siblings, 1 reply; 8+ messages in thread From: Wu Bo @ 2021-05-25 8:15 UTC (permalink / raw) To: viro, herbert, davem, linux-fsdevel, linux-crypto, linux-kernel Cc: linfeilong, wubo40 From: Wu Bo <wubo40@huawei.com> Replace open coded divisor calculations with the DIV_ROUND_UP kernel macro for better readability. Signed-off-by: Wu Bo <wubo40@huawei.com> --- fs/direct-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/direct-io.c b/fs/direct-io.c index b2e86e7..6e7d402 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -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; } -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] fs: direct-io: use DIV_ROUND_UP helper macro for calculations 2021-05-25 8:15 ` [PATCH 2/2] fs: direct-io: " Wu Bo @ 2021-05-25 8:38 ` Christophe Leroy 0 siblings, 0 replies; 8+ messages in thread From: Christophe Leroy @ 2021-05-25 8:38 UTC (permalink / raw) To: Wu Bo Cc: linfeilong, linux-kernel, linux-crypto, linux-fsdevel, davem, herbert, viro Wu Bo <wubo40@huawei.com> a écrit : > From: Wu Bo <wubo40@huawei.com> > > Replace open coded divisor calculations with the DIV_ROUND_UP kernel > macro for better readability. > > Signed-off-by: Wu Bo <wubo40@huawei.com> > --- > fs/direct-io.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/direct-io.c b/fs/direct-io.c > index b2e86e7..6e7d402 100644 > --- a/fs/direct-io.c > +++ b/fs/direct-io.c > @@ -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. > sdio->to = ((ret - 1) & (PAGE_SIZE - 1)) + 1; > return 0; > } > -- > 1.8.3.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/2] use DIV_ROUND_UP helper macro for calculations 2021-05-25 8:15 [PATCH 0/2] use DIV_ROUND_UP helper macro for calculations Wu Bo 2021-05-25 8:15 ` [PATCH 1/2] crypto: af_alg - " Wu Bo 2021-05-25 8:15 ` [PATCH 2/2] fs: direct-io: " Wu Bo @ 2021-05-25 8:41 ` Christophe Leroy 2 siblings, 0 replies; 8+ messages in thread From: Christophe Leroy @ 2021-05-25 8:41 UTC (permalink / raw) To: Wu Bo Cc: linfeilong, linux-kernel, linux-crypto, linux-fsdevel, davem, herbert, viro Wu Bo <wubo40@huawei.com> a écrit : > This patchset is replace open coded divisor calculations with the > DIV_ROUND_UP kernel 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. > > 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(-) > > -- > 1.8.3.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-06-03 12:30 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-05-25 8:15 [PATCH 0/2] use DIV_ROUND_UP helper macro for calculations Wu Bo 2021-05-25 8:15 ` [PATCH 1/2] crypto: af_alg - " Wu Bo 2021-05-25 8:37 ` Christophe Leroy 2021-05-26 8:31 ` Dave Chinner 2021-06-03 12:30 ` Herbert Xu 2021-05-25 8:15 ` [PATCH 2/2] fs: direct-io: " Wu Bo 2021-05-25 8:38 ` Christophe Leroy 2021-05-25 8:41 ` [PATCH 0/2] " Christophe Leroy
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.