Skip to content

Commit ab04de8

Browse files
Christoph Hellwiggregkh
authored andcommitted
/dev/zero: fixups for ->read
Reported the cleared bytes in case of a partial clear_user instead of -EFAULT, and remove a pointless conditional, as cleared must be non-zero by the time we hit the signal_pending check. Reported-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20200907082700.2057137-1-hch@lst.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 947bece commit ab04de8

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎drivers/char/mem.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,14 +733,20 @@ static ssize_t read_zero(struct file *file, char __user *buf,
733733

734734
while (count) {
735735
size_t chunk = min_t(size_t, count, PAGE_SIZE);
736+
size_t left;
736737

737-
if (clear_user(buf + cleared, chunk))
738-
return cleared ? cleared : -EFAULT;
738+
left = clear_user(buf + cleared, chunk);
739+
if (unlikely(left)) {
740+
cleared += (chunk - left);
741+
if (!cleared)
742+
return -EFAULT;
743+
break;
744+
}
739745
cleared += chunk;
740746
count -= chunk;
741747

742748
if (signal_pending(current))
743-
return cleared ? cleared : -ERESTARTSYS;
749+
break;
744750
cond_resched();
745751
}
746752

0 commit comments

Comments
 (0)