From: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
To: Shuah Khan <shuahkh@osg.samsung.com>
Cc: tiwai@suse.com, perex@perex.cz, linux-media@vger.kernel.org,
alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sound/usb: fix to release stream resources from media_snd_device_delete()
Date: Sat, 19 Mar 2016 07:39:44 -0300 [thread overview]
Message-ID: <20160319073944.60235d88@recife.lan> (raw)
In-Reply-To: <20160318235708.1eccf0e6@recife.lan>
Em Fri, 18 Mar 2016 23:57:08 -0300
Mauro Carvalho Chehab <mchehab@osg.samsung.com> escreveu:
> Em Fri, 18 Mar 2016 20:50:31 -0600
> Shuah Khan <shuahkh@osg.samsung.com> escreveu:
>
> > Fix to release stream resources from media_snd_device_delete() before
> > media device is unregistered. Without this change, stream resource free
> > is attempted after the media device is unregistered which would result
> > in use-after-free errors.
> >
> > Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
> > ---
> >
> > - Ran bind/unbind loop (1000 iteration) test on snd-usb-audio
> > while running mc_nextgen_test loop (1000 iterations) in parallel.
> > - Ran bind/unbind and rmmod/modprobe tests on both drivers. Also
> > generated graphs when after bind/unbind, rmmod/modprobe. Graphs
> > look good.
> > - Note: Please apply the following patch to fix memory leak:
> > sound/usb: Fix memory leak in media_snd_stream_delete() during unbind
> > https://lkml.org/lkml/2016/3/16/1050
> >
> > sound/usb/media.c | 7 +++++++
> > 1 file changed, 7 insertions(+)
> >
> > diff --git a/sound/usb/media.c b/sound/usb/media.c
> > index de4a815..e35af88 100644
> > --- a/sound/usb/media.c
> > +++ b/sound/usb/media.c
> > @@ -301,6 +301,13 @@ int media_snd_device_create(struct snd_usb_audio *chip,
> > void media_snd_device_delete(struct snd_usb_audio *chip)
> > {
> > struct media_device *mdev = chip->media_dev;
> > + struct snd_usb_stream *stream;
> > +
> > + /* release resources */
> > + list_for_each_entry(stream, &chip->pcm_list, list) {
> > + media_snd_stream_delete(&stream->substream[0]);
> > + media_snd_stream_delete(&stream->substream[1]);
>
> I'll look on it better tomorrow, but it sounds weird to hardcode
> substream[0] and [1] here... are you sure that this is valid for
> *all* devices supported by snd-usb-audio?
After looking at pcm.c and finding this:
static void snd_usb_audio_stream_free(struct snd_usb_stream *stream)
{
free_substream(&stream->substream[0]);
free_substream(&stream->substream[1]);
list_del(&stream->list);
kfree(stream);
}
It seems that assuming that substream is always an array with size 2
is right.
I'll do some tests with it today with your patch.
Regards,
Mauro
>
> Regards,
> Mauro
>
> > + }
> >
> > media_snd_mixer_delete(chip);
> >
>
>
--
Thanks,
Mauro
next prev parent reply other threads:[~2016-03-19 10:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-19 2:50 [PATCH] sound/usb: fix to release stream resources from media_snd_device_delete() Shuah Khan
2016-03-19 2:57 ` Mauro Carvalho Chehab
2016-03-19 10:39 ` Mauro Carvalho Chehab [this message]
2016-03-19 13:25 ` Shuah Khan
2016-03-19 12:10 ` Mauro Carvalho Chehab
2016-03-19 13:31 ` Shuah Khan
2016-03-22 4:01 ` Shuah Khan
2016-03-22 13:03 ` Shuah Khan
2016-03-22 17:29 ` Shuah Khan
2016-03-22 17:37 ` Mauro Carvalho Chehab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160319073944.60235d88@recife.lan \
--to=mchehab@osg.samsung.com \
--cc=alsa-devel@alsa-project.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=perex@perex.cz \
--cc=shuahkh@osg.samsung.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).