From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66E7DC04A6A for ; Tue, 15 Aug 2023 19:02:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239472AbjHOTCR (ORCPT ); Tue, 15 Aug 2023 15:02:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239759AbjHOTCM (ORCPT ); Tue, 15 Aug 2023 15:02:12 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11D88213A for ; Tue, 15 Aug 2023 12:01:50 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 54254211C2; Tue, 15 Aug 2023 19:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126107; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jL1kZwcY6dMGheLY8VT1W4i0RrpIBAIOY7mmAx3IYPo=; b=U0X1AgYfraeXpvSANmhqdI7y2OkQ2UGIwcVOzfcm/4PdYBALruX+lRci8AHZZJT5xfnCiw Rq/leeZlmplImx0Gfb4IuCNEf1HduS/gLJSTJV3ws+ITLCn5hyV0hdxvDEnSgXDCertqKd RDAGtXlAcYho/A2L3BMbJrOlxtTgXeM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126107; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jL1kZwcY6dMGheLY8VT1W4i0RrpIBAIOY7mmAx3IYPo=; b=+TU5ZXj5De1Bwf8O1Mw0fmUPyyUx62ZWZTkuT1FEmBwy51vPvohgM1zBdg9+Njv67ADUf6 3Jg43Eu1NUlI1FAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 32F511390C; Tue, 15 Aug 2023 19:01:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0PykC5vL22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:47 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai , Alexander Viro Subject: [PATCH v2 01/25] iov_iter: Export import_ubuf() Date: Tue, 15 Aug 2023 21:01:12 +0200 Message-Id: <20230815190136.8987-2-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Export import_ubuf() to be used in sound subsystem for generic memory handling as Linus suggested. It's used for constructing an iov_iter of a single segment user-space copy for PCM data. Cc: Alexander Viro Link: https://lore.kernel.org/r/CAHk-=3Dwh-mUL6mp4chAc6E_UjwpPLyCPRCJK+iB4Z= MD2BqjwGHA@mail.gmail.com Signed-off-by: Takashi Iwai --- lib/iov_iter.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index e4dc809d1075..3743bbcbbb89 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1544,6 +1544,7 @@ int import_ubuf(int rw, void __user *buf, size_t len,= struct iov_iter *i) iov_iter_ubuf(i, rw, buf, len); return 0; } +EXPORT_SYMBOL_GPL(import_ubuf); =20 /** * iov_iter_restore() - Restore a &struct iov_iter to the same state as wh= en --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E36EC04FE1 for ; Tue, 15 Aug 2023 19:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239740AbjHOTC6 (ORCPT ); Tue, 15 Aug 2023 15:02:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239810AbjHOTCo (ORCPT ); Tue, 15 Aug 2023 15:02:44 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 063141FF0 for ; Tue, 15 Aug 2023 12:02:25 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7809F2199D; Tue, 15 Aug 2023 19:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126107; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PjigMRXLLwFiO9MVxJuREvNKaLKvWTiGPYNpYq6YtnM=; b=khwM0L4ITMnzxHfdV8TMUn4HhQTnWf3JOWqQbmhNVHaivDiyY+PkbKRLAIlu9yeATuvd6f owPw0Ky8sMBDGdJglgqsxlHkTBudGztgamlP/KRCiDjXOSAhjYdcSDElTO0A1zn95QxXGT 65uAwx6VqPBBFdEHwORuEtkMgdC1M7w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126107; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PjigMRXLLwFiO9MVxJuREvNKaLKvWTiGPYNpYq6YtnM=; b=0bZhnakDUVFS9Vr9FCG83A+jWSpr8bwbSy6vIAG1kcFrsvAe1cGLBSYe43fQQar3SyNs9K fbzc5MhsiSxNGvAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5A76B1353E; Tue, 15 Aug 2023 19:01:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id AE9aFZvL22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:47 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 02/25] ALSA: pcm: Add copy ops with iov_iter Date: Tue, 15 Aug 2023 21:01:13 +0200 Message-Id: <20230815190136.8987-3-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" iov_iter is a universal interface to copy the data chunk from/to user-space and kernel in a unified manner. This API can fit for ALSA PCM copy ops, too; we had to split to copy_user and copy_kernel in the past, and those can be unified to a single ops with iov_iter. This patch adds a new PCM copy ops that passes iov_iter for copying both kernel and user-space in the same way. This patch touches only the ALSA PCM core part, and the actual users will be replaced in the following patches. The expansion of iov_iter is done in the PCM core right before calling each copy callback. It's a bit suboptimal, but I took this now as it's the most straightforward replacement. The more conversion to iov_iter in the caller side is a TODO for future. As of now, the old copy_user and copy_kernel ops are still kept. Once after all users are converted, we'll drop the old copy_user and copy_kernel ops, too. Signed-off-by: Takashi Iwai --- include/sound/pcm.h | 3 ++ sound/core/pcm_lib.c | 111 ++++++++++++++++++++++++---------------- sound/core/pcm_native.c | 2 +- 3 files changed, 71 insertions(+), 45 deletions(-) diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 19f564606ac4..ff4a0c1c93a2 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -16,6 +16,7 @@ #include #include #include +#include =20 #define snd_pcm_substream_chip(substream) ((substream)->private_data) #define snd_pcm_chip(pcm) ((pcm)->private_data) @@ -68,6 +69,8 @@ struct snd_pcm_ops { struct snd_pcm_audio_tstamp_report *audio_tstamp_report); int (*fill_silence)(struct snd_pcm_substream *substream, int channel, unsigned long pos, unsigned long bytes); + int (*copy)(struct snd_pcm_substream *substream, int channel, + unsigned long pos, struct iov_iter *iter, unsigned long bytes); int (*copy_user)(struct snd_pcm_substream *substream, int channel, unsigned long pos, void __user *buf, unsigned long bytes); diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 9c121a921b04..3303914c58ea 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -1973,10 +1973,11 @@ static int wait_for_avail(struct snd_pcm_substream = *substream, =09 typedef int (*pcm_transfer_f)(struct snd_pcm_substream *substream, int channel, unsigned long hwoff, - void *buf, unsigned long bytes); + struct iov_iter *iter, unsigned long bytes); =20 typedef int (*pcm_copy_f)(struct snd_pcm_substream *, snd_pcm_uframes_t, v= oid *, - snd_pcm_uframes_t, snd_pcm_uframes_t, pcm_transfer_f); + snd_pcm_uframes_t, snd_pcm_uframes_t, pcm_transfer_f, + bool); =20 /* calculate the target DMA-buffer position to be written/read */ static void *get_dma_ptr(struct snd_pcm_runtime *runtime, @@ -1986,32 +1987,24 @@ static void *get_dma_ptr(struct snd_pcm_runtime *ru= ntime, channel * (runtime->dma_bytes / runtime->channels); } =20 -/* default copy_user ops for write; used for both interleaved and non- mod= es */ +/* default copy ops for write; used for both interleaved and non- modes */ static int default_write_copy(struct snd_pcm_substream *substream, int channel, unsigned long hwoff, - void *buf, unsigned long bytes) + struct iov_iter *iter, unsigned long bytes) { - if (copy_from_user(get_dma_ptr(substream->runtime, channel, hwoff), - (void __user *)buf, bytes)) + if (!copy_from_iter(get_dma_ptr(substream->runtime, channel, hwoff), + bytes, iter)) return -EFAULT; return 0; } =20 -/* default copy_kernel ops for write */ -static int default_write_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long hwoff, - void *buf, unsigned long bytes) -{ - memcpy(get_dma_ptr(substream->runtime, channel, hwoff), buf, bytes); - return 0; -} - /* fill silence instead of copy data; called as a transfer helper * from __snd_pcm_lib_write() or directly from noninterleaved_copy() when * a NULL buffer is passed */ static int fill_silence(struct snd_pcm_substream *substream, int channel, - unsigned long hwoff, void *buf, unsigned long bytes) + unsigned long hwoff, struct iov_iter *iter, + unsigned long bytes) { struct snd_pcm_runtime *runtime =3D substream->runtime; =20 @@ -2027,25 +2020,54 @@ static int fill_silence(struct snd_pcm_substream *s= ubstream, int channel, return 0; } =20 -/* default copy_user ops for read; used for both interleaved and non- mode= s */ +/* default copy ops for read; used for both interleaved and non- modes */ static int default_read_copy(struct snd_pcm_substream *substream, int channel, unsigned long hwoff, - void *buf, unsigned long bytes) + struct iov_iter *iter, unsigned long bytes) { - if (copy_to_user((void __user *)buf, - get_dma_ptr(substream->runtime, channel, hwoff), - bytes)) + if (!copy_to_iter(get_dma_ptr(substream->runtime, channel, hwoff), + bytes, iter)) return -EFAULT; return 0; } =20 -/* default copy_kernel ops for read */ -static int default_read_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long hwoff, - void *buf, unsigned long bytes) +/* a wrapper for calling old copy_kernel or copy_user ops */ +static int call_old_copy(struct snd_pcm_substream *substream, + int channel, unsigned long hwoff, + struct iov_iter *iter, unsigned long bytes) { - memcpy(buf, get_dma_ptr(substream->runtime, channel, hwoff), bytes); - return 0; + if (iov_iter_is_kvec(iter)) + return substream->ops->copy_kernel(substream, channel, hwoff, + iter_iov_addr(iter), bytes); + else + return substream->ops->copy_user(substream, channel, hwoff, + iter_iov_addr(iter), bytes); +} + +/* call transfer with the filled iov_iter */ +static int do_transfer(struct snd_pcm_substream *substream, int c, + unsigned long hwoff, void *data, unsigned long bytes, + pcm_transfer_f transfer, bool in_kernel) +{ + struct iov_iter iter; + int err, type; + + if (substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK) + type =3D ITER_SOURCE; + else + type =3D ITER_DEST; + + if (in_kernel) { + struct kvec kvec =3D { data, bytes }; + + iov_iter_kvec(&iter, type, &kvec, 1, bytes); + return transfer(substream, c, hwoff, &iter, bytes); + } + + err =3D import_ubuf(type, (__force void __user *)data, bytes, &iter); + if (err) + return err; + return transfer(substream, c, hwoff, &iter, bytes); } =20 /* call transfer function with the converted pointers and sizes; @@ -2055,7 +2077,8 @@ static int interleaved_copy(struct snd_pcm_substream = *substream, snd_pcm_uframes_t hwoff, void *data, snd_pcm_uframes_t off, snd_pcm_uframes_t frames, - pcm_transfer_f transfer) + pcm_transfer_f transfer, + bool in_kernel) { struct snd_pcm_runtime *runtime =3D substream->runtime; =20 @@ -2063,7 +2086,9 @@ static int interleaved_copy(struct snd_pcm_substream = *substream, hwoff =3D frames_to_bytes(runtime, hwoff); off =3D frames_to_bytes(runtime, off); frames =3D frames_to_bytes(runtime, frames); - return transfer(substream, 0, hwoff, data + off, frames); + + return do_transfer(substream, 0, hwoff, data + off, frames, transfer, + in_kernel); } =20 /* call transfer function with the converted pointers and sizes for each @@ -2073,7 +2098,8 @@ static int noninterleaved_copy(struct snd_pcm_substre= am *substream, snd_pcm_uframes_t hwoff, void *data, snd_pcm_uframes_t off, snd_pcm_uframes_t frames, - pcm_transfer_f transfer) + pcm_transfer_f transfer, + bool in_kernel) { struct snd_pcm_runtime *runtime =3D substream->runtime; int channels =3D runtime->channels; @@ -2091,8 +2117,8 @@ static int noninterleaved_copy(struct snd_pcm_substre= am *substream, if (!data || !*bufs) err =3D fill_silence(substream, c, hwoff, NULL, frames); else - err =3D transfer(substream, c, hwoff, *bufs + off, - frames); + err =3D do_transfer(substream, c, hwoff, *bufs + off, + frames, transfer, in_kernel); if (err < 0) return err; } @@ -2108,10 +2134,10 @@ static int fill_silence_frames(struct snd_pcm_subst= ream *substream, if (substream->runtime->access =3D=3D SNDRV_PCM_ACCESS_RW_INTERLEAVED || substream->runtime->access =3D=3D SNDRV_PCM_ACCESS_MMAP_INTERLEAVED) return interleaved_copy(substream, off, NULL, 0, frames, - fill_silence); + fill_silence, true); else return noninterleaved_copy(substream, off, NULL, 0, frames, - fill_silence); + fill_silence, true); } =20 /* sanity-check for read/write methods */ @@ -2121,7 +2147,7 @@ static int pcm_sanity_check(struct snd_pcm_substream = *substream) if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime =3D substream->runtime; - if (snd_BUG_ON(!substream->ops->copy_user && !runtime->dma_area)) + if (snd_BUG_ON(!substream->ops->copy && !substream->ops->copy_user && !ru= ntime->dma_area)) return -EINVAL; if (runtime->state =3D=3D SNDRV_PCM_STATE_OPEN) return -EBADFD; @@ -2226,15 +2252,12 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm= _substream *substream, transfer =3D fill_silence; else return -EINVAL; - } else if (in_kernel) { - if (substream->ops->copy_kernel) - transfer =3D substream->ops->copy_kernel; - else - transfer =3D is_playback ? - default_write_copy_kernel : default_read_copy_kernel; } else { - if (substream->ops->copy_user) - transfer =3D (pcm_transfer_f)substream->ops->copy_user; + if (substream->ops->copy) + transfer =3D substream->ops->copy; + else if ((in_kernel && substream->ops->copy_kernel) || + (!in_kernel && substream->ops->copy_user)) + transfer =3D call_old_copy; else transfer =3D is_playback ? default_write_copy : default_read_copy; @@ -2307,7 +2330,7 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_s= ubstream *substream, if (!is_playback) snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_CPU); err =3D writer(substream, appl_ofs, data, offset, frames, - transfer); + transfer, in_kernel); if (is_playback) snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE); snd_pcm_stream_lock_irq(substream); diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 95fc56e403b1..34efd4d198d6 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -809,7 +809,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *= substream, runtime->boundary *=3D 2; =20 /* clear the buffer for avoiding possible kernel info leaks */ - if (runtime->dma_area && !substream->ops->copy_user) { + if (runtime->dma_area && !substream->ops->copy && !substream->ops->copy_u= ser) { size_t size =3D runtime->dma_bytes; =20 if (runtime->info & SNDRV_PCM_INFO_MMAP) --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CC9BC07E8A for ; Tue, 15 Aug 2023 19:03:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239796AbjHOTDG (ORCPT ); Tue, 15 Aug 2023 15:03:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239808AbjHOTCo (ORCPT ); Tue, 15 Aug 2023 15:02:44 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B0EA1FF2 for ; Tue, 15 Aug 2023 12:02:25 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 99772219A1; Tue, 15 Aug 2023 19:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126107; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8RZMTb1rxLyBEVZU95vweXMEGYopGdvruEyyejDZppQ=; b=0Qp9+1vfiiYtF6EG6shZSaICf9cSAJgeWoeNg1/uvV9TI5PC+0YkHSexA4R/JrJw5Dr4d6 kL8ymL/yG7VOj0BrWNtqioIcg1k6k50qqi8+QrmauxiTRuOsV+zcC/U5iU3ZIIFK0JOhxK 8TaNg/FpdJYt+3mcxnqZRVlqgOz6cmY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126107; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8RZMTb1rxLyBEVZU95vweXMEGYopGdvruEyyejDZppQ=; b=8xWX4G98mxLuQSemC7ipDW41GHaHGhuB+4PV0tsFuRUW29LiE/O1xWbubCSP4tN5g/6VQb 72t94gOF0coOo7CA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7B97E1390C; Tue, 15 Aug 2023 19:01:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id eCdXHZvL22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:47 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 03/25] ALSA: core: Add memory copy helpers between iov_iter and iomem Date: Tue, 15 Aug 2023 21:01:14 +0200 Message-Id: <20230815190136.8987-4-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add two more helpers for copying memory between iov_iter and iomem, which will be used by the new PCM copy ops in a few drivers. The existing helpers became wrappers of those now. Note that copy_from/to_iter() returns the copied bytes, hence the error condition is adjusted accordingly. Signed-off-by: Takashi Iwai --- include/sound/pcm.h | 5 ++++ sound/core/memory.c | 56 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/include/sound/pcm.h b/include/sound/pcm.h index ff4a0c1c93a2..f75beead79e3 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -1559,6 +1559,11 @@ static inline u64 pcm_format_to_bits(snd_pcm_format_= t pcm_format) #define pcm_dbg(pcm, fmt, args...) \ dev_dbg((pcm)->card->dev, fmt, ##args) =20 +/* helpers for copying between iov_iter and iomem */ +int copy_to_iter_fromio(struct iov_iter *itert, const void __iomem *src, + size_t count); +int copy_from_iter_toio(void __iomem *dst, struct iov_iter *iter, size_t c= ount); + struct snd_pcm_status64 { snd_pcm_state_t state; /* stream state */ u8 rsvd[4]; diff --git a/sound/core/memory.c b/sound/core/memory.c index 5d894dc32f7d..2d2d0094c897 100644 --- a/sound/core/memory.c +++ b/sound/core/memory.c @@ -9,6 +9,7 @@ #include #include #include +#include =20 /** * copy_to_user_fromio - copy data from mmio-space to user-space @@ -21,9 +22,30 @@ * Return: Zero if successful, or non-zero on failure. */ int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src= , size_t count) +{ + struct iov_iter iter; + + if (import_ubuf(ITER_DEST, dst, count, &iter)) + return -EFAULT; + return copy_to_iter_fromio(&iter, (const void __iomem *)src, count); +} +EXPORT_SYMBOL(copy_to_user_fromio); + +/** + * copy_to_iter_fromio - copy data from mmio-space to iov_iter + * @dst: the destination iov_iter + * @src: the source pointer on mmio + * @count: the data size to copy in bytes + * + * Copies the data from mmio-space to iov_iter. + * + * Return: Zero if successful, or non-zero on failure. + */ +int copy_to_iter_fromio(struct iov_iter *dst, const void __iomem *src, + size_t count) { #if defined(__i386__) || defined(CONFIG_SPARC32) - return copy_to_user(dst, (const void __force*)src, count) ? -EFAULT : 0; + return copy_to_iter((const void __force *)src, count, dst) =3D=3D count ?= 0 : -EFAULT; #else char buf[256]; while (count) { @@ -31,16 +53,15 @@ int copy_to_user_fromio(void __user *dst, const volatil= e void __iomem *src, size if (c > sizeof(buf)) c =3D sizeof(buf); memcpy_fromio(buf, (void __iomem *)src, c); - if (copy_to_user(dst, buf, c)) + if (copy_to_iter(buf, c, dst) !=3D c) return -EFAULT; count -=3D c; - dst +=3D c; src +=3D c; } return 0; #endif } -EXPORT_SYMBOL(copy_to_user_fromio); +EXPORT_SYMBOL(copy_to_iter_fromio); =20 /** * copy_from_user_toio - copy data from user-space to mmio-space @@ -53,23 +74,42 @@ EXPORT_SYMBOL(copy_to_user_fromio); * Return: Zero if successful, or non-zero on failure. */ int copy_from_user_toio(volatile void __iomem *dst, const void __user *src= , size_t count) +{ + struct iov_iter iter; + + if (import_ubuf(ITER_SOURCE, (void __user *)src, count, &iter)) + return -EFAULT; + return copy_from_iter_toio((void __iomem *)dst, &iter, count); +} +EXPORT_SYMBOL(copy_from_user_toio); + +/** + * copy_from_iter_toio - copy data from iov_iter to mmio-space + * @dst: the destination pointer on mmio-space + * @src: the source iov_iter + * @count: the data size to copy in bytes + * + * Copies the data from iov_iter to mmio-space. + * + * Return: Zero if successful, or non-zero on failure. + */ +int copy_from_iter_toio(void __iomem *dst, struct iov_iter *src, size_t co= unt) { #if defined(__i386__) || defined(CONFIG_SPARC32) - return copy_from_user((void __force *)dst, src, count) ? -EFAULT : 0; + return copy_from_iter((void __force *)dst, count, src) =3D=3D count ? 0 := -EFAULT; #else char buf[256]; while (count) { size_t c =3D count; if (c > sizeof(buf)) c =3D sizeof(buf); - if (copy_from_user(buf, src, c)) + if (copy_from_iter(buf, c, src) !=3D c) return -EFAULT; memcpy_toio(dst, buf, c); count -=3D c; dst +=3D c; - src +=3D c; } return 0; #endif } -EXPORT_SYMBOL(copy_from_user_toio); +EXPORT_SYMBOL(copy_from_iter_toio); --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54472C0015E for ; Tue, 15 Aug 2023 19:02:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237353AbjHOTCP (ORCPT ); Tue, 15 Aug 2023 15:02:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239762AbjHOTCN (ORCPT ); Tue, 15 Aug 2023 15:02:13 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 018441BEB for ; Tue, 15 Aug 2023 12:01:50 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C2B741F8C3; Tue, 15 Aug 2023 19:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126107; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O3VMFP/ThTKsmB7svo+Y2YbkVeoI7hlTMO+M5msj2cY=; b=mm09zqvI44MC0922Q7QnkyYJvxBZYPcsk3RCwu6F07NcF5wi97H0zbEDkJT0cWMa6+PtXR b8mV93NLPGNqrE8XEGWR7fXMmlBJ6DO9rz4drcQuvhd9g9EWdzlWYXs0GF8mYCkZeKq0cZ 8YTTgyEVMis/jT31jpEFAU0QKnh8rTE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126107; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O3VMFP/ThTKsmB7svo+Y2YbkVeoI7hlTMO+M5msj2cY=; b=Sgp0i9A+cNlhxo1Y+AdjM8Mf1wTrvb5b3JtTK83KCaJ3d/BkRsIq3o5OdWkzdVUyS6J4Q0 RXCFae0By7k2XGBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9D8171353E; Tue, 15 Aug 2023 19:01:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wEucJZvL22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:47 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai , Andy Shevchenko Subject: [PATCH v2 04/25] ALSA: dummy: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:15 +0200 Message-Id: <20230815190136.8987-5-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the dummy driver code to use the new unified PCM copy callback. As dummy driver doesn't do anything in the callback, it's just a simple replacement. Reviewed-by: Andy Shevchenko Signed-off-by: Takashi Iwai --- sound/drivers/dummy.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c index 9c17b49a2ae1..4317677ba24a 100644 --- a/sound/drivers/dummy.c +++ b/sound/drivers/dummy.c @@ -626,14 +626,7 @@ static int alloc_fake_buffer(void) =20 static int dummy_pcm_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *dst, unsigned long bytes) -{ - return 0; /* do nothing */ -} - -static int dummy_pcm_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long pos, - void *dst, unsigned long bytes) + struct iov_iter *iter, unsigned long bytes) { return 0; /* do nothing */ } @@ -667,8 +660,7 @@ static const struct snd_pcm_ops dummy_pcm_ops_no_buf = =3D { .prepare =3D dummy_pcm_prepare, .trigger =3D dummy_pcm_trigger, .pointer =3D dummy_pcm_pointer, - .copy_user =3D dummy_pcm_copy, - .copy_kernel =3D dummy_pcm_copy_kernel, + .copy =3D dummy_pcm_copy, .fill_silence =3D dummy_pcm_silence, .page =3D dummy_pcm_page, }; --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D1F3C41513 for ; Tue, 15 Aug 2023 19:02:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239644AbjHOTCT (ORCPT ); Tue, 15 Aug 2023 15:02:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239765AbjHOTCN (ORCPT ); Tue, 15 Aug 2023 15:02:13 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EB5F213E for ; Tue, 15 Aug 2023 12:01:51 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E365D219A3; Tue, 15 Aug 2023 19:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126107; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xEwshEXd5jHzSin+0WURFtdbZgE1smV0MVE5PXNoruQ=; b=MXBQHOYYgfH/bnDoaMxIMU9sASgToyrxBUm30m8PuWlu/pP5JqqJvzzrBpOtgj76DJY1c7 pbTQcR3wzes52tW2kWVN8ugApPC2jTS3erRVA9FGQ4rmB1la2XsHUdm6BwBlNt8/PdcqRq LuubXnRCBl0PcDOzyIbaUw+A7VxykgE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126107; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xEwshEXd5jHzSin+0WURFtdbZgE1smV0MVE5PXNoruQ=; b=kaVCJFAtAOnSLajpLtq32S+HTkQCWOElto/vs99aqqdWPdCqOBAN03HyTMDs5wC1qfy/48 wVqb4g/Z9BsXrxBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C567E1390C; Tue, 15 Aug 2023 19:01:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id mOkrL5vL22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:47 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 05/25] ALSA: gus: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:16 +0200 Message-Id: <20230815190136.8987-6-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the GUS driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants. Note that copy_from/to_iter() returns the copied bytes, hence the error condition is adjusted accordingly. Signed-off-by: Takashi Iwai --- sound/isa/gus/gus_pcm.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/sound/isa/gus/gus_pcm.c b/sound/isa/gus/gus_pcm.c index 388db5fb65bd..850544725da7 100644 --- a/sound/isa/gus/gus_pcm.c +++ b/sound/isa/gus/gus_pcm.c @@ -369,7 +369,7 @@ static int playback_copy_ack(struct snd_pcm_substream *= substream, =20 static int snd_gf1_pcm_playback_copy(struct snd_pcm_substream *substream, int voice, unsigned long pos, - void __user *src, unsigned long count) + struct iov_iter *src, unsigned long count) { struct snd_pcm_runtime *runtime =3D substream->runtime; struct gus_pcm_private *pcmp =3D runtime->private_data; @@ -379,27 +379,11 @@ static int snd_gf1_pcm_playback_copy(struct snd_pcm_s= ubstream *substream, bpos =3D get_bpos(pcmp, voice, pos, len); if (bpos < 0) return pos; - if (copy_from_user(runtime->dma_area + bpos, src, len)) + if (copy_from_iter(runtime->dma_area + bpos, len, src) !=3D len) return -EFAULT; return playback_copy_ack(substream, bpos, len); } =20 -static int snd_gf1_pcm_playback_copy_kernel(struct snd_pcm_substream *subs= tream, - int voice, unsigned long pos, - void *src, unsigned long count) -{ - struct snd_pcm_runtime *runtime =3D substream->runtime; - struct gus_pcm_private *pcmp =3D runtime->private_data; - unsigned int len =3D count; - int bpos; - - bpos =3D get_bpos(pcmp, voice, pos, len); - if (bpos < 0) - return pos; - memcpy(runtime->dma_area + bpos, src, len); - return playback_copy_ack(substream, bpos, len); -} - static int snd_gf1_pcm_playback_silence(struct snd_pcm_substream *substrea= m, int voice, unsigned long pos, unsigned long count) @@ -830,8 +814,7 @@ static const struct snd_pcm_ops snd_gf1_pcm_playback_op= s =3D { .prepare =3D snd_gf1_pcm_playback_prepare, .trigger =3D snd_gf1_pcm_playback_trigger, .pointer =3D snd_gf1_pcm_playback_pointer, - .copy_user =3D snd_gf1_pcm_playback_copy, - .copy_kernel =3D snd_gf1_pcm_playback_copy_kernel, + .copy =3D snd_gf1_pcm_playback_copy, .fill_silence =3D snd_gf1_pcm_playback_silence, }; =20 --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B649C07E8E for ; Tue, 15 Aug 2023 19:03:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239818AbjHOTDJ (ORCPT ); Tue, 15 Aug 2023 15:03:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239784AbjHOTCk (ORCPT ); Tue, 15 Aug 2023 15:02:40 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B055A2689 for ; Tue, 15 Aug 2023 12:02:19 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1D64E1F8CC; Tue, 15 Aug 2023 19:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126108; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UCVs2lrJV8zC/zCpUs0xKreUnK1an8pHd+lADqQDEu8=; b=dWpc/5WWLuNXxLGjXvAzH+6PaF/36QRVNCyebWMMP2mSbiNuAR3AA25ZLZHn1k20i4AT7P yytqCE4pJc12oVHaC/dKyiCokCEX7qiHBt49kNIp6RHVSy5rZ6YyBuOqR0gxaASuibiPSJ yXdl10kRkhEjZzmEDS6iOZagxEnrUSo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126108; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UCVs2lrJV8zC/zCpUs0xKreUnK1an8pHd+lADqQDEu8=; b=JWMviMul9KnRRD4eXpKDVm1dN9Obgd77w/S0ARyhavGWB9611pmDlqEtmNeUR40y9jjoZI oFDg5VZ+elu5PQCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F260A1353E; Tue, 15 Aug 2023 19:01:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IJo4OpvL22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:47 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 06/25] ALSA: emu8000: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:17 +0200 Message-Id: <20230815190136.8987-7-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the SB Emu8000 driver code to use the new unified PCM copy callback. The conversion is a bit complicated because of many open code in emu8000_pcm.c. GET_VAL() and LOOP_WRITE() macros were rewritten / simplified with copy_from_iter(). As copy_from_iter() updates the internal offset value, we can drop the corresponding part, too. Signed-off-by: Takashi Iwai --- sound/isa/sb/emu8000_pcm.c | 74 +++++++++----------------------------- 1 file changed, 16 insertions(+), 58 deletions(-) diff --git a/sound/isa/sb/emu8000_pcm.c b/sound/isa/sb/emu8000_pcm.c index c8afc4347c54..c05935c2edc4 100644 --- a/sound/isa/sb/emu8000_pcm.c +++ b/sound/isa/sb/emu8000_pcm.c @@ -409,39 +409,25 @@ do { \ return -EAGAIN;\ } while (0) =20 -enum { - COPY_USER, COPY_KERNEL, FILL_SILENCE, -}; - -#define GET_VAL(sval, buf, mode) \ +#define GET_VAL(sval, iter) \ do { \ - switch (mode) { \ - case FILL_SILENCE: \ + if (!iter) \ sval =3D 0; \ - break; \ - case COPY_KERNEL: \ - sval =3D *buf++; \ - break; \ - default: \ - if (get_user(sval, (unsigned short __user *)buf)) \ - return -EFAULT; \ - buf++; \ - break; \ - } \ + else if (copy_from_iter(&sval, 2, iter) !=3D 2) \ + return -EFAULT; \ } while (0) =20 #ifdef USE_NONINTERLEAVE =20 -#define LOOP_WRITE(rec, offset, _buf, count, mode) \ +#define LOOP_WRITE(rec, offset, iter, count) \ do { \ struct snd_emu8000 *emu =3D (rec)->emu; \ - unsigned short *buf =3D (__force unsigned short *)(_buf); \ snd_emu8000_write_wait(emu, 1); \ EMU8000_SMALW_WRITE(emu, offset); \ while (count > 0) { \ unsigned short sval; \ CHECK_SCHEDULER(); \ - GET_VAL(sval, buf, mode); \ + GET_VAL(sval, iter); \ EMU8000_SMLD_WRITE(emu, sval); \ count--; \ } \ @@ -450,27 +436,14 @@ enum { /* copy one channel block */ static int emu8k_pcm_copy(struct snd_pcm_substream *subs, int voice, unsigned long pos, - void __user *src, unsigned long count) + struct iov_iter *src, unsigned long count) { struct snd_emu8k_pcm *rec =3D subs->runtime->private_data; =20 /* convert to word unit */ pos =3D (pos << 1) + rec->loop_start[voice]; count <<=3D 1; - LOOP_WRITE(rec, pos, src, count, COPY_USER); - return 0; -} - -static int emu8k_pcm_copy_kernel(struct snd_pcm_substream *subs, - int voice, unsigned long pos, - void *src, unsigned long count) -{ - struct snd_emu8k_pcm *rec =3D subs->runtime->private_data; - - /* convert to word unit */ - pos =3D (pos << 1) + rec->loop_start[voice]; - count <<=3D 1; - LOOP_WRITE(rec, pos, src, count, COPY_KERNEL); + LOOP_WRITE(rec, pos, src, count); return 0; } =20 @@ -483,16 +456,15 @@ static int emu8k_pcm_silence(struct snd_pcm_substream= *subs, /* convert to word unit */ pos =3D (pos << 1) + rec->loop_start[voice]; count <<=3D 1; - LOOP_WRITE(rec, pos, NULL, count, FILL_SILENCE); + LOOP_WRITE(rec, pos, USER_SOCKPTR(NULL), count); return 0; } =20 #else /* interleave */ =20 -#define LOOP_WRITE(rec, pos, _buf, count, mode) \ +#define LOOP_WRITE(rec, pos, iter, count) \ do { \ struct snd_emu8000 *emu =3D rec->emu; \ - unsigned short *buf =3D (__force unsigned short *)(_buf); \ snd_emu8000_write_wait(emu, 1); \ EMU8000_SMALW_WRITE(emu, pos + rec->loop_start[0]); \ if (rec->voices > 1) \ @@ -500,11 +472,11 @@ static int emu8k_pcm_silence(struct snd_pcm_substream= *subs, while (count > 0) { \ unsigned short sval; \ CHECK_SCHEDULER(); \ - GET_VAL(sval, buf, mode); \ + GET_VAL(sval, iter); \ EMU8000_SMLD_WRITE(emu, sval); \ if (rec->voices > 1) { \ CHECK_SCHEDULER(); \ - GET_VAL(sval, buf, mode); \ + GET_VAL(sval, iter); \ EMU8000_SMRD_WRITE(emu, sval); \ } \ count--; \ @@ -518,27 +490,14 @@ static int emu8k_pcm_silence(struct snd_pcm_substream= *subs, */ static int emu8k_pcm_copy(struct snd_pcm_substream *subs, int voice, unsigned long pos, - void __user *src, unsigned long count) + struct iov_iter *src, unsigned long count) { struct snd_emu8k_pcm *rec =3D subs->runtime->private_data; =20 /* convert to frames */ pos =3D bytes_to_frames(subs->runtime, pos); count =3D bytes_to_frames(subs->runtime, count); - LOOP_WRITE(rec, pos, src, count, COPY_USER); - return 0; -} - -static int emu8k_pcm_copy_kernel(struct snd_pcm_substream *subs, - int voice, unsigned long pos, - void *src, unsigned long count) -{ - struct snd_emu8k_pcm *rec =3D subs->runtime->private_data; - - /* convert to frames */ - pos =3D bytes_to_frames(subs->runtime, pos); - count =3D bytes_to_frames(subs->runtime, count); - LOOP_WRITE(rec, pos, src, count, COPY_KERNEL); + LOOP_WRITE(rec, pos, src, count); return 0; } =20 @@ -550,7 +509,7 @@ static int emu8k_pcm_silence(struct snd_pcm_substream *= subs, /* convert to frames */ pos =3D bytes_to_frames(subs->runtime, pos); count =3D bytes_to_frames(subs->runtime, count); - LOOP_WRITE(rec, pos, NULL, count, FILL_SILENCE); + LOOP_WRITE(rec, pos, NULL, count); return 0; } #endif @@ -666,8 +625,7 @@ static const struct snd_pcm_ops emu8k_pcm_ops =3D { .prepare =3D emu8k_pcm_prepare, .trigger =3D emu8k_pcm_trigger, .pointer =3D emu8k_pcm_pointer, - .copy_user =3D emu8k_pcm_copy, - .copy_kernel =3D emu8k_pcm_copy_kernel, + .copy =3D emu8k_pcm_copy, .fill_silence =3D emu8k_pcm_silence, }; =20 --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80E6CC04FE2 for ; Tue, 15 Aug 2023 19:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239772AbjHOTDD (ORCPT ); Tue, 15 Aug 2023 15:03:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239788AbjHOTCk (ORCPT ); Tue, 15 Aug 2023 15:02:40 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AEB4269E for ; Tue, 15 Aug 2023 12:02:21 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3F76D1FD64; Tue, 15 Aug 2023 19:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126108; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lu8lb3bHhmPhKXNMb+mmGurfLxLx/VLPR5QQUqntmKQ=; b=MlqT5XvafyDPjf1x2nD3fgibQP/p2/djqKkJU1L6NB1q2/io1nno0OGqoincwBfT2i4cc4 GwyeKBMNyqHIvYYToEBRnZrllPJQSB9NqM22lXpmAN9sADy5BEMUmDMY6tcTxXKiR9o11p V8tuRQZoHc/ibBSmph6KQY/YBmR/f+Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126108; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lu8lb3bHhmPhKXNMb+mmGurfLxLx/VLPR5QQUqntmKQ=; b=E2Sv8+yqGwRUW6uVvh0pDjuyLR5O+AA39/DW8PFzxdWEhD2xCq2hbgQiB72hEMLQR/i4sF gcZ+bUJFwB1kTsDg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 212E81390C; Tue, 15 Aug 2023 19:01:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2H44B5zL22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:48 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 07/25] ALSA: es1938: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:18 +0200 Message-Id: <20230815190136.8987-8-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the es1938 driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants in most parts. Note that copy_from/to_iter() returns the copied bytes, hence the error condition is adjusted accordingly. Signed-off-by: Takashi Iwai --- sound/pci/es1938.c | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c index e34ec6f89e7e..ec598ba1a883 100644 --- a/sound/pci/es1938.c +++ b/sound/pci/es1938.c @@ -824,7 +824,7 @@ static snd_pcm_uframes_t snd_es1938_playback_pointer(st= ruct snd_pcm_substream *s =20 static int snd_es1938_capture_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *dst, unsigned long count) + struct iov_iter *dst, unsigned long count) { struct snd_pcm_runtime *runtime =3D substream->runtime; struct es1938 *chip =3D snd_pcm_substream_chip(substream); @@ -832,36 +832,17 @@ static int snd_es1938_capture_copy(struct snd_pcm_sub= stream *substream, if (snd_BUG_ON(pos + count > chip->dma1_size)) return -EINVAL; if (pos + count < chip->dma1_size) { - if (copy_to_user(dst, runtime->dma_area + pos + 1, count)) + if (copy_to_iter(runtime->dma_area + pos + 1, count, dst) !=3D count) return -EFAULT; } else { - if (copy_to_user(dst, runtime->dma_area + pos + 1, count - 1)) + if (copy_to_iter(runtime->dma_area + pos + 1, count - 1, dst) !=3D count= - 1) return -EFAULT; - if (put_user(runtime->dma_area[0], - ((unsigned char __user *)dst) + count - 1)) + if (copy_to_iter(runtime->dma_area, 1, dst) !=3D 1) return -EFAULT; } return 0; } =20 -static int snd_es1938_capture_copy_kernel(struct snd_pcm_substream *substr= eam, - int channel, unsigned long pos, - void *dst, unsigned long count) -{ - struct snd_pcm_runtime *runtime =3D substream->runtime; - struct es1938 *chip =3D snd_pcm_substream_chip(substream); - - if (snd_BUG_ON(pos + count > chip->dma1_size)) - return -EINVAL; - if (pos + count < chip->dma1_size) { - memcpy(dst, runtime->dma_area + pos + 1, count); - } else { - memcpy(dst, runtime->dma_area + pos + 1, count - 1); - runtime->dma_area[0] =3D *((unsigned char *)dst + count - 1); - } - return 0; -} - /* ---------------------------------------------------------------------- * Audio1 Capture (ADC) * ----------------------------------------------------------------------*/ @@ -987,8 +968,7 @@ static const struct snd_pcm_ops snd_es1938_capture_ops = =3D { .prepare =3D snd_es1938_capture_prepare, .trigger =3D snd_es1938_capture_trigger, .pointer =3D snd_es1938_capture_pointer, - .copy_user =3D snd_es1938_capture_copy, - .copy_kernel =3D snd_es1938_capture_copy_kernel, + .copy =3D snd_es1938_capture_copy, }; =20 static int snd_es1938_new_pcm(struct es1938 *chip, int device) --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B3F1C05052 for ; Tue, 15 Aug 2023 19:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239759AbjHOTDC (ORCPT ); Tue, 15 Aug 2023 15:03:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239802AbjHOTCm (ORCPT ); Tue, 15 Aug 2023 15:02:42 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CC651FE2 for ; Tue, 15 Aug 2023 12:02:23 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 611801FD65; Tue, 15 Aug 2023 19:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126108; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ASUwd958P5x/mva8ZR+pltrHluFd6nJ8P9qOx6QddwI=; b=G0Y7LAV+S/FgM6AOhM28ndSn1Qz3m7uVuVFDSbKieVTcR+i0Mgln7Tildr8GVW2dRnYea2 Q7PqSk779EFanAiaaUKcbdFTK0n1ZKcCzvWrj3AOFavqc0D3i225Th3kEuSMqA3v/Khoyu hzYZK+xJFx2pO1BNf2nVOll1pWAjOIk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126108; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ASUwd958P5x/mva8ZR+pltrHluFd6nJ8P9qOx6QddwI=; b=HLLejty9AB+8i7AzQ7TON8xut8eQQx3L3eywPI6mKjJjcUDu0TsqB/Nb8vA9tiGP6Q6iJY 8ijncOpftX7onaBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 431601353E; Tue, 15 Aug 2023 19:01:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0DGZD5zL22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:48 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 08/25] ALSA: korg1212: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:19 +0200 Message-Id: <20230815190136.8987-9-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Takashi Iwai --- sound/pci/korg1212/korg1212.c | 50 +++++++++-------------------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c index 33b4f95d65b3..5c2cac201a28 100644 --- a/sound/pci/korg1212/korg1212.c +++ b/sound/pci/korg1212/korg1212.c @@ -1285,8 +1285,7 @@ static int snd_korg1212_silence(struct snd_korg1212 *= korg1212, int pos, int coun } =20 static int snd_korg1212_copy_to(struct snd_pcm_substream *substream, - void __user *dst, int pos, int count, - bool in_kernel) + struct iov_iter *dst, int pos, int count) { struct snd_pcm_runtime *runtime =3D substream->runtime; struct snd_korg1212 *korg1212 =3D snd_pcm_substream_chip(substream= ); @@ -1306,24 +1305,20 @@ static int snd_korg1212_copy_to(struct snd_pcm_subs= tream *substream, #if K1212_DEBUG_LEVEL > 0 if ( (void *) src < (void *) korg1212->recordDataBufsPtr || (void *) src > (void *) korg1212->recordDataBufsPtr[8].bufferData )= { - printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src= =3D%p dst=3D%p iter=3D%d\n", src, dst, i); + printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_to KERNEL EFAULT, src= =3D%p dst=3D%p iter=3D%d\n", src, dst->kvec.iov_base, i); return -EFAULT; } #endif - if (in_kernel) - memcpy((__force void *)dst, src, size); - else if (copy_to_user(dst, src, size)) + if (copy_to_iter(src, size, dst) !=3D size) return -EFAULT; src++; - dst +=3D size; } =20 return 0; } =20 static int snd_korg1212_copy_from(struct snd_pcm_substream *substream, - void __user *src, int pos, int count, - bool in_kernel) + struct iov_iter *src, int pos, int count) { struct snd_pcm_runtime *runtime =3D substream->runtime; struct snd_korg1212 *korg1212 =3D snd_pcm_substream_chip(substream); @@ -1345,16 +1340,13 @@ static int snd_korg1212_copy_from(struct snd_pcm_su= bstream *substream, #if K1212_DEBUG_LEVEL > 0 if ( (void *) dst < (void *) korg1212->playDataBufsPtr || (void *) dst > (void *) korg1212->playDataBufsPtr[8].bufferData ) { - printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, s= rc=3D%p dst=3D%p iter=3D%d\n", src, dst, i); + printk(KERN_DEBUG "K1212_DEBUG: snd_korg1212_copy_from KERNEL EFAULT, s= rc=3D%p dst=3D%p iter=3D%d\n", src->kvec.iov_base, dst, i); return -EFAULT; } #endif - if (in_kernel) - memcpy(dst, (__force void *)src, size); - else if (copy_from_user(dst, src, size)) + if (copy_from_iter(dst, size, src) !=3D size) return -EFAULT; dst++; - src +=3D size; } =20 return 0; @@ -1642,17 +1634,9 @@ static snd_pcm_uframes_t snd_korg1212_capture_pointe= r(struct snd_pcm_substream * =20 static int snd_korg1212_playback_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *src, unsigned long count) + struct iov_iter *src, unsigned long count) { - return snd_korg1212_copy_from(substream, src, pos, count, false); -} - -static int snd_korg1212_playback_copy_kernel(struct snd_pcm_substream *sub= stream, - int channel, unsigned long pos, - void *src, unsigned long count) -{ - return snd_korg1212_copy_from(substream, (void __user *)src, - pos, count, true); + return snd_korg1212_copy_from(substream, src, pos, count); } =20 static int snd_korg1212_playback_silence(struct snd_pcm_substream *substre= am, @@ -1670,17 +1654,9 @@ static int snd_korg1212_playback_silence(struct snd_= pcm_substream *substream, =20 static int snd_korg1212_capture_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *dst, unsigned long count) + struct iov_iter *dst, unsigned long count) { - return snd_korg1212_copy_to(substream, dst, pos, count, false); -} - -static int snd_korg1212_capture_copy_kernel(struct snd_pcm_substream *subs= tream, - int channel, unsigned long pos, - void *dst, unsigned long count) -{ - return snd_korg1212_copy_to(substream, (void __user *)dst, - pos, count, true); + return snd_korg1212_copy_to(substream, dst, pos, count); } =20 static const struct snd_pcm_ops snd_korg1212_playback_ops =3D { @@ -1691,8 +1667,7 @@ static const struct snd_pcm_ops snd_korg1212_playback= _ops =3D { .prepare =3D snd_korg1212_prepare, .trigger =3D snd_korg1212_trigger, .pointer =3D snd_korg1212_playback_pointer, - .copy_user =3D snd_korg1212_playback_copy, - .copy_kernel =3D snd_korg1212_playback_copy_kernel, + .copy =3D snd_korg1212_playback_copy, .fill_silence =3D snd_korg1212_playback_silence, }; =20 @@ -1704,8 +1679,7 @@ static const struct snd_pcm_ops snd_korg1212_capture_= ops =3D { .prepare =3D snd_korg1212_prepare, .trigger =3D snd_korg1212_trigger, .pointer =3D snd_korg1212_capture_pointer, - .copy_user =3D snd_korg1212_capture_copy, - .copy_kernel =3D snd_korg1212_capture_copy_kernel, + .copy =3D snd_korg1212_capture_copy, }; =20 /* --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A09F4C07E8B for ; Tue, 15 Aug 2023 19:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239785AbjHOTDF (ORCPT ); Tue, 15 Aug 2023 15:03:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239754AbjHOTCg (ORCPT ); Tue, 15 Aug 2023 15:02:36 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EF232134 for ; Tue, 15 Aug 2023 12:02:14 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 86E26219A5; Tue, 15 Aug 2023 19:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126108; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5xJHuvA5gT6n1i0ytgW/H7/p1r9TYXBmYRI/sH4EsE0=; b=quIMOGurxTUd4o7P4VgI/hdYPnbjocIKWNj2o5BIX6Q8YM0crETczGGn6AeQdjGNJWrcmv ndBzGg1YefBc4s+3O/ypswil0XD64jqeWFo0DhJdmQF+8Q2bHEZ6XHLMeMq9+GDLnPZ8uy 1+TqikHpxovQk0GGZaa1Z4MeJF4FMuQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126108; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5xJHuvA5gT6n1i0ytgW/H7/p1r9TYXBmYRI/sH4EsE0=; b=kFCrXlZzwDVJxIOSXyqawncQf1HecYhqYFgTAOtXt3Qr8QOD/Pb71Rnv6W2gpvLto+qtGI rfc72SC+9kFfmsBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 65E0B1390C; Tue, 15 Aug 2023 19:01:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id cNDjF5zL22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:48 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 09/25] ALSA: nm256: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:20 +0200 Message-Id: <20230815190136.8987-10-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the nm256 driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants. Signed-off-by: Takashi Iwai --- sound/pci/nm256/nm256.c | 42 ++++++----------------------------------- 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c index f99a1e96e923..34f90829e656 100644 --- a/sound/pci/nm256/nm256.c +++ b/sound/pci/nm256/nm256.c @@ -691,26 +691,12 @@ snd_nm256_playback_silence(struct snd_pcm_substream *= substream, static int snd_nm256_playback_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *src, unsigned long count) + struct iov_iter *src, unsigned long count) { struct snd_pcm_runtime *runtime =3D substream->runtime; struct nm256_stream *s =3D runtime->private_data; =20 - if (copy_from_user_toio(s->bufptr + pos, src, count)) - return -EFAULT; - return 0; -} - -static int -snd_nm256_playback_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long pos, - void *src, unsigned long count) -{ - struct snd_pcm_runtime *runtime =3D substream->runtime; - struct nm256_stream *s =3D runtime->private_data; - - memcpy_toio(s->bufptr + pos, src, count); - return 0; + return copy_from_iter_toio(s->bufptr + pos, src, count); } =20 /* @@ -719,26 +705,12 @@ snd_nm256_playback_copy_kernel(struct snd_pcm_substre= am *substream, static int snd_nm256_capture_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *dst, unsigned long count) + struct iov_iter *dst, unsigned long count) { struct snd_pcm_runtime *runtime =3D substream->runtime; struct nm256_stream *s =3D runtime->private_data; =20 - if (copy_to_user_fromio(dst, s->bufptr + pos, count)) - return -EFAULT; - return 0; -} - -static int -snd_nm256_capture_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long pos, - void *dst, unsigned long count) -{ - struct snd_pcm_runtime *runtime =3D substream->runtime; - struct nm256_stream *s =3D runtime->private_data; - - memcpy_fromio(dst, s->bufptr + pos, count); - return 0; + return copy_to_iter_fromio(dst, s->bufptr + pos, count); } =20 #endif /* !__i386__ */ @@ -909,8 +881,7 @@ static const struct snd_pcm_ops snd_nm256_playback_ops = =3D { .trigger =3D snd_nm256_playback_trigger, .pointer =3D snd_nm256_playback_pointer, #ifndef __i386__ - .copy_user =3D snd_nm256_playback_copy, - .copy_kernel =3D snd_nm256_playback_copy_kernel, + .copy =3D snd_nm256_playback_copy, .fill_silence =3D snd_nm256_playback_silence, #endif .mmap =3D snd_pcm_lib_mmap_iomem, @@ -924,8 +895,7 @@ static const struct snd_pcm_ops snd_nm256_capture_ops = =3D { .trigger =3D snd_nm256_capture_trigger, .pointer =3D snd_nm256_capture_pointer, #ifndef __i386__ - .copy_user =3D snd_nm256_capture_copy, - .copy_kernel =3D snd_nm256_capture_copy_kernel, + .copy =3D snd_nm256_capture_copy, #endif .mmap =3D snd_pcm_lib_mmap_iomem, }; --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C9D2C001E0 for ; Tue, 15 Aug 2023 19:02:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239678AbjHOTCW (ORCPT ); Tue, 15 Aug 2023 15:02:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239766AbjHOTCN (ORCPT ); Tue, 15 Aug 2023 15:02:13 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC00D2680 for ; Tue, 15 Aug 2023 12:01:51 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AC2181FD66; Tue, 15 Aug 2023 19:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126108; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KmpMqv9W8iYfflO8sQaY3lJwfHw1dyMQl8ItqzCOPcc=; b=dQBv3Bb5S9LU7uqrz7alAy2/ZG1W5C+xSoa6dBQf1/aRdNQu1EvhAZRGQCnYiqiQlm7JEf AmD53OFTixKoz8fwH7wW7flEu5AeR75n0ZPRBoJSTCt3zMWWJxDByHCviQnMZFhI94DSOG T7XJpRWMk47M+oEtd0evepUm4rw0g4k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126108; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KmpMqv9W8iYfflO8sQaY3lJwfHw1dyMQl8ItqzCOPcc=; b=/GnCwUHag7xh2X3cOvCvmo2rLX24+ESCzhOmmqtRZmuYy6GrHNMIqDeKmphtdFzr5Y2hnM DYQruRmLHWh+wYAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8B2691353E; Tue, 15 Aug 2023 19:01:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gL0KIZzL22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:48 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 10/25] ALSA: rme32: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:21 +0200 Message-Id: <20230815190136.8987-11-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the rme32 driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants. Signed-off-by: Takashi Iwai --- sound/pci/rme32.c | 50 +++++++++++------------------------------------ 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c index 9c0ac025e143..02144bbee6d5 100644 --- a/sound/pci/rme32.c +++ b/sound/pci/rme32.c @@ -252,48 +252,24 @@ static int snd_rme32_playback_silence(struct snd_pcm_= substream *substream, /* copy callback for halfduplex mode */ static int snd_rme32_playback_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *src, unsigned long count) + struct iov_iter *src, unsigned long count) { struct rme32 *rme32 =3D snd_pcm_substream_chip(substream); =20 - if (copy_from_user_toio(rme32->iobase + RME32_IO_DATA_BUFFER + pos, - src, count)) - return -EFAULT; - return 0; -} - -static int snd_rme32_playback_copy_kernel(struct snd_pcm_substream *substr= eam, - int channel, unsigned long pos, - void *src, unsigned long count) -{ - struct rme32 *rme32 =3D snd_pcm_substream_chip(substream); - - memcpy_toio(rme32->iobase + RME32_IO_DATA_BUFFER + pos, src, count); - return 0; + return copy_from_iter_toio(rme32->iobase + RME32_IO_DATA_BUFFER + pos, + src, count); } =20 /* copy callback for halfduplex mode */ static int snd_rme32_capture_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *dst, unsigned long count) + struct iov_iter *dst, unsigned long count) { struct rme32 *rme32 =3D snd_pcm_substream_chip(substream); =20 - if (copy_to_user_fromio(dst, - rme32->iobase + RME32_IO_DATA_BUFFER + pos, - count)) - return -EFAULT; - return 0; -} - -static int snd_rme32_capture_copy_kernel(struct snd_pcm_substream *substre= am, - int channel, unsigned long pos, - void *dst, unsigned long count) -{ - struct rme32 *rme32 =3D snd_pcm_substream_chip(substream); - - memcpy_fromio(dst, rme32->iobase + RME32_IO_DATA_BUFFER + pos, count); - return 0; + return copy_to_iter_fromio(dst, + rme32->iobase + RME32_IO_DATA_BUFFER + pos, + count); } =20 /* @@ -1194,8 +1170,7 @@ static const struct snd_pcm_ops snd_rme32_playback_sp= dif_ops =3D { .prepare =3D snd_rme32_playback_prepare, .trigger =3D snd_rme32_pcm_trigger, .pointer =3D snd_rme32_playback_pointer, - .copy_user =3D snd_rme32_playback_copy, - .copy_kernel =3D snd_rme32_playback_copy_kernel, + .copy =3D snd_rme32_playback_copy, .fill_silence =3D snd_rme32_playback_silence, .mmap =3D snd_pcm_lib_mmap_iomem, }; @@ -1207,8 +1182,7 @@ static const struct snd_pcm_ops snd_rme32_capture_spd= if_ops =3D { .prepare =3D snd_rme32_capture_prepare, .trigger =3D snd_rme32_pcm_trigger, .pointer =3D snd_rme32_capture_pointer, - .copy_user =3D snd_rme32_capture_copy, - .copy_kernel =3D snd_rme32_capture_copy_kernel, + .copy =3D snd_rme32_capture_copy, .mmap =3D snd_pcm_lib_mmap_iomem, }; =20 @@ -1219,8 +1193,7 @@ static const struct snd_pcm_ops snd_rme32_playback_ad= at_ops =3D { .prepare =3D snd_rme32_playback_prepare, .trigger =3D snd_rme32_pcm_trigger, .pointer =3D snd_rme32_playback_pointer, - .copy_user =3D snd_rme32_playback_copy, - .copy_kernel =3D snd_rme32_playback_copy_kernel, + .copy =3D snd_rme32_playback_copy, .fill_silence =3D snd_rme32_playback_silence, .mmap =3D snd_pcm_lib_mmap_iomem, }; @@ -1232,8 +1205,7 @@ static const struct snd_pcm_ops snd_rme32_capture_ada= t_ops =3D { .prepare =3D snd_rme32_capture_prepare, .trigger =3D snd_rme32_pcm_trigger, .pointer =3D snd_rme32_capture_pointer, - .copy_user =3D snd_rme32_capture_copy, - .copy_kernel =3D snd_rme32_capture_copy_kernel, + .copy =3D snd_rme32_capture_copy, .mmap =3D snd_pcm_lib_mmap_iomem, }; =20 --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1963C001E0 for ; Tue, 15 Aug 2023 19:03:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239661AbjHOTCu (ORCPT ); Tue, 15 Aug 2023 15:02:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239762AbjHOTCg (ORCPT ); Tue, 15 Aug 2023 15:02:36 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB6902135 for ; Tue, 15 Aug 2023 12:02:14 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D0A121FD68; Tue, 15 Aug 2023 19:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126108; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jjxBtA0K776P/pHFSLKAptmDdu6ejterm7BFJcjarEE=; b=Yi1UMFdy/AKEMCC6k3tZ9C2ebOSUD8giq3eIIVdUwfu6N1MCqz1rEevLwxMQmEEePPnrGp 6uMNBaTrYJ1MItBmLECev+7NYXAfdcuyl6VuBJBYJvuKVI+H42kKpDye35cVmZbjy+vVqu AIVA4qCGRqKAVpJwdGe2dx/eA0hCOZs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126108; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jjxBtA0K776P/pHFSLKAptmDdu6ejterm7BFJcjarEE=; b=3mOjfjiJV8gEjFikT0niNVAJiS4JgEQMsn09QJ0UEro9pGUCL3AWBJtvN+JByKDT0qDTUc 1pZwFFWzSK3gH3BQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id AFFCB1390C; Tue, 15 Aug 2023 19:01:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iAcAKpzL22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:48 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 11/25] ALSA: rme96: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:22 +0200 Message-Id: <20230815190136.8987-12-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the rme96 driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants. Signed-off-by: Takashi Iwai --- sound/pci/rme96.c | 42 ++++++++---------------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c index bccb7e0d3d11..6b5ffb18197b 100644 --- a/sound/pci/rme96.c +++ b/sound/pci/rme96.c @@ -320,48 +320,26 @@ snd_rme96_playback_silence(struct snd_pcm_substream *= substream, static int snd_rme96_playback_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *src, unsigned long count) + struct iov_iter *src, unsigned long count) { struct rme96 *rme96 =3D snd_pcm_substream_chip(substream); =20 - return copy_from_user_toio(rme96->iobase + RME96_IO_PLAY_BUFFER + pos, + return copy_from_iter_toio(rme96->iobase + RME96_IO_PLAY_BUFFER + pos, src, count); } =20 -static int -snd_rme96_playback_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long pos, - void *src, unsigned long count) -{ - struct rme96 *rme96 =3D snd_pcm_substream_chip(substream); - - memcpy_toio(rme96->iobase + RME96_IO_PLAY_BUFFER + pos, src, count); - return 0; -} - static int snd_rme96_capture_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *dst, unsigned long count) + struct iov_iter *dst, unsigned long count) { struct rme96 *rme96 =3D snd_pcm_substream_chip(substream); =20 - return copy_to_user_fromio(dst, + return copy_to_iter_fromio(dst, rme96->iobase + RME96_IO_REC_BUFFER + pos, count); } =20 -static int -snd_rme96_capture_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long pos, - void *dst, unsigned long count) -{ - struct rme96 *rme96 =3D snd_pcm_substream_chip(substream); - - memcpy_fromio(dst, rme96->iobase + RME96_IO_REC_BUFFER + pos, count); - return 0; -} - /* * Digital output capabilities (S/PDIF) */ @@ -1518,8 +1496,7 @@ static const struct snd_pcm_ops snd_rme96_playback_sp= dif_ops =3D { .prepare =3D snd_rme96_playback_prepare, .trigger =3D snd_rme96_playback_trigger, .pointer =3D snd_rme96_playback_pointer, - .copy_user =3D snd_rme96_playback_copy, - .copy_kernel =3D snd_rme96_playback_copy_kernel, + .copy =3D snd_rme96_playback_copy, .fill_silence =3D snd_rme96_playback_silence, .mmap =3D snd_pcm_lib_mmap_iomem, }; @@ -1531,8 +1508,7 @@ static const struct snd_pcm_ops snd_rme96_capture_spd= if_ops =3D { .prepare =3D snd_rme96_capture_prepare, .trigger =3D snd_rme96_capture_trigger, .pointer =3D snd_rme96_capture_pointer, - .copy_user =3D snd_rme96_capture_copy, - .copy_kernel =3D snd_rme96_capture_copy_kernel, + .copy =3D snd_rme96_capture_copy, .mmap =3D snd_pcm_lib_mmap_iomem, }; =20 @@ -1543,8 +1519,7 @@ static const struct snd_pcm_ops snd_rme96_playback_ad= at_ops =3D { .prepare =3D snd_rme96_playback_prepare, .trigger =3D snd_rme96_playback_trigger, .pointer =3D snd_rme96_playback_pointer, - .copy_user =3D snd_rme96_playback_copy, - .copy_kernel =3D snd_rme96_playback_copy_kernel, + .copy =3D snd_rme96_playback_copy, .fill_silence =3D snd_rme96_playback_silence, .mmap =3D snd_pcm_lib_mmap_iomem, }; @@ -1556,8 +1531,7 @@ static const struct snd_pcm_ops snd_rme96_capture_ada= t_ops =3D { .prepare =3D snd_rme96_capture_prepare, .trigger =3D snd_rme96_capture_trigger, .pointer =3D snd_rme96_capture_pointer, - .copy_user =3D snd_rme96_capture_copy, - .copy_kernel =3D snd_rme96_capture_copy_kernel, + .copy =3D snd_rme96_capture_copy, .mmap =3D snd_pcm_lib_mmap_iomem, }; =20 --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E04AC04E69 for ; Tue, 15 Aug 2023 19:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239726AbjHOTC4 (ORCPT ); Tue, 15 Aug 2023 15:02:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239757AbjHOTCg (ORCPT ); Tue, 15 Aug 2023 15:02:36 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA2BA2111 for ; Tue, 15 Aug 2023 12:02:14 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0182A219A6; Tue, 15 Aug 2023 19:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126109; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GEM0JpvvNXgVoPGt8/nKe1D2Fu2bJ0X4FKoHDA6Se7U=; b=EibpAQDLAN/yRjiNCq/uE8i3OxdTYBb42hURvRfthILWuqeX+gBir/9W+Pjhz935yylD+o wWs1lT8U+1sxQ0aGvijxUwQcWjUuTOymxaYwwiiZ/giSNilRF+LvQIC35pYlQATUtngoJ3 DRjR9zmMiR6pRTlG94A7EJ3o30fhZoE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126109; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GEM0JpvvNXgVoPGt8/nKe1D2Fu2bJ0X4FKoHDA6Se7U=; b=7JEM6T+II07WgfoPcy/rD9Db457zakf+uG9uEhqMZhR+vrdBuaGL852MElvfV++ae7gXz3 fQHOHQ1224bg5EBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D3DC31353E; Tue, 15 Aug 2023 19:01:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ELXaMpzL22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:48 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 12/25] ALSA: hdsp: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:23 +0200 Message-Id: <20230815190136.8987-13-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the hdsp driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants. Note that copy_from/to_iter() returns the copied bytes, hence the error condition is adjusted accordingly. Signed-off-by: Takashi Iwai --- sound/pci/rme9652/hdsp.c | 42 ++++++---------------------------------- 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c index 65add92c88aa..e7d1b43471a2 100644 --- a/sound/pci/rme9652/hdsp.c +++ b/sound/pci/rme9652/hdsp.c @@ -3961,7 +3961,7 @@ static signed char *hdsp_channel_buffer_location(stru= ct hdsp *hdsp, =20 static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *src, unsigned long count) + struct iov_iter *src, unsigned long count) { struct hdsp *hdsp =3D snd_pcm_substream_chip(substream); signed char *channel_buf; @@ -3972,28 +3972,14 @@ static int snd_hdsp_playback_copy(struct snd_pcm_su= bstream *substream, channel_buf =3D hdsp_channel_buffer_location (hdsp, substream->pstr->stre= am, channel); if (snd_BUG_ON(!channel_buf)) return -EIO; - if (copy_from_user(channel_buf + pos, src, count)) + if (copy_from_iter(channel_buf + pos, count, src) !=3D count) return -EFAULT; return 0; } =20 -static int snd_hdsp_playback_copy_kernel(struct snd_pcm_substream *substre= am, - int channel, unsigned long pos, - void *src, unsigned long count) -{ - struct hdsp *hdsp =3D snd_pcm_substream_chip(substream); - signed char *channel_buf; - - channel_buf =3D hdsp_channel_buffer_location(hdsp, substream->pstr->strea= m, channel); - if (snd_BUG_ON(!channel_buf)) - return -EIO; - memcpy(channel_buf + pos, src, count); - return 0; -} - static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *dst, unsigned long count) + struct iov_iter *dst, unsigned long count) { struct hdsp *hdsp =3D snd_pcm_substream_chip(substream); signed char *channel_buf; @@ -4004,25 +3990,11 @@ static int snd_hdsp_capture_copy(struct snd_pcm_sub= stream *substream, channel_buf =3D hdsp_channel_buffer_location (hdsp, substream->pstr->stre= am, channel); if (snd_BUG_ON(!channel_buf)) return -EIO; - if (copy_to_user(dst, channel_buf + pos, count)) + if (copy_to_iter(channel_buf + pos, count, dst) !=3D count) return -EFAULT; return 0; } =20 -static int snd_hdsp_capture_copy_kernel(struct snd_pcm_substream *substrea= m, - int channel, unsigned long pos, - void *dst, unsigned long count) -{ - struct hdsp *hdsp =3D snd_pcm_substream_chip(substream); - signed char *channel_buf; - - channel_buf =3D hdsp_channel_buffer_location(hdsp, substream->pstr->strea= m, channel); - if (snd_BUG_ON(!channel_buf)) - return -EIO; - memcpy(dst, channel_buf + pos, count); - return 0; -} - static int snd_hdsp_hw_silence(struct snd_pcm_substream *substream, int channel, unsigned long pos, unsigned long count) @@ -4950,8 +4922,7 @@ static const struct snd_pcm_ops snd_hdsp_playback_ops= =3D { .prepare =3D snd_hdsp_prepare, .trigger =3D snd_hdsp_trigger, .pointer =3D snd_hdsp_hw_pointer, - .copy_user =3D snd_hdsp_playback_copy, - .copy_kernel =3D snd_hdsp_playback_copy_kernel, + .copy =3D snd_hdsp_playback_copy, .fill_silence =3D snd_hdsp_hw_silence, }; =20 @@ -4963,8 +4934,7 @@ static const struct snd_pcm_ops snd_hdsp_capture_ops = =3D { .prepare =3D snd_hdsp_prepare, .trigger =3D snd_hdsp_trigger, .pointer =3D snd_hdsp_hw_pointer, - .copy_user =3D snd_hdsp_capture_copy, - .copy_kernel =3D snd_hdsp_capture_copy_kernel, + .copy =3D snd_hdsp_capture_copy, }; =20 static int snd_hdsp_create_hwdep(struct snd_card *card, struct hdsp *hdsp) --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26F83C04A94 for ; Tue, 15 Aug 2023 19:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239708AbjHOTDY (ORCPT ); Tue, 15 Aug 2023 15:03:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239677AbjHOTCx (ORCPT ); Tue, 15 Aug 2023 15:02:53 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49DD3210A for ; Tue, 15 Aug 2023 12:02:32 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 229071FD69; Tue, 15 Aug 2023 19:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126109; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8ySaxeYR4V6QAHTuuwVyisQreRoOordxkp1IR/NdAHw=; b=JbAezIn6LBIFEk3x6CGtLkgEv/YMgYekvaXq4NM4ANDZAyOe8+CkLs2jDJ5dmVBigG+85y D93TbACISwday1+W9N3u+ARGfX+Z8NjAtyxuG0tsf84JVQLELSrBooHT5otSczWpxQbFvO ubYH3SpI8Ekqw0Si5U9jL/HPAx3V5eo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126109; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8ySaxeYR4V6QAHTuuwVyisQreRoOordxkp1IR/NdAHw=; b=9OLjurHIjISj0ca4zZByPgGXlRHLbSqtBscNp5S8Bpf+BXeqyEAdfgAmpaOJYR0Ou4NFoY lztKgEKurYrK9ZCw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 044D91390C; Tue, 15 Aug 2023 19:01:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id MNguAJ3L22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:49 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 13/25] ALSA: rme9652: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:24 +0200 Message-Id: <20230815190136.8987-14-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the rme9652 driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants. Note that copy_from/to_iter() returns the copied bytes, hence the error condition is adjusted accordingly. Signed-off-by: Takashi Iwai --- sound/pci/rme9652/rme9652.c | 46 +++++-------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c index e7c320afefe8..d066c70ae160 100644 --- a/sound/pci/rme9652/rme9652.c +++ b/sound/pci/rme9652/rme9652.c @@ -1844,7 +1844,7 @@ static signed char *rme9652_channel_buffer_location(s= truct snd_rme9652 *rme9652, =20 static int snd_rme9652_playback_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *src, unsigned long count) + struct iov_iter *src, unsigned long count) { struct snd_rme9652 *rme9652 =3D snd_pcm_substream_chip(substream); signed char *channel_buf; @@ -1857,30 +1857,14 @@ static int snd_rme9652_playback_copy(struct snd_pcm= _substream *substream, channel); if (snd_BUG_ON(!channel_buf)) return -EIO; - if (copy_from_user(channel_buf + pos, src, count)) + if (copy_from_iter(channel_buf + pos, count, src) !=3D count) return -EFAULT; return 0; } =20 -static int snd_rme9652_playback_copy_kernel(struct snd_pcm_substream *subs= tream, - int channel, unsigned long pos, - void *src, unsigned long count) -{ - struct snd_rme9652 *rme9652 =3D snd_pcm_substream_chip(substream); - signed char *channel_buf; - - channel_buf =3D rme9652_channel_buffer_location(rme9652, - substream->pstr->stream, - channel); - if (snd_BUG_ON(!channel_buf)) - return -EIO; - memcpy(channel_buf + pos, src, count); - return 0; -} - static int snd_rme9652_capture_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *dst, unsigned long count) + struct iov_iter *dst, unsigned long count) { struct snd_rme9652 *rme9652 =3D snd_pcm_substream_chip(substream); signed char *channel_buf; @@ -1893,27 +1877,11 @@ static int snd_rme9652_capture_copy(struct snd_pcm_= substream *substream, channel); if (snd_BUG_ON(!channel_buf)) return -EIO; - if (copy_to_user(dst, channel_buf + pos, count)) + if (copy_to_iter(channel_buf + pos, count, dst) !=3D count) return -EFAULT; return 0; } =20 -static int snd_rme9652_capture_copy_kernel(struct snd_pcm_substream *subst= ream, - int channel, unsigned long pos, - void *dst, unsigned long count) -{ - struct snd_rme9652 *rme9652 =3D snd_pcm_substream_chip(substream); - signed char *channel_buf; - - channel_buf =3D rme9652_channel_buffer_location(rme9652, - substream->pstr->stream, - channel); - if (snd_BUG_ON(!channel_buf)) - return -EIO; - memcpy(dst, channel_buf + pos, count); - return 0; -} - static int snd_rme9652_hw_silence(struct snd_pcm_substream *substream, int channel, unsigned long pos, unsigned long count) @@ -2370,8 +2338,7 @@ static const struct snd_pcm_ops snd_rme9652_playback_= ops =3D { .prepare =3D snd_rme9652_prepare, .trigger =3D snd_rme9652_trigger, .pointer =3D snd_rme9652_hw_pointer, - .copy_user =3D snd_rme9652_playback_copy, - .copy_kernel =3D snd_rme9652_playback_copy_kernel, + .copy =3D snd_rme9652_playback_copy, .fill_silence =3D snd_rme9652_hw_silence, }; =20 @@ -2383,8 +2350,7 @@ static const struct snd_pcm_ops snd_rme9652_capture_o= ps =3D { .prepare =3D snd_rme9652_prepare, .trigger =3D snd_rme9652_trigger, .pointer =3D snd_rme9652_hw_pointer, - .copy_user =3D snd_rme9652_capture_copy, - .copy_kernel =3D snd_rme9652_capture_copy_kernel, + .copy =3D snd_rme9652_capture_copy, }; =20 static int snd_rme9652_create_pcm(struct snd_card *card, --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C134C07E8C for ; Tue, 15 Aug 2023 19:03:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239806AbjHOTDH (ORCPT ); Tue, 15 Aug 2023 15:03:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239763AbjHOTCg (ORCPT ); Tue, 15 Aug 2023 15:02:36 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A6881BF0 for ; Tue, 15 Aug 2023 12:02:15 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 47406219A7; Tue, 15 Aug 2023 19:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126109; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sornzw8ObUuh4FueGJ820FsFvgO7TY3p6mTQ3GQIfsY=; b=jG0k+hmt8BaiXy++sBlopaHE0hw2JIj6o3if6sRej6jH6sh3dETozZyf7OjdO6VJyxEBcA DaAIQQmToLwNP05Ao8xfIOpkCXn80ZCjOnEK1Huxgcugu5Wf2WqBRRRPfkrpkViAEyCNis SAb6BMZkNH0YRCCe1QYrAhrKG9voK9c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126109; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sornzw8ObUuh4FueGJ820FsFvgO7TY3p6mTQ3GQIfsY=; b=5pnxoJd9EADnJgS8b5Ma0d96iIBpGMCPDpyUF7+4XwEmBylofppoRGs8mULzn0+yKWP+WM nU21cSHRHLR8p6CQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 284C71353E; Tue, 15 Aug 2023 19:01:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uNn7CJ3L22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:49 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 14/25] ALSA: sh: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:25 +0200 Message-Id: <20230815190136.8987-15-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the sh_dac_audio driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants. Signed-off-by: Takashi Iwai --- sound/sh/sh_dac_audio.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/sound/sh/sh_dac_audio.c b/sound/sh/sh_dac_audio.c index 8cf571955c9d..95ba3abd4e47 100644 --- a/sound/sh/sh_dac_audio.c +++ b/sound/sh/sh_dac_audio.c @@ -158,12 +158,12 @@ static int snd_sh_dac_pcm_trigger(struct snd_pcm_subs= tream *substream, int cmd) =20 static int snd_sh_dac_pcm_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *src, unsigned long count) + struct iov_iter *src, unsigned long count) { /* channel is not used (interleaved data) */ struct snd_sh_dac *chip =3D snd_pcm_substream_chip(substream); =20 - if (copy_from_user_toio(chip->data_buffer + pos, src, count)) + if (copy_from_iter_toio(chip->data_buffer + pos, src, count)) return -EFAULT; chip->buffer_end =3D chip->data_buffer + pos + count; =20 @@ -175,24 +175,6 @@ static int snd_sh_dac_pcm_copy(struct snd_pcm_substrea= m *substream, return 0; } =20 -static int snd_sh_dac_pcm_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long pos, - void *src, unsigned long count) -{ - /* channel is not used (interleaved data) */ - struct snd_sh_dac *chip =3D snd_pcm_substream_chip(substream); - - memcpy_toio(chip->data_buffer + pos, src, count); - chip->buffer_end =3D chip->data_buffer + pos + count; - - if (chip->empty) { - chip->empty =3D 0; - dac_audio_start_timer(chip); - } - - return 0; -} - static int snd_sh_dac_pcm_silence(struct snd_pcm_substream *substream, int channel, unsigned long pos, unsigned long count) @@ -227,8 +209,7 @@ static const struct snd_pcm_ops snd_sh_dac_pcm_ops =3D { .prepare =3D snd_sh_dac_pcm_prepare, .trigger =3D snd_sh_dac_pcm_trigger, .pointer =3D snd_sh_dac_pcm_pointer, - .copy_user =3D snd_sh_dac_pcm_copy, - .copy_kernel =3D snd_sh_dac_pcm_copy_kernel, + .copy =3D snd_sh_dac_pcm_copy, .fill_silence =3D snd_sh_dac_pcm_silence, .mmap =3D snd_pcm_lib_mmap_iomem, }; --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C8E7C04FDF for ; Tue, 15 Aug 2023 19:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239673AbjHOTCx (ORCPT ); Tue, 15 Aug 2023 15:02:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239775AbjHOTCi (ORCPT ); Tue, 15 Aug 2023 15:02:38 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEB4810E5 for ; Tue, 15 Aug 2023 12:02:17 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 736141FD6A; Tue, 15 Aug 2023 19:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126109; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K/BgMI8FuOi/5pmBMZAtt3gp913bmnjYvQcbxzOHfHE=; b=nhabCSKsWkx41NfRqAxKgh8FQUXjbeOAtxOYCVMoXsAyxByAjesTZHGSNbtuRbYe9rWpob l/pgaU9eAKtGUJ+w5zfo5Qky1TpOVwKv1YoiTfvx4KZQwdlLea7GH114OMQV9Gjib9bFB0 9JbVbJgcn5fjiqGxhu56qkfvsNm1M/w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126109; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K/BgMI8FuOi/5pmBMZAtt3gp913bmnjYvQcbxzOHfHE=; b=+XKBo0gra+U9kLyDt5tVYGNJHRwve2LRNG7LL5QlEl7517QnhuahhelIchrFC0AdbhSepj n3JcgCWw5rBcIkAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4B7221390C; Tue, 15 Aug 2023 19:01:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wFeVEZ3L22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:49 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai , Oleksandr Andrushchenko , xen-devel@lists.xenproject.org Subject: [PATCH v2 15/25] ALSA: xen: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:26 +0200 Message-Id: <20230815190136.8987-16-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the xen frontend driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants. Note that copy_from/to_iter() returns the copied bytes, hence the error condition is adjusted accordingly. Cc: Oleksandr Andrushchenko Cc: xen-devel@lists.xenproject.org Signed-off-by: Takashi Iwai --- sound/xen/xen_snd_front_alsa.c | 56 +++++++--------------------------- 1 file changed, 11 insertions(+), 45 deletions(-) diff --git a/sound/xen/xen_snd_front_alsa.c b/sound/xen/xen_snd_front_alsa.c index db917453a473..bfae303633ef 100644 --- a/sound/xen/xen_snd_front_alsa.c +++ b/sound/xen/xen_snd_front_alsa.c @@ -602,38 +602,24 @@ static snd_pcm_uframes_t alsa_pointer(struct snd_pcm_= substream *substream) return (snd_pcm_uframes_t)atomic_read(&stream->hw_ptr); } =20 -static int alsa_pb_copy_user(struct snd_pcm_substream *substream, - int channel, unsigned long pos, void __user *src, - unsigned long count) +static int alsa_pb_copy(struct snd_pcm_substream *substream, + int channel, unsigned long pos, struct iov_iter *src, + unsigned long count) { struct xen_snd_front_pcm_stream_info *stream =3D stream_get(substream); =20 if (unlikely(pos + count > stream->buffer_sz)) return -EINVAL; =20 - if (copy_from_user(stream->buffer + pos, src, count)) + if (copy_from_iter(stream->buffer + pos, count, src) !=3D count) return -EFAULT; =20 return xen_snd_front_stream_write(&stream->evt_pair->req, pos, count); } =20 -static int alsa_pb_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long pos, void *src, - unsigned long count) -{ - struct xen_snd_front_pcm_stream_info *stream =3D stream_get(substream); - - if (unlikely(pos + count > stream->buffer_sz)) - return -EINVAL; - - memcpy(stream->buffer + pos, src, count); - - return xen_snd_front_stream_write(&stream->evt_pair->req, pos, count); -} - -static int alsa_cap_copy_user(struct snd_pcm_substream *substream, - int channel, unsigned long pos, void __user *dst, - unsigned long count) +static int alsa_cap_copy(struct snd_pcm_substream *substream, + int channel, unsigned long pos, struct iov_iter *dst, + unsigned long count) { struct xen_snd_front_pcm_stream_info *stream =3D stream_get(substream); int ret; @@ -645,26 +631,8 @@ static int alsa_cap_copy_user(struct snd_pcm_substream= *substream, if (ret < 0) return ret; =20 - return copy_to_user(dst, stream->buffer + pos, count) ? - -EFAULT : 0; -} - -static int alsa_cap_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long pos, void *dst, - unsigned long count) -{ - struct xen_snd_front_pcm_stream_info *stream =3D stream_get(substream); - int ret; - - if (unlikely(pos + count > stream->buffer_sz)) - return -EINVAL; - - ret =3D xen_snd_front_stream_read(&stream->evt_pair->req, pos, count); - if (ret < 0) - return ret; - - memcpy(dst, stream->buffer + pos, count); - + if (copy_to_iter(stream->buffer + pos, count, dst) !=3D count) + return -EFAULT; return 0; } =20 @@ -697,8 +665,7 @@ static const struct snd_pcm_ops snd_drv_alsa_playback_o= ps =3D { .prepare =3D alsa_prepare, .trigger =3D alsa_trigger, .pointer =3D alsa_pointer, - .copy_user =3D alsa_pb_copy_user, - .copy_kernel =3D alsa_pb_copy_kernel, + .copy =3D alsa_pb_copy, .fill_silence =3D alsa_pb_fill_silence, }; =20 @@ -710,8 +677,7 @@ static const struct snd_pcm_ops snd_drv_alsa_capture_op= s =3D { .prepare =3D alsa_prepare, .trigger =3D alsa_trigger, .pointer =3D alsa_pointer, - .copy_user =3D alsa_cap_copy_user, - .copy_kernel =3D alsa_cap_copy_kernel, + .copy =3D alsa_cap_copy, }; =20 static int new_pcm_instance(struct xen_snd_front_card_info *card_info, --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5595FC04FE0 for ; Tue, 15 Aug 2023 19:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239750AbjHOTDA (ORCPT ); Tue, 15 Aug 2023 15:03:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239765AbjHOTCh (ORCPT ); Tue, 15 Aug 2023 15:02:37 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2891810DC for ; Tue, 15 Aug 2023 12:02:17 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9D9751FD6B; Tue, 15 Aug 2023 19:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126109; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NulgZ+I3Oy7nzxJJ1bqwE8Bv2yKQrwT2tCgp2KXuefI=; b=TSDiA7MeXEdjzGY6xLKrSFR8wUeLIr+uapzCpchIYhpqBzucXri8vRhTO+hjpt5sfVutr+ LkOsIG1KGrBu9j5wZegKAUhGE6J2R/mMbZqUhlJr8f9GS6IryuylDWYg6qMoIY9yxrnVbC o70Z9wLdOLtVmMcot8zkCsxhfnlJKKw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126109; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NulgZ+I3Oy7nzxJJ1bqwE8Bv2yKQrwT2tCgp2KXuefI=; b=sDpVxR73Gn8ID8RWy1yIFSPH2YsWcWBFQ8xuNhEOpRS16JDaLJaiabCcs0br3LYWvBYHeQ 83ubIOnsMS878cDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 77DBA1353E; Tue, 15 Aug 2023 19:01:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id SOFpHJ3L22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:49 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 16/25] ALSA: pcmtest: Update comment about PCM copy ops Date: Tue, 15 Aug 2023 21:01:27 +0200 Message-Id: <20230815190136.8987-17-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Just an update of a comment mentioning the old PCM callbacks to correct to the new PCM copy ops. Signed-off-by: Takashi Iwai --- sound/drivers/pcmtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/drivers/pcmtest.c b/sound/drivers/pcmtest.c index 291e7fe47893..d205e10a0605 100644 --- a/sound/drivers/pcmtest.c +++ b/sound/drivers/pcmtest.c @@ -225,7 +225,7 @@ static void check_buf_block(struct pcmtst_buf_iter *v_i= ter, struct snd_pcm_runti =20 /* * Fill buffer in the non-interleaved mode. The order of samples is C0, ..= ., C0, C1, ..., C1, C2... - * The channel buffers lay in the DMA buffer continuously (see default cop= y_user and copy_kernel + * The channel buffers lay in the DMA buffer continuously (see default copy * handlers in the pcm_lib.c file). * * Here we increment the DMA buffer position every time we write a byte to= any channel 'buffer'. --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 073BAC0015E for ; Tue, 15 Aug 2023 19:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239680AbjHOTDV (ORCPT ); Tue, 15 Aug 2023 15:03:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239681AbjHOTCy (ORCPT ); Tue, 15 Aug 2023 15:02:54 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A72126A4; Tue, 15 Aug 2023 12:02:32 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id DF6DF219A8; Tue, 15 Aug 2023 19:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126109; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mhKago/+MCR3o39oTp1UW242sI+KCP3Ja+SPBE1eNiE=; b=of2V5JNXpQ3qurf5n6V2EOUe3/MzV5E49vszJ5xT1Oz1bLEGxP5btcSndkYez9HzQl5LYJ 6c1lSGP6OtxlefJtQfOQpVRNuFqoGVbpflcaGSZMoWvZfP91wCcVwfFFiIF0SzLvfm+Oqs dUtlSwAEJnSIrRyeX90XbreihnnHxuw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126109; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mhKago/+MCR3o39oTp1UW242sI+KCP3Ja+SPBE1eNiE=; b=sfCZqTc2AbugMk0Cqkfjcc5dBZIcUNhuArGYgPrjxJnmYMBQ+BeW6eaVgFyLSD7plWj4MY AUEcGhgRpgRwBRDA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A75931353E; Tue, 15 Aug 2023 19:01:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GLDyJp3L22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:49 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai , Ismael Luceno , Bluecherry Maintainers , Anton Sviridenko , Andrey Utkin , Mauro Carvalho Chehab , linux-media@vger.kernel.org Subject: [PATCH v2 17/25] media: solo6x10: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:28 +0200 Message-Id: <20230815190136.8987-18-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the solo6x10 driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants. As copy_to_iter() updates the internal offest at each write, we can drop the dst counter update in the loop, too. Note that copy_to_iter() returns the copied bytes, hence the error condition is adjusted accordingly. Acked-by: Ismael Luceno Cc: Bluecherry Maintainers Cc: Anton Sviridenko Cc: Andrey Utkin Cc: Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org Signed-off-by: Takashi Iwai Acked-by: Hans Verkuil --- drivers/media/pci/solo6x10/solo6x10-g723.c | 39 ++++------------------ 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci= /solo6x10/solo6x10-g723.c index 6cebad665565..1db9f40ee0c0 100644 --- a/drivers/media/pci/solo6x10/solo6x10-g723.c +++ b/drivers/media/pci/solo6x10/solo6x10-g723.c @@ -204,9 +204,9 @@ static snd_pcm_uframes_t snd_solo_pcm_pointer(struct sn= d_pcm_substream *ss) return idx * G723_FRAMES_PER_PAGE; } =20 -static int snd_solo_pcm_copy_user(struct snd_pcm_substream *ss, int channe= l, - unsigned long pos, void __user *dst, - unsigned long count) +static int snd_solo_pcm_copy(struct snd_pcm_substream *ss, int channel, + unsigned long pos, struct iov_iter *dst, + unsigned long count) { struct solo_snd_pcm *solo_pcm =3D snd_pcm_substream_chip(ss); struct solo_dev *solo_dev =3D solo_pcm->solo_dev; @@ -223,35 +223,9 @@ static int snd_solo_pcm_copy_user(struct snd_pcm_subst= ream *ss, int channel, if (err) return err; =20 - if (copy_to_user(dst, solo_pcm->g723_buf, G723_PERIOD_BYTES)) + if (copy_to_iter(solo_pcm->g723_buf, G723_PERIOD_BYTES, dst) !=3D + G723_PERIOD_BYTES) return -EFAULT; - dst +=3D G723_PERIOD_BYTES; - } - - return 0; -} - -static int snd_solo_pcm_copy_kernel(struct snd_pcm_substream *ss, int chan= nel, - unsigned long pos, void *dst, - unsigned long count) -{ - struct solo_snd_pcm *solo_pcm =3D snd_pcm_substream_chip(ss); - struct solo_dev *solo_dev =3D solo_pcm->solo_dev; - int err, i; - - for (i =3D 0; i < (count / G723_FRAMES_PER_PAGE); i++) { - int page =3D (pos / G723_FRAMES_PER_PAGE) + i; - - err =3D solo_p2m_dma_t(solo_dev, 0, solo_pcm->g723_dma, - SOLO_G723_EXT_ADDR(solo_dev) + - (page * G723_PERIOD_BLOCK) + - (ss->number * G723_PERIOD_BYTES), - G723_PERIOD_BYTES, 0, 0); - if (err) - return err; - - memcpy(dst, solo_pcm->g723_buf, G723_PERIOD_BYTES); - dst +=3D G723_PERIOD_BYTES; } =20 return 0; @@ -263,8 +237,7 @@ static const struct snd_pcm_ops snd_solo_pcm_ops =3D { .prepare =3D snd_solo_pcm_prepare, .trigger =3D snd_solo_pcm_trigger, .pointer =3D snd_solo_pcm_pointer, - .copy_user =3D snd_solo_pcm_copy_user, - .copy_kernel =3D snd_solo_pcm_copy_kernel, + .copy =3D snd_solo_pcm_copy, }; =20 static int snd_solo_capture_volume_info(struct snd_kcontrol *kcontrol, --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9848C04FE2 for ; Tue, 15 Aug 2023 19:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239820AbjHOTDj (ORCPT ); Tue, 15 Aug 2023 15:03:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239774AbjHOTDD (ORCPT ); Tue, 15 Aug 2023 15:03:03 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 012362682 for ; Tue, 15 Aug 2023 12:02:41 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 11D391FD6D; Tue, 15 Aug 2023 19:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EVJBJqPljS5bAtrXtcs5yvyG9sJCsx+H498Fzf+ebP8=; b=LJ3Llucs5fEtsVSJqxidWvwZ5vJte0yiYczTi7CCxSXG0uBVgsFC1gy2wFyq4UtGedhTN5 A7nv4Tr6DO6onRlu6BiFcPSBy/qBtMqZ163y1g7RTjvnsdYi/XB/k/Opxcm1/pTSqcmESj Zpp3ijOCf7CD/utuOjH3xX8l/D0ySb0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EVJBJqPljS5bAtrXtcs5yvyG9sJCsx+H498Fzf+ebP8=; b=K/fwRmStEqMBlXOO9VFb2ww+c5O3zZw0VqwlRd438AVKbaWcmPAK2zDzX9v/XGVQTHpvMf TMBHc8nyEJgHqkBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E31081390C; Tue, 15 Aug 2023 19:01:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aIuPNp3L22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:49 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai , Mark Brown Subject: [PATCH v2 18/25] ASoC: component: Add generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:29 +0200 Message-Id: <20230815190136.8987-19-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" For following the ALSA PCM core change, a new PCM copy ops is added toe ASoC component framework: snd_soc_component_driver receives the copy ops, and snd_soc_pcm_component_copy() helper is provided. This also fixes a long-standing potential bug where the ASoC driver covers only copy_user PCM callback and misses the copy from kernel pointers (such as OSS PCM layer), too. As of this patch, the old copy_user is still kept, but it'll be dropped later after all drivers are converted. Reviewed-by: Mark Brown Signed-off-by: Takashi Iwai --- include/sound/soc-component.h | 7 +++++++ sound/soc/soc-component.c | 18 ++++++++++++++++++ sound/soc/soc-pcm.c | 4 +++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 87f248a06271..8040f001f2fb 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -141,6 +141,10 @@ struct snd_soc_component_driver { struct snd_pcm_substream *substream, int channel, unsigned long pos, void __user *buf, unsigned long bytes); + int (*copy)(struct snd_soc_component *component, + struct snd_pcm_substream *substream, int channel, + unsigned long pos, struct iov_iter *buf, + unsigned long bytes); struct page *(*page)(struct snd_soc_component *component, struct snd_pcm_substream *substream, unsigned long offset); @@ -512,6 +516,9 @@ int snd_soc_pcm_component_sync_stop(struct snd_pcm_subs= tream *substream); int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, int channel, unsigned long pos, void __user *buf, unsigned long bytes); +int snd_soc_pcm_component_copy(struct snd_pcm_substream *substream, + int channel, unsigned long pos, + struct iov_iter *buf, unsigned long bytes); struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substrea= m, unsigned long offset); int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream, diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index 4356cc320fea..ffa2dd8a21ba 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -1052,6 +1052,24 @@ int snd_soc_pcm_component_sync_stop(struct snd_pcm_s= ubstream *substream) return 0; } =20 +int snd_soc_pcm_component_copy(struct snd_pcm_substream *substream, + int channel, unsigned long pos, + struct iov_iter *buf, unsigned long bytes) +{ + struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); + struct snd_soc_component *component; + int i; + + /* FIXME. it returns 1st copy now */ + for_each_rtd_components(rtd, i, component) + if (component->driver->copy) + return soc_component_ret(component, + component->driver->copy(component, substream, + channel, pos, buf, bytes)); + + return -EINVAL; +} + int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, int channel, unsigned long pos, void __user *buf, unsigned long bytes) diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 8896227e4fb7..71403da28d37 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -2973,7 +2973,9 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int = num) rtd->ops.ioctl =3D snd_soc_pcm_component_ioctl; if (drv->sync_stop) rtd->ops.sync_stop =3D snd_soc_pcm_component_sync_stop; - if (drv->copy_user) + if (drv->copy) + rtd->ops.copy =3D snd_soc_pcm_component_copy; + else if (drv->copy_user) rtd->ops.copy_user =3D snd_soc_pcm_component_copy_user; if (drv->page) rtd->ops.page =3D snd_soc_pcm_component_page; --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8FACC04FE1 for ; Tue, 15 Aug 2023 19:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239829AbjHOTDl (ORCPT ); Tue, 15 Aug 2023 15:03:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239786AbjHOTDF (ORCPT ); Tue, 15 Aug 2023 15:03:05 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11BAA2683 for ; Tue, 15 Aug 2023 12:02:42 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 380D51FD6E; Tue, 15 Aug 2023 19:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D6ETb9fq7HCS4tFLoqPg7xnmdjK64qt8f71hdCKXa8k=; b=Srfm4UIYpzYCy+pYQArW4SxQonZ5+jWY7nv/E7sBGpPswXQHq7983vZb9/d1dGCW7SO2Xf nniw5P4lwgYZZ2DXM9TI0nkgulDgihioKeeIV8dhrXmm9tVXrpnsHVsUH8nMbD4Y6YlSGr 4L4rjJw2xd8/m86Y4d35oC3CFciiTbk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D6ETb9fq7HCS4tFLoqPg7xnmdjK64qt8f71hdCKXa8k=; b=i0q7ZsVZIbbzD8jgYdc2BErt+pTjvH+NSFNlrHYEq9UewDlu0/IcP4xjSNq5UPOj4I6RDo qiogmyqMORJFJoBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1544D1353E; Tue, 15 Aug 2023 19:01:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WMhdBJ7L22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:50 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai , Mark Brown Subject: [PATCH v2 19/25] ASoC: mediatek: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:30 +0200 Message-Id: <20230815190136.8987-20-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the mediatek BT SCO driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants. As copy_form/to_iter() updates the internal offset at each read/write, we can drop the cur_*_idx counter in the loop, too. Note that copy_from/to_iter() returns the copied bytes, hence the error condition is adjusted accordingly. Reviewed-by: Mark Brown Signed-off-by: Takashi Iwai --- sound/soc/mediatek/common/mtk-btcvsd.c | 27 ++++++++++---------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/sound/soc/mediatek/common/mtk-btcvsd.c b/sound/soc/mediatek/co= mmon/mtk-btcvsd.c index 1ba0633e542f..c12d170fa1de 100644 --- a/sound/soc/mediatek/common/mtk-btcvsd.c +++ b/sound/soc/mediatek/common/mtk-btcvsd.c @@ -696,11 +696,10 @@ static int wait_for_bt_irq(struct mtk_btcvsd_snd *bt, } =20 static ssize_t mtk_btcvsd_snd_read(struct mtk_btcvsd_snd *bt, - char __user *buf, + struct iov_iter *buf, size_t count) { ssize_t read_size =3D 0, read_count =3D 0, cur_read_idx, cont; - unsigned int cur_buf_ofs =3D 0; unsigned long avail; unsigned long flags; unsigned int packet_size =3D bt->rx->packet_size; @@ -743,10 +742,9 @@ static ssize_t mtk_btcvsd_snd_read(struct mtk_btcvsd_s= nd *bt, if (read_size > cont) read_size =3D cont; =20 - if (copy_to_user(buf + cur_buf_ofs, - bt->rx_packet_buf + cur_read_idx, - read_size)) { - dev_warn(bt->dev, "%s(), copy_to_user fail\n", + if (copy_to_iter(bt->rx_packet_buf + cur_read_idx, + read_size, buf) !=3D read_size) { + dev_warn(bt->dev, "%s(), copy_to_iter fail\n", __func__); return -EFAULT; } @@ -756,7 +754,6 @@ static ssize_t mtk_btcvsd_snd_read(struct mtk_btcvsd_sn= d *bt, spin_unlock_irqrestore(&bt->rx_lock, flags); =20 read_count +=3D read_size; - cur_buf_ofs +=3D read_size; count -=3D read_size; } =20 @@ -777,11 +774,10 @@ static ssize_t mtk_btcvsd_snd_read(struct mtk_btcvsd_= snd *bt, } =20 static ssize_t mtk_btcvsd_snd_write(struct mtk_btcvsd_snd *bt, - char __user *buf, + struct iov_iter *buf, size_t count) { int written_size =3D count, avail, cur_write_idx, write_size, cont; - unsigned int cur_buf_ofs =3D 0; unsigned long flags; unsigned int packet_size =3D bt->tx->packet_size; =20 @@ -835,11 +831,9 @@ static ssize_t mtk_btcvsd_snd_write(struct mtk_btcvsd_= snd *bt, if (write_size > cont) write_size =3D cont; =20 - if (copy_from_user(bt->tx_packet_buf + - cur_write_idx, - buf + cur_buf_ofs, - write_size)) { - dev_warn(bt->dev, "%s(), copy_from_user fail\n", + if (copy_from_iter(bt->tx_packet_buf + cur_write_idx, + write_size, buf) !=3D write_size) { + dev_warn(bt->dev, "%s(), copy_from_iter fail\n", __func__); return -EFAULT; } @@ -847,7 +841,6 @@ static ssize_t mtk_btcvsd_snd_write(struct mtk_btcvsd_s= nd *bt, spin_lock_irqsave(&bt->tx_lock, flags); bt->tx->packet_w +=3D write_size / packet_size; spin_unlock_irqrestore(&bt->tx_lock, flags); - cur_buf_ofs +=3D write_size; count -=3D write_size; } =20 @@ -1033,7 +1026,7 @@ static snd_pcm_uframes_t mtk_pcm_btcvsd_pointer( static int mtk_pcm_btcvsd_copy(struct snd_soc_component *component, struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *buf, unsigned long count) + struct iov_iter *buf, unsigned long count) { struct mtk_btcvsd_snd *bt =3D snd_soc_component_get_drvdata(component); =20 @@ -1274,7 +1267,7 @@ static const struct snd_soc_component_driver mtk_btcv= sd_snd_platform =3D { .prepare =3D mtk_pcm_btcvsd_prepare, .trigger =3D mtk_pcm_btcvsd_trigger, .pointer =3D mtk_pcm_btcvsd_pointer, - .copy_user =3D mtk_pcm_btcvsd_copy, + .copy =3D mtk_pcm_btcvsd_copy, }; =20 static int mtk_btcvsd_snd_probe(struct platform_device *pdev) --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE935C07E8A for ; Tue, 15 Aug 2023 19:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239837AbjHOTDn (ORCPT ); Tue, 15 Aug 2023 15:03:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239791AbjHOTDF (ORCPT ); Tue, 15 Aug 2023 15:03:05 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 300B21FD4 for ; Tue, 15 Aug 2023 12:02:43 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6744B1FD6F; Tue, 15 Aug 2023 19:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7KZcjZJEL1AUmZfArsYWETPc96FRe6MC2Sdf2yaw4uU=; b=0C0PMJTlr/UvmiwxiiCfTrWVk2r3ILdwphrfgHX+RWaEVZa1CCzLADXJ+VKhaeLAw+CbgL PQBJ0vF326cSBCB4ByN0Bx13jCgQSmX0Tz+3mu0Ff+PQ7UlOeoUd0QvvtTtq2ntUBM4N7R dIlmEzmnYHf7q+pq+guUZH1Ovq8cc40= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7KZcjZJEL1AUmZfArsYWETPc96FRe6MC2Sdf2yaw4uU=; b=v+T/Kwjg9tmLlOfOkpi/rf0WgCWsA20OpT2+xEfMPeGw4LU4QdfheMVTb1n0sTd/Y0E+yU irzyxYs4lkotHvDw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3D5401353E; Tue, 15 Aug 2023 19:01:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id yMIRDp7L22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:50 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai , Mark Brown , Srinivas Kandagatla , Banajit Goswami Subject: [PATCH v2 20/25] ASoC: qcom: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:31 +0200 Message-Id: <20230815190136.8987-21-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the qcom lpass driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants. Note that copy_from/to_iter() returns the copied bytes, hence the error condition is adjusted accordingly. Reviewed-by: Mark Brown Cc: Srinivas Kandagatla Cc: Banajit Goswami Signed-off-by: Takashi Iwai --- sound/soc/qcom/lpass-platform.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platfor= m.c index ef5cb40b2d9b..990d7c33f90f 100644 --- a/sound/soc/qcom/lpass-platform.c +++ b/sound/soc/qcom/lpass-platform.c @@ -1219,7 +1219,8 @@ static int lpass_platform_pcmops_resume(struct snd_so= c_component *component) =20 static int lpass_platform_copy(struct snd_soc_component *component, struct snd_pcm_substream *substream, int channel, - unsigned long pos, void __user *buf, unsigned long bytes) + unsigned long pos, struct iov_iter *buf, + unsigned long bytes) { struct snd_pcm_runtime *rt =3D substream->runtime; unsigned int dai_id =3D component->id; @@ -1230,16 +1231,16 @@ static int lpass_platform_copy(struct snd_soc_compo= nent *component, =20 if (substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK) { if (is_cdc_dma_port(dai_id)) { - ret =3D copy_from_user_toio(dma_buf, buf, bytes); + ret =3D copy_from_iter_toio(dma_buf, buf, bytes); } else { - if (copy_from_user((void __force *)dma_buf, buf, bytes)) + if (copy_from_iter((void __force *)dma_buf, bytes, buf) !=3D bytes) ret =3D -EFAULT; } } else if (substream->stream =3D=3D SNDRV_PCM_STREAM_CAPTURE) { if (is_cdc_dma_port(dai_id)) { - ret =3D copy_to_user_fromio(buf, dma_buf, bytes); + ret =3D copy_to_iter_fromio(buf, dma_buf, bytes); } else { - if (copy_to_user(buf, (void __force *)dma_buf, bytes)) + if (copy_to_iter((void __force *)dma_buf, bytes, buf) !=3D bytes) ret =3D -EFAULT; } } @@ -1260,7 +1261,7 @@ static const struct snd_soc_component_driver lpass_co= mponent_driver =3D { .pcm_construct =3D lpass_platform_pcm_new, .suspend =3D lpass_platform_pcmops_suspend, .resume =3D lpass_platform_pcmops_resume, - .copy_user =3D lpass_platform_copy, + .copy =3D lpass_platform_copy, =20 }; =20 --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79636C41513 for ; Tue, 15 Aug 2023 19:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239789AbjHOTDf (ORCPT ); Tue, 15 Aug 2023 15:03:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239768AbjHOTDD (ORCPT ); Tue, 15 Aug 2023 15:03:03 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BCA62681 for ; Tue, 15 Aug 2023 12:02:41 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 92CDB219AB; Tue, 15 Aug 2023 19:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AoYuahFv9jY9TJIQezpvBTUC7RKI1JDEmMCNFlRwbQU=; b=HFlsEFfpJhddTfmlbA88RQm9z2/PARL8ZYymbiJTyFFcGyykZJKzEnfgaQ9+2OUJ20Hjep 8mdHAmx+90TWzwgkOVgPPRU7rp8Y538ZbnSqH399WslW2sK1+u2EXjFjVAhYZ9QxGTrTOB YEG9G9drermuiSry0wP7mGkUkZyQjC8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AoYuahFv9jY9TJIQezpvBTUC7RKI1JDEmMCNFlRwbQU=; b=H7+rZg0RDu+leJTafpFZYEIXnx5iBQbYiF56ix+ByDMib7O1FgaNUGTft2AnWfym2DKlka y9IiK0NNiMz9YTCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6B3A91390C; Tue, 15 Aug 2023 19:01:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EKtOGZ7L22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:50 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai , Mark Brown , Lars-Peter Clausen Subject: [PATCH v2 21/25] ASoC: dmaengine: Convert to generic PCM copy ops Date: Tue, 15 Aug 2023 21:01:32 +0200 Message-Id: <20230815190136.8987-22-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch converts the ASoC dmaenging driver code to use the new unified PCM copy callback. It's a straightforward conversion from *_user() to *_iter() variants. The process callback is still using the direct pointer as of now, but it'll be converted in the next patch. Note that copy_from/to_iter() returns the copied bytes, hence the error condition is adjusted accordingly. Reviewed-by: Mark Brown Cc: Lars-Peter Clausen Signed-off-by: Takashi Iwai --- sound/soc/soc-generic-dmaengine-pcm.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-= dmaengine-pcm.c index 3b99f619e37e..f2cb75781566 100644 --- a/sound/soc/soc-generic-dmaengine-pcm.c +++ b/sound/soc/soc-generic-dmaengine-pcm.c @@ -287,10 +287,10 @@ static snd_pcm_uframes_t dmaengine_pcm_pointer( return snd_dmaengine_pcm_pointer(substream); } =20 -static int dmaengine_copy_user(struct snd_soc_component *component, - struct snd_pcm_substream *substream, - int channel, unsigned long hwoff, - void __user *buf, unsigned long bytes) +static int dmaengine_copy(struct snd_soc_component *component, + struct snd_pcm_substream *substream, + int channel, unsigned long hwoff, + struct iov_iter *buf, unsigned long bytes) { struct snd_pcm_runtime *runtime =3D substream->runtime; struct dmaengine_pcm *pcm =3D soc_component_to_pcm(component); @@ -300,19 +300,20 @@ static int dmaengine_copy_user(struct snd_soc_compone= nt *component, bool is_playback =3D substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK; void *dma_ptr =3D runtime->dma_area + hwoff + channel * (runtime->dma_bytes / runtime->channels); + void *ptr =3D (void __force *)iter_iov_addr(buf); =20 if (is_playback) - if (copy_from_user(dma_ptr, buf, bytes)) + if (copy_from_iter(dma_ptr, bytes, buf) !=3D bytes) return -EFAULT; =20 if (process) { - int ret =3D process(substream, channel, hwoff, (__force void *)buf, byte= s); + int ret =3D process(substream, channel, hwoff, ptr, bytes); if (ret < 0) return ret; } =20 if (!is_playback) - if (copy_to_user(buf, dma_ptr, bytes)) + if (copy_to_iter(dma_ptr, bytes, buf) !=3D bytes) return -EFAULT; =20 return 0; @@ -337,7 +338,7 @@ static const struct snd_soc_component_driver dmaengine_= pcm_component_process =3D { .hw_params =3D dmaengine_pcm_hw_params, .trigger =3D dmaengine_pcm_trigger, .pointer =3D dmaengine_pcm_pointer, - .copy_user =3D dmaengine_copy_user, + .copy =3D dmaengine_copy, .pcm_construct =3D dmaengine_pcm_new, }; =20 --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68C61C04E69 for ; Tue, 15 Aug 2023 19:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239752AbjHOTDc (ORCPT ); Tue, 15 Aug 2023 15:03:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239730AbjHOTC4 (ORCPT ); Tue, 15 Aug 2023 15:02:56 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5B7A2133 for ; Tue, 15 Aug 2023 12:02:38 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CC8291FD70; Tue, 15 Aug 2023 19:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=62EgIloqhA+hcLk/4OBOeWiYMDU41CiAUCQbyVwWNP0=; b=tal2WdM3yUfMr2BHj04XTNgYz0GkxkaYuAo8LQnwHU8DfOOy84eaQZq4LNe3mGepqw0Tlb PZOKVO3N02i4i7dn7l/VO7QXw1KM+rCL4HH4ys36AlFBiHY/ypa7SeXsDHQCEKaEndB+4F ydHQ3YIQNiSWZx1aq2uazDIHR/EmYaw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=62EgIloqhA+hcLk/4OBOeWiYMDU41CiAUCQbyVwWNP0=; b=lwscZ13Wsg2Jj270Y2Bv2EJPxhgDy86ZgM+fteNNw5OOGvx9Z4f3TIom9WWB4iCYAxA2L7 xYFEh9LQvDkSr4Bg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9871D1353E; Tue, 15 Aug 2023 19:01:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oGIpJJ7L22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:50 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai , Mark Brown , Lars-Peter Clausen , Claudiu Beznea , Olivier Moysan , Arnaud Pouliquen Subject: [PATCH v2 22/25] ASoC: dmaengine: Use iov_iter for process callback, too Date: Tue, 15 Aug 2023 21:01:33 +0200 Message-Id: <20230815190136.8987-23-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Along with the conversion to PCM copy ops, use the iov_iter for the pointer to be passed to the dmaengine process callback, too. It avoids the direct reference of iter_iov_addr(), and it can potentially help for the drivers to access memory properly (although both atmel and stm drivers don't use the given buffer address at all for now). Reviewed-by: Mark Brown Cc: Lars-Peter Clausen Cc: Claudiu Beznea Cc: Olivier Moysan Cc: Arnaud Pouliquen Signed-off-by: Takashi Iwai --- include/sound/dmaengine_pcm.h | 2 +- sound/soc/atmel/mchp-pdmc.c | 2 +- sound/soc/soc-generic-dmaengine-pcm.c | 5 ++--- sound/soc/stm/stm32_sai_sub.c | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/sound/dmaengine_pcm.h b/include/sound/dmaengine_pcm.h index 2df54cf02cb3..c9a8bce9a785 100644 --- a/include/sound/dmaengine_pcm.h +++ b/include/sound/dmaengine_pcm.h @@ -142,7 +142,7 @@ struct snd_dmaengine_pcm_config { struct snd_pcm_substream *substream); int (*process)(struct snd_pcm_substream *substream, int channel, unsigned long hwoff, - void *buf, unsigned long bytes); + struct iov_iter *buf, unsigned long bytes); dma_filter_fn compat_filter_fn; struct device *dma_dev; const char *chan_names[SNDRV_PCM_STREAM_LAST + 1]; diff --git a/sound/soc/atmel/mchp-pdmc.c b/sound/soc/atmel/mchp-pdmc.c index c79c73e6791e..b3afcf25b4a9 100644 --- a/sound/soc/atmel/mchp-pdmc.c +++ b/sound/soc/atmel/mchp-pdmc.c @@ -962,7 +962,7 @@ static int mchp_pdmc_dt_init(struct mchp_pdmc *dd) /* used to clean the channel index found on RHR's MSB */ static int mchp_pdmc_process(struct snd_pcm_substream *substream, int channel, unsigned long hwoff, - void *buf, unsigned long bytes) + struct iov_iter *buf, unsigned long bytes) { struct snd_pcm_runtime *runtime =3D substream->runtime; u8 *dma_ptr =3D runtime->dma_area + hwoff + diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-= dmaengine-pcm.c index f2cb75781566..ff2166525dbc 100644 --- a/sound/soc/soc-generic-dmaengine-pcm.c +++ b/sound/soc/soc-generic-dmaengine-pcm.c @@ -296,18 +296,17 @@ static int dmaengine_copy(struct snd_soc_component *c= omponent, struct dmaengine_pcm *pcm =3D soc_component_to_pcm(component); int (*process)(struct snd_pcm_substream *substream, int channel, unsigned long hwoff, - void *buf, unsigned long bytes) =3D pcm->config->process; + struct iov_iter *buf, unsigned long bytes) =3D pcm->config->proce= ss; bool is_playback =3D substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK; void *dma_ptr =3D runtime->dma_area + hwoff + channel * (runtime->dma_bytes / runtime->channels); - void *ptr =3D (void __force *)iter_iov_addr(buf); =20 if (is_playback) if (copy_from_iter(dma_ptr, bytes, buf) !=3D bytes) return -EFAULT; =20 if (process) { - int ret =3D process(substream, channel, hwoff, ptr, bytes); + int ret =3D process(substream, channel, hwoff, buf, bytes); if (ret < 0) return ret; } diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c index 271ec5b3378d..39f9b4654fa2 100644 --- a/sound/soc/stm/stm32_sai_sub.c +++ b/sound/soc/stm/stm32_sai_sub.c @@ -1233,7 +1233,7 @@ static const struct snd_soc_dai_ops stm32_sai_pcm_dai= _ops =3D { =20 static int stm32_sai_pcm_process_spdif(struct snd_pcm_substream *substream, int channel, unsigned long hwoff, - void *buf, unsigned long bytes) + struct iov_iter *buf, unsigned long bytes) { struct snd_pcm_runtime *runtime =3D substream->runtime; struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 514D6C04FDF for ; Tue, 15 Aug 2023 19:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239741AbjHOTDb (ORCPT ); Tue, 15 Aug 2023 15:03:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239715AbjHOTCz (ORCPT ); Tue, 15 Aug 2023 15:02:55 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 630C8212D for ; Tue, 15 Aug 2023 12:02:37 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id F2EE0219AC; Tue, 15 Aug 2023 19:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126110; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T8//wcNQwPthyNc3xqkx3W41Gepnl5c0ocQ4zcQs/T8=; b=IGa8I5Ln4UTWznZ12OCFML9vAayTcN026IZSEjabIagp72t1e1c9A0mFNWJunhP7x9Iswf q8ToEOIPtVn0vQEdPcj95rqfyLWRvK2JaHnO5WPo0p4h+ErAfclHjnXOFdXwhxfrmhwtfE m22f2sVTq8wHF2HlR0yaKa5Hv4ciDS4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126111; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T8//wcNQwPthyNc3xqkx3W41Gepnl5c0ocQ4zcQs/T8=; b=2R+RcxgtIgD+uo64NiNryZWEe5dGUW9Cqz4v2tT8ELTkQGaeBGBoTpbBckveuirdMDVJKt bt/XDwlXZ6Acd1Dw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D19EC1390C; Tue, 15 Aug 2023 19:01:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GCcvMp7L22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:50 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 23/25] ALSA: doc: Update description for the new PCM copy ops Date: Tue, 15 Aug 2023 21:01:34 +0200 Message-Id: <20230815190136.8987-24-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Update the documentation about the PCM copy callbacks. The update was kept minimalistic, just correcting the use of copy_user ops with the single copy ops, and drop/update the text mentioning the copy_kernel. Signed-off-by: Takashi Iwai --- .../kernel-api/writing-an-alsa-driver.rst | 58 ++++++------------- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/Documentation/sound/kernel-api/writing-an-alsa-driver.rst b/Do= cumentation/sound/kernel-api/writing-an-alsa-driver.rst index 4335c98b3d82..cd421856409e 100644 --- a/Documentation/sound/kernel-api/writing-an-alsa-driver.rst +++ b/Documentation/sound/kernel-api/writing-an-alsa-driver.rst @@ -2018,8 +2018,8 @@ sleeping poll threads, etc. =20 This callback is also atomic by default. =20 -copy_user, copy_kernel and fill_silence ops -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +copy and fill_silence ops +~~~~~~~~~~~~~~~~~~~~~~~~~ =20 These callbacks are not mandatory, and can be omitted in most cases. These callbacks are used when the hardware buffer cannot be in the @@ -3444,8 +3444,8 @@ external hardware buffer in interrupts (or in tasklet= s, preferably). =20 The first case works fine if the external hardware buffer is large enough. This method doesn't need any extra buffers and thus is more -efficient. You need to define the ``copy_user`` and ``copy_kernel`` -callbacks for the data transfer, in addition to the ``fill_silence`` +efficient. You need to define the ``copy`` callback +for the data transfer, in addition to the ``fill_silence`` callback for playback. However, there is a drawback: it cannot be mmapped. The examples are GUS's GF1 PCM or emu8000's wavetable PCM. =20 @@ -3458,22 +3458,22 @@ Another case is when the chip uses a PCI memory-map= region for the buffer instead of the host memory. In this case, mmap is available only on certain architectures like the Intel one. In non-mmap mode, the data cannot be transferred as in the normal way. Thus you need to define the -``copy_user``, ``copy_kernel`` and ``fill_silence`` callbacks as well, +``copy`` and ``fill_silence`` callbacks as well, as in the cases above. Examples are found in ``rme32.c`` and ``rme96.c``. =20 -The implementation of the ``copy_user``, ``copy_kernel`` and +The implementation of the ``copy`` and ``silence`` callbacks depends upon whether the hardware supports -interleaved or non-interleaved samples. The ``copy_user`` callback is +interleaved or non-interleaved samples. The ``copy`` callback is defined like below, a bit differently depending on whether the direction is playback or capture:: =20 - static int playback_copy_user(struct snd_pcm_substream *substream, + static int playback_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *src, unsigned long count); - static int capture_copy_user(struct snd_pcm_substream *substream, + struct iov_iter *src, unsigned long count); + static int capture_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, - void __user *dst, unsigned long count); + struct iov_iter *dst, unsigned long count); =20 In the case of interleaved samples, the second argument (``channel``) is not used. The third argument (``pos``) specifies the position in bytes. @@ -3490,18 +3490,17 @@ of data (``count``) at the specified pointer (``src= ``) to the specified offset (``pos``) in the hardware buffer. When coded like memcpy-like way, the copy would look like:: =20 - my_memcpy_from_user(my_buffer + pos, src, count); + my_memcpy_from_iter(my_buffer + pos, src, count); =20 For the capture direction, you copy the given amount of data (``count``) at the specified offset (``pos``) in the hardware buffer to the specified pointer (``dst``):: =20 - my_memcpy_to_user(dst, my_buffer + pos, count); + my_memcpy_to_iter(dst, my_buffer + pos, count); =20 -Here the functions are named ``from_user`` and ``to_user`` because -it's the user-space buffer that is passed to these callbacks. That -is, the callback is supposed to copy data from/to the user-space -directly to/from the hardware buffer. +The given ``src`` or ``dst`` a struct iov_iter pointer containing the +pointer and the size. Use the existing helpers to copy or access the +data as defined in ``linux/uio.h``. =20 Careful readers might notice that these callbacks receive the arguments in bytes, not in frames like other callbacks. It's because @@ -3519,25 +3518,6 @@ the given user-space buffer, but only for the given = channel. For details, please check ``isa/gus/gus_pcm.c`` or ``pci/rme9652/rme9652.c`` as examples. =20 -The above callbacks are the copies from/to the user-space buffer. There -are some cases where we want to copy from/to the kernel-space buffer -instead. In such a case, the ``copy_kernel`` callback is called. It'd -look like:: - - static int playback_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long pos, - void *src, unsigned long count); - static int capture_copy_kernel(struct snd_pcm_substream *substream, - int channel, unsigned long pos, - void *dst, unsigned long count); - -As found easily, the only difference is that the buffer pointer is -without a ``__user`` prefix; that is, a kernel-buffer pointer is passed -in the fourth argument. Correspondingly, the implementation would be -a version without the user-copy, such as:: - - my_memcpy(my_buffer + pos, src, count); - Usually for the playback, another callback ``fill_silence`` is defined. It's implemented in a similar way as the copy callbacks above:: @@ -3545,10 +3525,10 @@ above:: static int silence(struct snd_pcm_substream *substream, int channel, unsigned long pos, unsigned long count); =20 -The meanings of arguments are the same as in the ``copy_user`` and -``copy_kernel`` callbacks, although there is no buffer pointer +The meanings of arguments are the same as in the ``copy`` callback, +although there is no buffer pointer argument. In the case of interleaved samples, the channel argument has -no meaning, as for the ``copy_*`` callbacks. +no meaning, as for the ``copy`` callback. =20 The role of the ``fill_silence`` callback is to set the given amount (``count``) of silence data at the specified offset (``pos``) in the --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F744C3DA40 for ; Tue, 15 Aug 2023 19:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239729AbjHOTD1 (ORCPT ); Tue, 15 Aug 2023 15:03:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239722AbjHOTCz (ORCPT ); Tue, 15 Aug 2023 15:02:55 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEAC41BF0 for ; Tue, 15 Aug 2023 12:02:37 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 304B5219AD; Tue, 15 Aug 2023 19:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126111; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LiqXzAgJEKHlp1AZFo+uKtC6D/wVCSD9GdB9VXlnpF4=; b=Pd5UtkVHp+fHJxaC9wG7YZ3G5hosm7/XkLmE842clgRYk7qf6iImCSoaGQkViJF9yjn9lw 1nArvvU/wv8UNYx0Gcr0jTSyNUOPkL/KPAmd/bZdKjAbhbXtubyUhPtHAxs3YHg8XLoMtI KX8E/IJWbElYHCZbY4rahgM1x9fnQFc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126111; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LiqXzAgJEKHlp1AZFo+uKtC6D/wVCSD9GdB9VXlnpF4=; b=GqB4FIqK68pJtv2CVcjLVMwKVWcW9mNIGoZzTnZWFsz6VXxq+pLEvDj90afoIgtpPJLvsw t+MJsynamhcKLwCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 02CB81353E; Tue, 15 Aug 2023 19:01:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8IhLO57L22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:50 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai , Mark Brown Subject: [PATCH v2 24/25] ASoC: pcm: Drop obsoleted PCM copy_user ops Date: Tue, 15 Aug 2023 21:01:35 +0200 Message-Id: <20230815190136.8987-25-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Now all ASoC users have been replaced to use the new PCM copy ops, let's drop the obsoleted copy_user ops and its helper function. Reviewed-by: Mark Brown Signed-off-by: Takashi Iwai --- include/sound/soc-component.h | 7 ------- sound/soc/soc-component.c | 20 -------------------- sound/soc/soc-pcm.c | 2 -- 3 files changed, 29 deletions(-) diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h index 8040f001f2fb..17bea3144551 100644 --- a/include/sound/soc-component.h +++ b/include/sound/soc-component.h @@ -137,10 +137,6 @@ struct snd_soc_component_driver { struct timespec64 *audio_ts, struct snd_pcm_audio_tstamp_config *audio_tstamp_config, struct snd_pcm_audio_tstamp_report *audio_tstamp_report); - int (*copy_user)(struct snd_soc_component *component, - struct snd_pcm_substream *substream, int channel, - unsigned long pos, void __user *buf, - unsigned long bytes); int (*copy)(struct snd_soc_component *component, struct snd_pcm_substream *substream, int channel, unsigned long pos, struct iov_iter *buf, @@ -513,9 +509,6 @@ int snd_soc_pcm_component_pointer(struct snd_pcm_substr= eam *substream); int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg); int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream); -int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, - int channel, unsigned long pos, - void __user *buf, unsigned long bytes); int snd_soc_pcm_component_copy(struct snd_pcm_substream *substream, int channel, unsigned long pos, struct iov_iter *buf, unsigned long bytes); diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c index ffa2dd8a21ba..f18406dfa1e4 100644 --- a/sound/soc/soc-component.c +++ b/sound/soc/soc-component.c @@ -1070,26 +1070,6 @@ int snd_soc_pcm_component_copy(struct snd_pcm_substr= eam *substream, return -EINVAL; } =20 -int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, - int channel, unsigned long pos, - void __user *buf, unsigned long bytes) -{ - struct snd_soc_pcm_runtime *rtd =3D asoc_substream_to_rtd(substream); - struct snd_soc_component *component; - int i; - - /* FIXME. it returns 1st copy now */ - for_each_rtd_components(rtd, i, component) - if (component->driver->copy_user) - return soc_component_ret( - component, - component->driver->copy_user( - component, substream, channel, - pos, buf, bytes)); - - return -EINVAL; -} - struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substrea= m, unsigned long offset) { diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 71403da28d37..ae02d1d80c88 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -2975,8 +2975,6 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int = num) rtd->ops.sync_stop =3D snd_soc_pcm_component_sync_stop; if (drv->copy) rtd->ops.copy =3D snd_soc_pcm_component_copy; - else if (drv->copy_user) - rtd->ops.copy_user =3D snd_soc_pcm_component_copy_user; if (drv->page) rtd->ops.page =3D snd_soc_pcm_component_page; if (drv->mmap) --=20 2.35.3 From nobody Wed Dec 17 23:52:49 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99DA4C04FE0 for ; Tue, 15 Aug 2023 19:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239813AbjHOTDh (ORCPT ); Tue, 15 Aug 2023 15:03:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239767AbjHOTDD (ORCPT ); Tue, 15 Aug 2023 15:03:03 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B39A2680 for ; Tue, 15 Aug 2023 12:02:41 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 48A48219AE; Tue, 15 Aug 2023 19:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1692126111; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DzfPkrsHVrap+B5JD7fqRR+3BmI5kvbs99homa/INDo=; b=juoT+uObn3CD0krY/i+cNkxP7QHDHI8/HrUuKScmdoZ50YMYYKJDz5tAx7miJATHux4YDw 6zdAFTaFHzbXO7A2TwSxxG0cH7HU/BNwnnGPDeGe5ohkywxpyRykvRuDMHpzZTAnTOY+2f 36C3K8C4jtGCZ9kQvAxvZ16xmbc8LTE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1692126111; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DzfPkrsHVrap+B5JD7fqRR+3BmI5kvbs99homa/INDo=; b=wc+3KYgI+GLwVih151IBlS+fSQFRm/wbGbNniZOWs9nQh/ueciFj6VekaqpydoXQhg/BiS rCnbCJJrtTJNpAAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2893D1390C; Tue, 15 Aug 2023 19:01:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0IEJCZ/L22QTVAAAMHmgww (envelope-from ); Tue, 15 Aug 2023 19:01:51 +0000 From: Takashi Iwai To: alsa-devel@alsa-project.org Cc: linux-kernel@vger.kernel.org, Takashi Iwai Subject: [PATCH v2 25/25] ALSA: pcm: Drop obsoleted PCM copy_user and copy_kernel ops Date: Tue, 15 Aug 2023 21:01:36 +0200 Message-Id: <20230815190136.8987-26-tiwai@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230815190136.8987-1-tiwai@suse.de> References: <20230815190136.8987-1-tiwai@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Finally all users have been converted to the new PCM copy ops, let's drop the obsoleted copy_kernel and copy_user ops completely. Signed-off-by: Takashi Iwai --- include/sound/pcm.h | 5 ----- sound/core/pcm_lib.c | 18 +----------------- sound/core/pcm_native.c | 2 +- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/include/sound/pcm.h b/include/sound/pcm.h index f75beead79e3..958a0b284b5f 100644 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -71,11 +71,6 @@ struct snd_pcm_ops { unsigned long pos, unsigned long bytes); int (*copy)(struct snd_pcm_substream *substream, int channel, unsigned long pos, struct iov_iter *iter, unsigned long bytes); - int (*copy_user)(struct snd_pcm_substream *substream, int channel, - unsigned long pos, void __user *buf, - unsigned long bytes); - int (*copy_kernel)(struct snd_pcm_substream *substream, int channel, - unsigned long pos, void *buf, unsigned long bytes); struct page *(*page)(struct snd_pcm_substream *substream, unsigned long offset); int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *v= ma); diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 3303914c58ea..4859fb1caec9 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -2031,19 +2031,6 @@ static int default_read_copy(struct snd_pcm_substrea= m *substream, return 0; } =20 -/* a wrapper for calling old copy_kernel or copy_user ops */ -static int call_old_copy(struct snd_pcm_substream *substream, - int channel, unsigned long hwoff, - struct iov_iter *iter, unsigned long bytes) -{ - if (iov_iter_is_kvec(iter)) - return substream->ops->copy_kernel(substream, channel, hwoff, - iter_iov_addr(iter), bytes); - else - return substream->ops->copy_user(substream, channel, hwoff, - iter_iov_addr(iter), bytes); -} - /* call transfer with the filled iov_iter */ static int do_transfer(struct snd_pcm_substream *substream, int c, unsigned long hwoff, void *data, unsigned long bytes, @@ -2147,7 +2134,7 @@ static int pcm_sanity_check(struct snd_pcm_substream = *substream) if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime =3D substream->runtime; - if (snd_BUG_ON(!substream->ops->copy && !substream->ops->copy_user && !ru= ntime->dma_area)) + if (snd_BUG_ON(!substream->ops->copy && !runtime->dma_area)) return -EINVAL; if (runtime->state =3D=3D SNDRV_PCM_STATE_OPEN) return -EBADFD; @@ -2255,9 +2242,6 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_s= ubstream *substream, } else { if (substream->ops->copy) transfer =3D substream->ops->copy; - else if ((in_kernel && substream->ops->copy_kernel) || - (!in_kernel && substream->ops->copy_user)) - transfer =3D call_old_copy; else transfer =3D is_playback ? default_write_copy : default_read_copy; diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index 34efd4d198d6..bd9ddf412b46 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -809,7 +809,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *= substream, runtime->boundary *=3D 2; =20 /* clear the buffer for avoiding possible kernel info leaks */ - if (runtime->dma_area && !substream->ops->copy && !substream->ops->copy_u= ser) { + if (runtime->dma_area && !substream->ops->copy) { size_t size =3D runtime->dma_bytes; =20 if (runtime->info & SNDRV_PCM_INFO_MMAP) --=20 2.35.3