pull handling of ->iov_offset into iterate_{iovec,bvec,xarray}
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 2 May 2021 17:03:41 +0000 (13:03 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Thu, 10 Jun 2021 15:45:20 +0000 (11:45 -0400)
fewer arguments (by one, but still...) for iterate_...() macros

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
lib/iov_iter.c

index f4ea04e..48a55de 100644 (file)
@@ -17,8 +17,9 @@
 #define PIPE_PARANOIA /* for now */
 
 /* covers iovec and kvec alike */
-#define iterate_iovec(i, n, base, len, off, __p, skip, STEP) { \
+#define iterate_iovec(i, n, base, len, off, __p, STEP) {       \
        size_t off = 0;                                         \
+       size_t skip = i->iov_offset;                            \
        do {                                                    \
                len = min(n, __p->iov_len - skip);              \
                if (likely(len)) {                              \
                __p++;                                          \
                skip = 0;                                       \
        } while (n);                                            \
+       i->iov_offset = skip;                                   \
        n = off;                                                \
 }
 
-#define iterate_bvec(i, n, base, len, off, p, skip, STEP) {    \
+#define iterate_bvec(i, n, base, len, off, p, STEP) {          \
        size_t off = 0;                                         \
+       unsigned skip = i->iov_offset;                          \
        while (n) {                                             \
                unsigned offset = p->bv_offset + skip;          \
                unsigned left;                                  \
                void *kaddr = kmap_local_page(p->bv_page +      \
                                        offset / PAGE_SIZE);    \
                base = kaddr + offset % PAGE_SIZE;              \
-               len = min(min(n, p->bv_len - skip),             \
+               len = min(min(n, (size_t)(p->bv_len - skip)),   \
                     (size_t)(PAGE_SIZE - offset % PAGE_SIZE)); \
                left = (STEP);                                  \
                kunmap_local(kaddr);                            \
                if (left)                                       \
                        break;                                  \
        }                                                       \
+       i->iov_offset = skip;                                   \
        n = off;                                                \
 }
 
-#define iterate_xarray(i, n, base, len, __off, skip, STEP) {   \
+#define iterate_xarray(i, n, base, len, __off, STEP) {         \
        __label__ __out;                                        \
        size_t __off = 0;                                       \
        struct page *head = NULL;                               \
        size_t offset;                                          \
-       loff_t start = i->xarray_start + skip;                  \
+       loff_t start = i->xarray_start + i->iov_offset;         \
        pgoff_t index = start >> PAGE_SHIFT;                    \
        int j;                                                  \
                                                                \
        }                                                       \
 __out:                                                         \
        rcu_read_unlock();                                      \
-       skip += __off;                                          \
+       i->iov_offset += __off;                                         \
        n = __off;                                              \
 }
 
@@ -108,13 +112,12 @@ __out:                                                            \
        if (unlikely(i->count < n))                             \
                n = i->count;                                   \
        if (likely(n)) {                                        \
-               size_t skip = i->iov_offset;                    \
                if (likely(iter_is_iovec(i))) {                 \
                        const struct iovec *iov = i->iov;       \
                        void __user *base;                      \
                        size_t len;                             \
                        iterate_iovec(i, n, base, len, off,     \
-                                               iov, skip, (I)) \
+                                               iov, (I))       \
                        i->nr_segs -= iov - i->iov;             \
                        i->iov = iov;                           \
                } else if (iov_iter_is_bvec(i)) {               \
@@ -122,7 +125,7 @@ __out:                                                              \
                        void *base;                             \
                        size_t len;                             \
                        iterate_bvec(i, n, base, len, off,      \
-                                       bvec, skip, (K))        \
+                                               bvec, (K))      \
                        i->nr_segs -= bvec - i->bvec;           \
                        i->bvec = bvec;                         \
                } else if (iov_iter_is_kvec(i)) {               \
@@ -130,17 +133,16 @@ __out:                                                            \
                        void *base;                             \
                        size_t len;                             \
                        iterate_iovec(i, n, base, len, off,     \
-                                       kvec, skip, (K))        \
+                                               kvec, (K))      \
                        i->nr_segs -= kvec - i->kvec;           \
                        i->kvec = kvec;                         \
                } else if (iov_iter_is_xarray(i)) {             \
                        void *base;                             \
                        size_t len;                             \
                        iterate_xarray(i, n, base, len, off,    \
-                                               skip, (K))      \
+                                                       (K))    \
                }                                               \
                i->count -= n;                                  \
-               i->iov_offset = skip;                           \
        }                                                       \
 }
 #define iterate_and_advance(i, n, base, len, off, I, K) \