]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - lib/iov_iter.c
Merge branch 'for-rc' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux
[karo-tx-linux.git] / lib / iov_iter.c
index 7312e7784611d7c56b6c154a2c2bb9975142792b..f2bd21b93dfca464ae24bb18c6492bd8c7f1eb88 100644 (file)
@@ -683,10 +683,11 @@ static void pipe_advance(struct iov_iter *i, size_t size)
        struct pipe_inode_info *pipe = i->pipe;
        struct pipe_buffer *buf;
        int idx = i->idx;
-       size_t off = i->iov_offset;
+       size_t off = i->iov_offset, orig_sz;
        
        if (unlikely(i->count < size))
                size = i->count;
+       orig_sz = size;
 
        if (size) {
                if (off) /* make it relative to the beginning of buffer */
@@ -713,6 +714,7 @@ static void pipe_advance(struct iov_iter *i, size_t size)
                        pipe->nrbufs--;
                }
        }
+       i->count -= orig_sz;
 }
 
 void iov_iter_advance(struct iov_iter *i, size_t size)
@@ -1139,6 +1141,28 @@ const void *dup_iter(struct iov_iter *new, struct iov_iter *old, gfp_t flags)
 }
 EXPORT_SYMBOL(dup_iter);
 
+/**
+ * import_iovec() - Copy an array of &struct iovec from userspace
+ *     into the kernel, check that it is valid, and initialize a new
+ *     &struct iov_iter iterator to access it.
+ *
+ * @type: One of %READ or %WRITE.
+ * @uvector: Pointer to the userspace array.
+ * @nr_segs: Number of elements in userspace array.
+ * @fast_segs: Number of elements in @iov.
+ * @iov: (input and output parameter) Pointer to pointer to (usually small
+ *     on-stack) kernel array.
+ * @i: Pointer to iterator that will be initialized on success.
+ *
+ * If the array pointed to by *@iov is large enough to hold all @nr_segs,
+ * then this function places %NULL in *@iov on return. Otherwise, a new
+ * array will be allocated and the result placed in *@iov. This means that
+ * the caller may call kfree() on *@iov regardless of whether the small
+ * on-stack array was used or not (and regardless of whether this function
+ * returns an error or not).
+ *
+ * Return: 0 on success or negative error code on error.
+ */
 int import_iovec(int type, const struct iovec __user * uvector,
                 unsigned nr_segs, unsigned fast_segs,
                 struct iovec **iov, struct iov_iter *i)