[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <s5hlfss2c5t.wl-tiwai@suse.de>
Date: Thu, 07 Nov 2019 11:50:22 +0100
From: Takashi Iwai <tiwai@...e.de>
To: "Gabbasov, Andrew" <Andrew_Gabbasov@...tor.com>
Cc: "alsa-devel@...a-project.org" <alsa-devel@...a-project.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"Jaroslav Kysela" <perex@...ex.cz>, Takashi Iwai <tiwai@...e.com>,
Timo Wischer <twischer@...adit-jv.com>
Subject: Re: [PATCH v2 8/8] ALSA: aloop: Support runtime change of snd_timer via info interface
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@...e.de]
> > Sent: Thursday, November 07, 2019 11:06 AM
> > To: Gabbasov, Andrew
> > Cc: alsa-devel@...a-project.org; linux-kernel@...r.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 <andrew_gabbasov@...tor.com>
> >
> > 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)
>
Powered by blists - more mailing lists