diff mbox

[MC,Next,Gen,v3,4/6] sound/usb: Fix media_stream_init() and media_stream_delete() error paths

Message ID 249a5b1eb3463167d2aef448265d638bf90c72f2.1447184001.git.shuahkh@osg.samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Shuah Khan Nov. 10, 2015, 8:40 p.m. UTC
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 <shuahkh@osg.samsung.com>
---
 sound/usb/media.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox

Patch

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;
 	}