ALSA: pcm: Fix error checks of default read/write copy ops
authorTakashi Iwai <tiwai@suse.de>
Sat, 2 Sep 2023 06:10:43 +0000 (08:10 +0200)
committerTakashi Iwai <tiwai@suse.de>
Sat, 2 Sep 2023 06:11:48 +0000 (08:11 +0200)
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>
sound/core/pcm_lib.c

index 4859fb1..a11cd7d 100644 (file)
@@ -1992,8 +1992,8 @@ static int default_write_copy(struct snd_pcm_substream *substream,
                              int channel, unsigned long hwoff,
                              struct iov_iter *iter, unsigned long bytes)
 {
-       if (!copy_from_iter(get_dma_ptr(substream->runtime, channel, hwoff),
-                           bytes, iter))
+       if (copy_from_iter(get_dma_ptr(substream->runtime, channel, hwoff),
+                          bytes, iter) != bytes)
                return -EFAULT;
        return 0;
 }
@@ -2025,8 +2025,8 @@ static int default_read_copy(struct snd_pcm_substream *substream,
                             int channel, unsigned long hwoff,
                             struct iov_iter *iter, unsigned long bytes)
 {
-       if (!copy_to_iter(get_dma_ptr(substream->runtime, channel, hwoff),
-                         bytes, iter))
+       if (copy_to_iter(get_dma_ptr(substream->runtime, channel, hwoff),
+                        bytes, iter) != bytes)
                return -EFAULT;
        return 0;
 }