lkml.org 
[lkml]   [2021]   [Jun]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[RFC PATCH 19/37] [xarray] iov_iter_npages(): just use DIV_ROUND_UP()
    Date
    Compiler is capable of recognizing division by power of 2 and turning
    it into shifts.

    Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
    ---
    lib/iov_iter.c | 16 ++--------------
    1 file changed, 2 insertions(+), 14 deletions(-)

    diff --git a/lib/iov_iter.c b/lib/iov_iter.c
    index 04c81481d309..6a968d2ff081 100644
    --- a/lib/iov_iter.c
    +++ b/lib/iov_iter.c
    @@ -1938,20 +1938,8 @@ int iov_iter_npages(const struct iov_iter *i, int maxpages)
    return min(npages, maxpages);
    }
    if (iov_iter_is_xarray(i)) {
    - size_t size = i->count;
    - unsigned offset;
    - int npages;
    -
    - offset = (i->xarray_start + i->iov_offset) & ~PAGE_MASK;
    -
    - npages = 1;
    - if (size > PAGE_SIZE - offset) {
    - size -= PAGE_SIZE - offset;
    - npages += size >> PAGE_SHIFT;
    - size &= ~PAGE_MASK;
    - if (size)
    - npages++;
    - }
    + unsigned offset = (i->xarray_start + i->iov_offset) % PAGE_SIZE;
    + int npages = DIV_ROUND_UP(offset + i->count, PAGE_SIZE);
    return min(npages, maxpages);
    }
    return 0;
    --
    2.11.0
    \
     
     \ /
      Last update: 2021-06-06 21:12    [W:4.179 / U:0.732 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site