From nobody Mon Feb 9 20:10:13 2026 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