Skip to content

Commit b2de525

Browse files
David JefferyAl Viro
authored andcommitted
Return short read or 0 at end of a raw device, not EIO
Author: David Jeffery <djeffery@redhat.com> Changes to the basic direct I/O code have broken the raw driver when reading to the end of a raw device. Instead of returning a short read for a read that extends partially beyond the device's end or 0 when at the end of the device, these reads now return EIO. The raw driver needs the same end of device handling as was added for normal block devices. Using blkdev_read_iter, which has the needed size checks, prevents the EIO conditions at the end of the device. Signed-off-by: David Jeffery <djeffery@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent b0afd8e commit b2de525

3 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎drivers/char/raw.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static long raw_ctl_compat_ioctl(struct file *file, unsigned int cmd,
285285

286286
static const struct file_operations raw_fops = {
287287
.read = new_sync_read,
288-
.read_iter = generic_file_read_iter,
288+
.read_iter = blkdev_read_iter,
289289
.write = new_sync_write,
290290
.write_iter = blkdev_write_iter,
291291
.fsync = blkdev_fsync,

‎fs/block_dev.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@ ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
15851585
}
15861586
EXPORT_SYMBOL_GPL(blkdev_write_iter);
15871587

1588-
static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
1588+
ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
15891589
{
15901590
struct file *file = iocb->ki_filp;
15911591
struct inode *bd_inode = file->f_mapping->host;
@@ -1599,6 +1599,7 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
15991599
iov_iter_truncate(to, size);
16001600
return generic_file_read_iter(iocb, to);
16011601
}
1602+
EXPORT_SYMBOL_GPL(blkdev_read_iter);
16021603

16031604
/*
16041605
* Try to release a page associated with block device when the system

‎include/linux/fs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,7 @@ extern ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, lo
24692469
extern ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos);
24702470

24712471
/* fs/block_dev.c */
2472+
extern ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to);
24722473
extern ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from);
24732474
extern int blkdev_fsync(struct file *filp, loff_t start, loff_t end,
24742475
int datasync);

0 commit comments

Comments
 (0)