From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8CE4C5DF61 for ; Thu, 7 Nov 2019 10:50:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A8756214D8 for ; Thu, 7 Nov 2019 10:50:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388109AbfKGKuZ (ORCPT ); Thu, 7 Nov 2019 05:50:25 -0500 Received: from mx2.suse.de ([195.135.220.15]:59350 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727528AbfKGKuZ (ORCPT ); Thu, 7 Nov 2019 05:50:25 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D984FB2CD; Thu, 7 Nov 2019 10:50:22 +0000 (UTC) Date: Thu, 07 Nov 2019 11:50:22 +0100 Message-ID: From: Takashi Iwai To: "Gabbasov, Andrew" Cc: "alsa-devel@alsa-project.org" , "linux-kernel@vger.kernel.org" , "Jaroslav Kysela" , Takashi Iwai , Timo Wischer Subject: Re: [PATCH v2 8/8] ALSA: aloop: Support runtime change of snd_timer via info interface In-Reply-To: <2dc6e7841e97441aa3b91fca8e5629e9@svr-ies-mbx-02.mgc.mentorg.com> References: <20191105143218.5948-1-andrew_gabbasov@mentor.com> <20191105143218.5948-2-andrew_gabbasov@mentor.com> <20191105143218.5948-3-andrew_gabbasov@mentor.com> <20191105143218.5948-4-andrew_gabbasov@mentor.com> <20191105143218.5948-5-andrew_gabbasov@mentor.com> <20191105143218.5948-6-andrew_gabbasov@mentor.com> <20191105143218.5948-7-andrew_gabbasov@mentor.com> <20191105143218.5948-8-andrew_gabbasov@mentor.com> <20191105143218.5948-9-andrew_gabbasov@mentor.com> <2dc6e7841e97441aa3b91fca8e5629e9@svr-ies-mbx-02.mgc.mentorg.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 07 Nov 2019 11:40:18 +0100, Gabbasov, Andrew wrote: > > Hello Takashi, > > Thank you very much for your feedback! > > > -----Original Message----- > > From: Takashi Iwai [mailto:tiwai@suse.de] > > Sent: Thursday, November 07, 2019 11:06 AM > > To: Gabbasov, Andrew > > Cc: alsa-devel@alsa-project.org; linux-kernel@vger.kernel.org; Jaroslav > > Kysela; Takashi Iwai; Timo Wischer > > Subject: Re: [PATCH v2 8/8] ALSA: aloop: Support runtime change of > > snd_timer via info interface > > > > On Tue, 05 Nov 2019 15:32:18 +0100, > > Andrew Gabbasov wrote: > > > > > > Show and change sound card timer source with read-write info > > > file in proc filesystem. Initial string can still be set as > > > module parameter. > > > > > > The timer source string value can be changed at any time, > > > but it is latched by PCM substream open callback (the first one > > > for a particular cable). At this point it is actually used, that > > > is the string is parsed, and the timer is looked up and opened. > > > > > > The timer source is set for a loopback card (the same as initial > > > setting by module parameter), but every cable uses the value, > > > current at the moment of open. > > > > > > Setting the value to empty string switches the timer to jiffies. > > > > > > Signed-off-by: Andrew Gabbasov > > > > Unfortunately the whole code here are racy. It may lead to a crash or > > use-after-free easily. Some locking is needed definitely. > > You are right, using and changing of loopback->timer_source should be protected. > I'll add locking with loopback->cable_lock to the bodies of print_timer_source_info() > and change_timer_source_info() (like in the example diff below), similarly to other > /proc files and mixer controls. All other uses of loopback->timer_source are already > covered by loopback->cable_lock, except for loopback_set_timer_source() call from > loopback_probe(), that is done at the very early stage and doesn't conflict with other > uses. I think, in order to avoid racing problems, this will be enough, won't it? Yes, I guess so. loopback_set_timer_source() replaces only the timer_source and it's referred only at opening a stream. thanks, Takashi > > Thanks. > > Best regards, > Andrew > > diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c > index 415128a97774..ca9307dd780e 100644 > --- a/sound/drivers/aloop.c > +++ b/sound/drivers/aloop.c > @@ -1684,8 +1684,10 @@ static void print_timer_source_info(struct snd_info_entry *entry, > { > struct loopback *loopback = entry->private_data; > > + mutex_lock(&loopback->cable_lock); > snd_iprintf(buffer, "%s\n", > loopback->timer_source ? loopback->timer_source : ""); > + mutex_unlock(&loopback->cable_lock); > } > > static void change_timer_source_info(struct snd_info_entry *entry, > @@ -1694,8 +1696,10 @@ static void change_timer_source_info(struct snd_info_entry *entry, > struct loopback *loopback = entry->private_data; > char line[64]; > > + mutex_lock(&loopback->cable_lock); > if (!snd_info_get_line(buffer, line, sizeof(line))) > loopback_set_timer_source(loopback, strim(line)); > + mutex_unlock(&loopback->cable_lock); > } > > static int loopback_timer_source_proc_new(struct loopback *loopback) >