Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10709604rwp; Fri, 21 Jul 2023 03:53:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlHdU+3a3oSednrZP9YDFXH7YKIcdAUA4Y1iIUxNOg7Qn8xIQfdhXmaOP0QIXXhJeYQ6sDJn X-Received: by 2002:a05:6358:9218:b0:134:cbff:c5a4 with SMTP id d24-20020a056358921800b00134cbffc5a4mr1788157rwb.18.1689936797988; Fri, 21 Jul 2023 03:53:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689936797; cv=none; d=google.com; s=arc-20160816; b=dBGpi6vC4Mqe9sZM3ZDjcQ0pAlwwLpLaLaXzHMZfe/71hR/o4l3MEemPI+sDMd9SzB rWc7DtaIj4H6XiM0JiyMBzRjLk7/QmJ4VaUbgqBaXjlM/aD3Hv1ytZ5KufCe969NlMUV f3Ol+bqStb7l/iGl91KyrUea72p8aLZGi2i9jKpXoKWZq5wEvpHTk7x83SPXdiJGObKt YgnVQoOMN+5cm1IRCmxYgFt/KiHcEKzJzLcQDszOmKoanSn2LVeGfcVT+41JnyXwE7wt dIWND0KmXO3c5Ytkazssbo05QzCKATLD4BD1A7+HZzkorYFlyEtERy7g66cZtePfKKJ+ V0Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=Ltp3vgBxTSOzGDIs46F3JngbLBYC+fyTISiSirvL/h0=; fh=wqYxEPYBezYUGOgBsTpeNqcUccS4oguhg+YVLMrNbVA=; b=R4r96GeJ8YFcbr4XXUWjvh9iJhcbdJqpgkEAEjV+TLWylKOfgOcdkWYVE9Ufyn35FU yRzb9vcryjttLKV6daJ3t8dcHPc1PO4HcW6HH7YSoD6UYs3kWSyv72rTlMNPogazSULB zmg5PhgIbyviJAVonTa90llaFTsAL8N+KbTKlrFnEAUAXe7tRrpGURM3UH+irvGWMU5i DLiT5S3+OegFMNSY6FQYuAEb47nE1nT53MUEyKQQaJ2gP3cvQqVf3Yf4dV1Nr0wfqqQU Rf9scZtD3AU/+QLLucMgnzBSfPkKsARJkz3xMk2fZKquTcKnoEiZDsHpCrLU52xMKOlq qrBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=HC0YGgZz; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a16-20020a63e410000000b00553b54585e9si2655265pgi.696.2023.07.21.03.53.05; Fri, 21 Jul 2023 03:53:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=HC0YGgZz; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230160AbjGUKIy (ORCPT + 99 others); Fri, 21 Jul 2023 06:08:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229751AbjGUKIw (ORCPT ); Fri, 21 Jul 2023 06:08:52 -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 7C782171A for ; Fri, 21 Jul 2023 03:08:48 -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 EAC3321873; Fri, 21 Jul 2023 10:08:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1689934126; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Ltp3vgBxTSOzGDIs46F3JngbLBYC+fyTISiSirvL/h0=; b=HC0YGgZzSAspp6B+lbyX4pKPh42PM4hz+tRDI09fep4mse2BjHK/ZoP8EuBk3/zeA1iXyC sMnk0JORalFxDqZj3K9ILqZsBst85OUrz2iKpHWRmuHuoUuo5IpVeQhObpH2c3Dq2qm6ZY PM6JA5JnmztR4ziJWnMQKQvKupydABw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1689934126; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Ltp3vgBxTSOzGDIs46F3JngbLBYC+fyTISiSirvL/h0=; b=a1MOJTVg5/HvtCnMrHuFIV3/W5wqKWTq9NIUHksjHwQpibdfWfg72Itz3IIUVGmpKXGm8F ysCMdFEWXvdEATDQ== 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 C1855134BA; Fri, 21 Jul 2023 10:08:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 3xonLi5ZumS2BgAAMHmgww (envelope-from ); Fri, 21 Jul 2023 10:08:46 +0000 Date: Fri, 21 Jul 2023 12:08:46 +0200 Message-ID: <878rb9h901.wl-tiwai@suse.de> From: Takashi Iwai To: Andy Shevchenko Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Jaroslav Kysela , Takashi Iwai , Dan Williams Subject: Re: [PATCH v1 1/1] ALSA: korg1212: Re-use sockptr_t and respective APIs In-Reply-To: <20230721100146.67293-1-andriy.shevchenko@linux.intel.com> References: <20230721100146.67293-1-andriy.shevchenko@linux.intel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 21 Jul 2023 12:01:46 +0200, Andy Shevchenko wrote: > > The sockptr_t (despite the naming) is a generic type to hold kernel > or user pointer and there are respective APIs to copy data to or > from it. Replace open coded variants in the driver by them. While I see the benefit, I feel this is very confusing. If we use the API for a generic use, it should be renamed at first. Also, the current function actually follows the call pattern, and we know in the caller side whether it's called for a kernel pointer or a user pointer. So, if any, the PCM core callbacks should be revised to use a generic pointer instead of fiddling in each driver side. thanks, Takashi > > Signed-off-by: Andy Shevchenko > --- > sound/pci/korg1212/korg1212.c | 33 +++++++++++++-------------------- > 1 file changed, 13 insertions(+), 20 deletions(-) > > diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c > index 33b4f95d65b3..92c3eab4d12c 100644 > --- a/sound/pci/korg1212/korg1212.c > +++ b/sound/pci/korg1212/korg1212.c > @@ -10,6 +10,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -1285,8 +1286,7 @@ static int snd_korg1212_silence(struct snd_korg1212 *korg1212, int pos, int coun > } > > static int snd_korg1212_copy_to(struct snd_pcm_substream *substream, > - void __user *dst, int pos, int count, > - bool in_kernel) > + sockptr_t dst, int pos, int count) > { > struct snd_pcm_runtime *runtime = substream->runtime; > struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); > @@ -1306,24 +1306,21 @@ static int snd_korg1212_copy_to(struct snd_pcm_substream *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=%p dst=%p iter=%d\n", src, dst, i); > + printk(KERN_DEBUG "K1212_DEBUG: %s KERNEL EFAULT, src=%p dst=%p iter=%d\n", > + __func__, src, sockptr_is_kernel(dst) ? dst.kernel : dst.user, i); > return -EFAULT; > } > #endif > - if (in_kernel) > - memcpy((__force void *)dst, src, size); > - else if (copy_to_user(dst, src, size)) > + if (copy_to_sockptr_offset(dst, i * size, src, size)) > return -EFAULT; > src++; > - dst += size; > } > > return 0; > } > > static int snd_korg1212_copy_from(struct snd_pcm_substream *substream, > - void __user *src, int pos, int count, > - bool in_kernel) > + sockptr_t src, int pos, int count) > { > struct snd_pcm_runtime *runtime = substream->runtime; > struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream); > @@ -1345,16 +1342,14 @@ static int snd_korg1212_copy_from(struct snd_pcm_substream *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, src=%p dst=%p iter=%d\n", src, dst, i); > + printk(KERN_DEBUG "K1212_DEBUG: %s KERNEL EFAULT, src=%p dst=%p iter=%d\n", > + __func__, sockptr_is_kernel(src) ? src.kernel : src.user, 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_sockptr_offset(dst, src, i * size, size)) > return -EFAULT; > dst++; > - src += size; > } > > return 0; > @@ -1644,15 +1639,14 @@ static int snd_korg1212_playback_copy(struct snd_pcm_substream *substream, > int channel, unsigned long pos, > void __user *src, unsigned long count) > { > - return snd_korg1212_copy_from(substream, src, pos, count, false); > + return snd_korg1212_copy_from(substream, USER_SOCKPTR(src), pos, count); > } > > static int snd_korg1212_playback_copy_kernel(struct snd_pcm_substream *substream, > 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, KERNEL_SOCKPTR(src), pos, count); > } > > static int snd_korg1212_playback_silence(struct snd_pcm_substream *substream, > @@ -1672,15 +1666,14 @@ static int snd_korg1212_capture_copy(struct snd_pcm_substream *substream, > int channel, unsigned long pos, > void __user *dst, unsigned long count) > { > - return snd_korg1212_copy_to(substream, dst, pos, count, false); > + return snd_korg1212_copy_to(substream, USER_SOCKPTR(dst), pos, count); > } > > static int snd_korg1212_capture_copy_kernel(struct snd_pcm_substream *substream, > 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, KERNEL_SOCKPTR(dst), pos, count); > } > > static const struct snd_pcm_ops snd_korg1212_playback_ops = { > -- > 2.40.0.1.gaa8946217a0b >