From patchwork Sat Mar 19 02:50:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 8624781 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A2A469F44D for ; Sat, 19 Mar 2016 02:51:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C2A9A2041A for ; Sat, 19 Mar 2016 02:51:01 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 371CE2042C for ; Sat, 19 Mar 2016 02:51:00 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id A9CD1266705; Sat, 19 Mar 2016 03:50:58 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 7C10A2617B8; Sat, 19 Mar 2016 03:50:51 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id D0CBB261AAB; Sat, 19 Mar 2016 03:50:49 +0100 (CET) Received: from mailout.easymail.ca (mailout.easymail.ca [64.68.201.169]) by alsa0.perex.cz (Postfix) with ESMTP id CA5592615F7 for ; Sat, 19 Mar 2016 03:50:43 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mailout.easymail.ca (Postfix) with ESMTP id 2428FF63D; Fri, 18 Mar 2016 22:50:38 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at mailout.easymail.ca Received: from mailout.easymail.ca ([127.0.0.1]) by localhost (easymail-mailout.easydns.vpn [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4SKwA-ZwczvC; Fri, 18 Mar 2016 22:50:33 -0400 (EDT) Received: from mail.gonehiking.org (c-73-181-52-62.hsd1.co.comcast.net [73.181.52.62]) by mailout.easymail.ca (Postfix) with ESMTPA id F2A94F636; Fri, 18 Mar 2016 22:50:32 -0400 (EDT) Received: from lorien.internal (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id A17CD9F2D3; Fri, 18 Mar 2016 20:50:32 -0600 (MDT) From: Shuah Khan To: mchehab@osg.samsung.com, tiwai@suse.com, perex@perex.cz Date: Fri, 18 Mar 2016 20:50:31 -0600 Message-Id: <1458355831-9467-1-git-send-email-shuahkh@osg.samsung.com> X-Mailer: git-send-email 2.5.0 Cc: linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Shuah Khan , linux-media@vger.kernel.org Subject: [alsa-devel] [PATCH] sound/usb: fix to release stream resources from media_snd_device_delete() X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Tested-by: Mauro Carvalho Chehab --- - 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]); + } media_snd_mixer_delete(chip);