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

ALSA: korg1212: Convert to generic PCM copy ops

This patch converts the korg1212 driver code to use the new unified
PCM copy callback. The open-coded conditional memory copies are
replaced with simpler copy_from/to_iter() calls.

Note that copy_from/to_iter() returns the copied bytes, hence the
error condition is adjusted accordingly.

Link: https://lore.kernel.org/r/20230815190136.8987-9-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+12 -38
+12 -38
sound/pci/korg1212/korg1212.c
··· 1285 1285 } 1286 1286 1287 1287 static int snd_korg1212_copy_to(struct snd_pcm_substream *substream, 1288 - void __user *dst, int pos, int count, 1289 - bool in_kernel) 1288 + struct iov_iter *dst, int pos, int count) 1290 1289 { 1291 1290 struct snd_pcm_runtime *runtime = substream->runtime; 1292 1291 struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); ··· 1305 1306 #if K1212_DEBUG_LEVEL > 0 1306 1307 if ( (void *) src < (void *) korg1212->recordDataBufsPtr || 1307 1308 (void *) src > (void *) korg1212->recordDataBufsPtr[8].bufferData ) { 1308 - printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i); 1309 + printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst->kvec.iov_base, i); 1309 1310 return -EFAULT; 1310 1311 } 1311 1312 #endif 1312 - if (in_kernel) 1313 - memcpy((__force void *)dst, src, size); 1314 - else if (copy_to_user(dst, src, size)) 1313 + if (copy_to_iter(src, size, dst) != size) 1315 1314 return -EFAULT; 1316 1315 src++; 1317 - dst += size; 1318 1316 } 1319 1317 1320 1318 return 0; 1321 1319 } 1322 1320 1323 1321 static int snd_korg1212_copy_from(struct snd_pcm_substream *substream, 1324 - void __user *src, int pos, int count, 1325 - bool in_kernel) 1322 + struct iov_iter *src, int pos, int count) 1326 1323 { 1327 1324 struct snd_pcm_runtime *runtime = substream->runtime; 1328 1325 struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); ··· 1340 1345 #if K1212_DEBUG_LEVEL > 0 1341 1346 if ( (void *) dst < (void *) korg1212->playDataBufsPtr || 1342 1347 (void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) { 1343 - printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, src=%p dst=%p iter=%d\n", src, dst, i); 1348 + printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, src=%p dst=%p iter=%d\n", src->kvec.iov_base, dst, i); 1344 1349 return -EFAULT; 1345 1350 } 1346 1351 #endif 1347 - if (in_kernel) 1348 - memcpy(dst, (__force void *)src, size); 1349 - else if (copy_from_user(dst, src, size)) 1352 + if (copy_from_iter(dst, size, src) != size) 1350 1353 return -EFAULT; 1351 1354 dst++; 1352 - src += size; 1353 1355 } 1354 1356 1355 1357 return 0; ··· 1634 1642 1635 1643 static int snd_korg1212_playback_copy(struct snd_pcm_substream *substream, 1636 1644 int channel, unsigned long pos, 1637 - void __user *src, unsigned long count) 1645 + struct iov_iter *src, unsigned long count) 1638 1646 { 1639 - return snd_korg1212_copy_from(substream, src, pos, count, false); 1640 - } 1641 - 1642 - static int snd_korg1212_playback_copy_kernel(struct snd_pcm_substream *substream, 1643 - int channel, unsigned long pos, 1644 - void *src, unsigned long count) 1645 - { 1646 - return snd_korg1212_copy_from(substream, (void __user *)src, 1647 - pos, count, true); 1647 + return snd_korg1212_copy_from(substream, src, pos, count); 1648 1648 } 1649 1649 1650 1650 static int snd_korg1212_playback_silence(struct snd_pcm_substream *substream, ··· 1654 1670 1655 1671 static int snd_korg1212_capture_copy(struct snd_pcm_substream *substream, 1656 1672 int channel, unsigned long pos, 1657 - void __user *dst, unsigned long count) 1673 + struct iov_iter *dst, unsigned long count) 1658 1674 { 1659 - return snd_korg1212_copy_to(substream, dst, pos, count, false); 1660 - } 1661 - 1662 - static int snd_korg1212_capture_copy_kernel(struct snd_pcm_substream *substream, 1663 - int channel, unsigned long pos, 1664 - void *dst, unsigned long count) 1665 - { 1666 - return snd_korg1212_copy_to(substream, (void __user *)dst, 1667 - pos, count, true); 1675 + return snd_korg1212_copy_to(substream, dst, pos, count); 1668 1676 } 1669 1677 1670 1678 static const struct snd_pcm_ops snd_korg1212_playback_ops = { ··· 1667 1691 .prepare = snd_korg1212_prepare, 1668 1692 .trigger = snd_korg1212_trigger, 1669 1693 .pointer = snd_korg1212_playback_pointer, 1670 - .copy_user = snd_korg1212_playback_copy, 1671 - .copy_kernel = snd_korg1212_playback_copy_kernel, 1694 + .copy = snd_korg1212_playback_copy, 1672 1695 .fill_silence = snd_korg1212_playback_silence, 1673 1696 }; 1674 1697 ··· 1679 1704 .prepare = snd_korg1212_prepare, 1680 1705 .trigger = snd_korg1212_trigger, 1681 1706 .pointer = snd_korg1212_capture_pointer, 1682 - .copy_user = snd_korg1212_capture_copy, 1683 - .copy_kernel = snd_korg1212_capture_copy_kernel, 1707 + .copy = snd_korg1212_capture_copy, 1684 1708 }; 1685 1709 1686 1710 /*