summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2021-04-25 23:57:42 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2021-06-10 11:45:16 -0400
commit5c67aa90cd5c59912ee71cff879e8f1ab237ad88 (patch)
tree35bd0d1b879a3ee9113372a5397143ab82209a25 /lib
parent7a1bcb5d255d4fd8b9725c3cf7ee0880a6369d2f (diff)
downloadlinux-5c67aa90cd5c59912ee71cff879e8f1ab237ad88.tar.gz
linux-5c67aa90cd5c59912ee71cff879e8f1ab237ad88.tar.bz2
linux-5c67aa90cd5c59912ee71cff879e8f1ab237ad88.zip
iov_iter: unify iterate_iovec and iterate_kvec
The differences between iterate_iovec and iterate_kvec are minor: * kvec callback is treated as if it returned 0 * initialization of __p is with i->iov and i->kvec resp. which is trivially dealt with. No code generation changes - compiler is quite capable of turning left = ((void)(STEP), 0); __v.iov_len -= left; (with no accesses to left downstream) and (void)(STEP); into the same code. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'lib')
-rw-r--r--lib/iov_iter.c28
1 files changed, 5 insertions, 23 deletions
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 2098059da64c..fc071d7b4528 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -16,10 +16,10 @@
#define PIPE_PARANOIA /* for now */
+/* covers iovec and kvec alike */
#define iterate_iovec(i, n, __v, __p, skip, STEP) { \
size_t left; \
size_t wanted = n; \
- __p = i->iov; \
do { \
__v.iov_len = min(n, __p->iov_len - skip); \
if (likely(__v.iov_len)) { \
@@ -37,25 +37,6 @@
n = wanted - n; \
}
-#define iterate_kvec(i, n, __v, __p, skip, STEP) { \
- size_t wanted = n; \
- __p = i->kvec; \
- do { \
- __v.iov_len = min(n, __p->iov_len - skip); \
- if (likely(__v.iov_len)) { \
- __v.iov_base = __p->iov_base + skip; \
- (void)(STEP); \
- skip += __v.iov_len; \
- n -= __v.iov_len; \
- if (skip < __p->iov_len) \
- break; \
- } \
- __p++; \
- skip = 0; \
- } while (n); \
- n = wanted - n; \
-}
-
#define iterate_bvec(i, n, __v, __bi, skip, STEP) { \
struct bvec_iter __start; \
__start.bi_size = n; \
@@ -109,7 +90,7 @@
if (likely(n)) { \
size_t skip = i->iov_offset; \
if (likely(iter_is_iovec(i))) { \
- const struct iovec *iov; \
+ const struct iovec *iov = i->iov; \
struct iovec v; \
iterate_iovec(i, n, v, iov, skip, (I)) \
i->nr_segs -= iov - i->iov; \
@@ -123,9 +104,10 @@
i->nr_segs -= i->bvec - bvec; \
skip = __bi.bi_bvec_done; \
} else if (iov_iter_is_kvec(i)) { \
- const struct kvec *kvec; \
+ const struct kvec *kvec = i->kvec; \
struct kvec v; \
- iterate_kvec(i, n, v, kvec, skip, (K)) \
+ iterate_iovec(i, n, v, kvec, skip, \
+ ((void)(K),0)) \
i->nr_segs -= kvec - i->kvec; \
i->kvec = kvec; \
} else if (iov_iter_is_xarray(i)) { \