Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: pcm: Fix error checks of default read/write copy ops

copy_from/to_iter() returns the actually copied bytes, and the more
correct check should be to compare with the given bytes, instead of
zero-check.

Fixes: cf393babb37a ("ALSA: pcm: Add copy ops with iov_iter")
Reported-by: Al Viro <viro@zeniv.linux.org.uk>
Closes: https://lore.kernel.org/r/20230902053044.GJ3390869@ZenIV
Link: https://lore.kernel.org/r/20230902061044.19366-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+4 -4
+4 -4
sound/core/pcm_lib.c
··· 1992 1992 int channel, unsigned long hwoff, 1993 1993 struct iov_iter *iter, unsigned long bytes) 1994 1994 { 1995 - if (!copy_from_iter(get_dma_ptr(substream->runtime, channel, hwoff), 1996 - bytes, iter)) 1995 + if (copy_from_iter(get_dma_ptr(substream->runtime, channel, hwoff), 1996 + bytes, iter) != bytes) 1997 1997 return -EFAULT; 1998 1998 return 0; 1999 1999 } ··· 2025 2025 int channel, unsigned long hwoff, 2026 2026 struct iov_iter *iter, unsigned long bytes) 2027 2027 { 2028 - if (!copy_to_iter(get_dma_ptr(substream->runtime, channel, hwoff), 2029 - bytes, iter)) 2028 + if (copy_to_iter(get_dma_ptr(substream->runtime, channel, hwoff), 2029 + bytes, iter) != bytes) 2030 2030 return -EFAULT; 2031 2031 return 0; 2032 2032 }