Commit 610c7a71 authored by Al Viro's avatar Al Viro

iov_iter_gap_alignment(): get rid of iterate_all_kinds()

For one thing, it's only used for iovec (and makes sense only for those).
For another, here we don't care about iov_offset, since the beginning of
the first segment and the end of the last one are ignored.  So it makes
a lot more sense to just walk through the iovec array...

We need to deal with the case of truncated iov_iter, but unlike the
situation with iov_iter_alignment() we don't care where the last
segment ends - just which segment is the last one.

[fixed a braino spotted by Qian Cai <quic_qiancai@quicinc.com>]
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 9221d2e3
...@@ -1398,23 +1398,24 @@ EXPORT_SYMBOL(iov_iter_alignment); ...@@ -1398,23 +1398,24 @@ EXPORT_SYMBOL(iov_iter_alignment);
unsigned long iov_iter_gap_alignment(const struct iov_iter *i) unsigned long iov_iter_gap_alignment(const struct iov_iter *i)
{ {
unsigned long res = 0; unsigned long res = 0;
unsigned long v = 0;
size_t size = i->count; size_t size = i->count;
unsigned k;
if (unlikely(iov_iter_is_pipe(i) || iov_iter_is_discard(i))) { if (WARN_ON(!iter_is_iovec(i)))
WARN_ON(1);
return ~0U; return ~0U;
}
iterate_all_kinds(i, size, v, for (k = 0; k < i->nr_segs; k++) {
(res |= (!res ? 0 : (unsigned long)v.iov_base) | if (i->iov[k].iov_len) {
(size != v.iov_len ? size : 0), 0), unsigned long base = (unsigned long)i->iov[k].iov_base;
(res |= (!res ? 0 : (unsigned long)v.bv_offset) | if (v) // if not the first one
(size != v.bv_len ? size : 0)), res |= base | v; // this start | previous end
(res |= (!res ? 0 : (unsigned long)v.iov_base) | v = base + i->iov[k].iov_len;
(size != v.iov_len ? size : 0)), if (size <= i->iov[k].iov_len)
(res |= (!res ? 0 : (unsigned long)v.bv_offset) | break;
(size != v.bv_len ? size : 0)) size -= i->iov[k].iov_len;
); }
}
return res; return res;
} }
EXPORT_SYMBOL(iov_iter_gap_alignment); EXPORT_SYMBOL(iov_iter_gap_alignment);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment