new helper: copy_to_iter_full()
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 7 Apr 2024 06:42:36 +0000 (02:42 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 7 Apr 2024 06:42:36 +0000 (02:42 -0400)
... and convert copy_linear_skb() to using that.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
include/linux/uio.h
include/net/udp.h

index 00cebe2b70de7ef3d74c814d4c59b4539c3d55da..7020adedfa08cf1c551bf6396b47830b65946368 100644 (file)
@@ -205,6 +205,16 @@ size_t copy_from_iter(void *addr, size_t bytes, struct iov_iter *i)
        return 0;
 }
 
+static __always_inline __must_check
+bool copy_to_iter_full(const void *addr, size_t bytes, struct iov_iter *i)
+{
+       size_t copied = copy_to_iter(addr, bytes, i);
+       if (likely(copied == bytes))
+               return true;
+       iov_iter_revert(i, copied);
+       return false;
+}
+
 static __always_inline __must_check
 bool copy_from_iter_full(void *addr, size_t bytes, struct iov_iter *i)
 {
index 488a6d2babccf26edfbaecc525f25e03d86b7d62..c4e05b14b648a4a98b67a8da5ed1e29f2413f35c 100644 (file)
@@ -379,14 +379,7 @@ static inline bool udp_skb_is_linear(struct sk_buff *skb)
 static inline int copy_linear_skb(struct sk_buff *skb, int len, int off,
                                  struct iov_iter *to)
 {
-       int n;
-
-       n = copy_to_iter(skb->data + off, len, to);
-       if (n == len)
-               return 0;
-
-       iov_iter_revert(to, n);
-       return -EFAULT;
+       return copy_to_iter_full(skb->data + off, len, to) ? 0 : -EFAULT;
 }
 
 /*