From patchwork Tue Nov 10 20:40:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 7592201 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C0B2DC05CA for ; Tue, 10 Nov 2015 20:47:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DED31205EB for ; Tue, 10 Nov 2015 20:47:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F41A3205F9 for ; Tue, 10 Nov 2015 20:47:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751618AbbKJUrD (ORCPT ); Tue, 10 Nov 2015 15:47:03 -0500 Received: from resqmta-po-05v.sys.comcast.net ([96.114.154.164]:46201 "EHLO resqmta-po-05v.sys.comcast.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751371AbbKJUq5 (ORCPT ); Tue, 10 Nov 2015 15:46:57 -0500 Received: from resomta-po-18v.sys.comcast.net ([96.114.154.242]) by resqmta-po-05v.sys.comcast.net with comcast id fwm91r0075E3ZMc01wmw4v; Tue, 10 Nov 2015 20:46:56 +0000 Received: from mail.gonehiking.org ([73.181.52.62]) by resomta-po-18v.sys.comcast.net with comcast id fwmw1r00K1LXgTt01wmwz4; Tue, 10 Nov 2015 20:46:56 +0000 Received: from lorien.internal (lorien-wl.internal [192.168.1.40]) by mail.gonehiking.org (Postfix) with ESMTP id 494839F378; Tue, 10 Nov 2015 13:40:55 -0700 (MST) From: Shuah Khan To: mchehab@osg.samsung.com, tiwai@suse.de, perex@perex.cz, chehabrafael@gmail.com, hans.verkuil@cisco.com, prabhakar.csengg@gmail.com, chris.j.arges@canonical.com Cc: Shuah Khan , linux-media@vger.kernel.org, alsa-devel@alsa-project.org Subject: [PATCH MC Next Gen v3 4/6] sound/usb: Fix media_stream_init() and media_stream_delete() error paths Date: Tue, 10 Nov 2015 13:40:47 -0700 Message-Id: <249a5b1eb3463167d2aef448265d638bf90c72f2.1447184001.git.shuahkh@osg.samsung.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: In-Reply-To: References: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1447188416; bh=D8HPYSBmZpUdUztm9m5Tqp6lNLKFwdjD4V8nrmNwbac=; h=Received:Received:Received:From:To:Subject:Date:Message-Id; b=KINQPAcwKCF9R0gfJQ378vRRFMLjuyMlgQH+gDguVNIuf5GdQG3vm+ZOGuw4OQ828 7XsbDLjmg66orS5P1s4xfpC7q8xjBZHGS5u+cent7t+TwD/+Ln6JmE8lYwDmvt8rww NEYnhbQ5K20UgzQ7yhb3fQfBo3dA3R1IWw4xP4ZifrspdUBV3kTrNlzK+WuMG2EOcT ghN6AqWHzeREtkgVdEow2VLtY85ikex4oECYHx/ymCs3c4/zC4CArStVOaja61FItd lLlq9YwA6VOdXhiiNbllWTMldpC8O67ssuLu1gv+x4OAWTEZqKlIqlj3lIaNPtguX6 L3set7GqSP+Bg== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix media_stream_init() to free memory in error paths. Fix media_stream_delete() to remove unnecessary set media_dev pointer to null before free mctl. Signed-off-by: Shuah Khan --- sound/usb/media.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sound/usb/media.c b/sound/usb/media.c index 6df346a..bebe27b 100644 --- a/sound/usb/media.c +++ b/sound/usb/media.c @@ -127,7 +127,6 @@ int media_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm, if (!mctl) return -ENOMEM; - subs->media_ctl = (void *) mctl; mctl->media_dev = mdev; if (stream == SNDRV_PCM_STREAM_PLAYBACK) { intf_type = MEDIA_INTF_T_ALSA_PCM_PLAYBACK; @@ -143,13 +142,16 @@ int media_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm, media_entity_init(&mctl->media_entity, 1, &mctl->media_pad); ret = media_device_register_entity(mctl->media_dev, &mctl->media_entity); - if (ret) + if (ret) { + kfree(mctl); return ret; + } mctl->intf_devnode = media_devnode_create(mdev, intf_type, 0, MAJOR(pcm_dev->devt), MINOR(pcm_dev->devt)); if (!mctl->intf_devnode) { media_device_unregister_entity(&mctl->media_entity); + kfree(mctl); return -ENOMEM; } mctl->intf_link = media_create_intf_link(&mctl->media_entity, @@ -158,8 +160,10 @@ int media_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm, if (!mctl->intf_link) { media_devnode_remove(mctl->intf_devnode); media_device_unregister_entity(&mctl->media_entity); + kfree(mctl); return -ENOMEM; } + subs->media_ctl = (void *) mctl; return 0; } @@ -177,7 +181,6 @@ void media_stream_delete(struct snd_usb_substream *subs) media_device_unregister_entity(&mctl->media_entity); media_entity_cleanup(&mctl->media_entity); } - mctl->media_dev = NULL; kfree(mctl); subs->media_ctl = NULL; }