9p: fix return code of read() when count is 0
authorVincent Bernat <vincent@bernat.im>
Sat, 15 Aug 2015 12:07:44 +0000 (14:07 +0200)
committerEric Van Hensbergen <ericvh@gmail.com>
Sun, 23 Aug 2015 19:21:36 +0000 (14:21 -0500)
When reading 0 bytes from an empty file on a 9P filesystem, the return
code of read() was not 0 as expected due to an unitialized err variable.

Tested with this simple program:

    #include <assert.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <unistd.h>

    int main(int argc, const char **argv)
    {
        assert(argc == 2);
        char buffer[256];
        int fd = open(argv[1], O_RDONLY|O_NOCTTY);
        assert(fd >= 0);
        assert(read(fd, buffer, 0) == 0);
        return 0;
    }

Signed-off-by: Vincent Bernat <vincent@bernat.im>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
fs/9p/vfs_file.c

index 1ef16bd..3abc447 100644 (file)
@@ -381,7 +381,7 @@ static ssize_t
 v9fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
 {
        struct p9_fid *fid = iocb->ki_filp->private_data;
-       int ret, err;
+       int ret, err = 0;
 
        p9_debug(P9_DEBUG_VFS, "count %zu offset %lld\n",
                 iov_iter_count(to), iocb->ki_pos);