[linux-dvb] [patch 2.6.12-rc4-dvb-cvs 13/14] dvb: error code checking in dvb_dmxdev_init

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Error code checking in dvb_dmxdev_init

Fix a few missing checks and plug the leaks.

Signed-off-by: Francois Romieu <romieu@xxxxxxxxxxxxx>

diff -puN drivers/media/dvb/dvb-core/dmxdev.c~dvb-240 drivers/media/dvb/dvb-core/dmxdev.c
--- a/drivers/media/dvb/dvb-core/dmxdev.c~dvb-240	2005-05-20 19:40:44.000204195 +0200
+++ b/drivers/media/dvb/dvb-core/dmxdev.c	2005-05-20 19:40:44.003203705 +0200
@@ -1087,21 +1087,19 @@ dvb_dmxdev_init(struct dmxdev *dmxdev, s
 {
 	const int filternum = dmxdev->filternum;
 	struct dmx_demux *dmx = &dmxdev->demux;
-	int i;
-
-	if (dmx->open(dmx) < 0)
-		return -EUSERS;
+	int i, rc = -ENOMEM;
 
 	dmxdev->filter = vmalloc(filternum*sizeof(struct dmxdev_filter));
 	if (!dmxdev->filter)
-		return -ENOMEM;
+		goto out;
 
 	dmxdev->dvr = vmalloc(filternum*sizeof(struct dmxdev_dvr));
-	if (!dmxdev->dvr) {
-		vfree(dmxdev->filter);
-		dmxdev->filter = NULL;
-		return -ENOMEM;
-	}
+	if (!dmxdev->dvr)
+		goto err_vfree_filter_0;
+
+	rc = dmx->open(dmx);
+	if (rc < 0)
+		goto err_vfree_dvr_1;
 
 	sema_init(&dmxdev->mutex, 1);
 	spin_lock_init(&dmxdev->lock);
@@ -1118,12 +1116,30 @@ dvb_dmxdev_init(struct dmxdev *dmxdev, s
 		dvb_dmxdev_dvr_state_set(dvr, DMXDEV_STATE_FREE);
 	}
 
-	dvb_register_device(dvb_adapter, &dmxdev->dvbdev, &dvbdev_demux, dmxdev, DVB_DEVICE_DEMUX);
-	dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, &dvbdev_dvr, dmxdev, DVB_DEVICE_DVR);
+	rc = dvb_register_device(dvb_adapter, &dmxdev->dvbdev, &dvbdev_demux,
+				 dmxdev, DVB_DEVICE_DEMUX);
+	if (rc < 0)
+		goto err_close_dmx_2;
+
+	rc = dvb_register_device(dvb_adapter, &dmxdev->dvr_dvbdev, &dvbdev_dvr,
+				 dmxdev, DVB_DEVICE_DVR);
+	if (rc < 0)
+		goto err_unregister_device_3;
 
 	dvb_dmxdev_buffer_init(&dmxdev->dvr_buffer);
+out:
+	return rc;
 
-	return 0;
+err_unregister_device_3:
+	dvb_unregister_device(dmxdev->dvbdev);
+err_close_dmx_2:
+	dmx->close(dmx);
+err_vfree_dvr_1:
+	vfree(dmxdev->dvr);
+err_vfree_filter_0:
+	vfree(dmxdev->filter);
+	dmxdev->filter = NULL;
+	goto out;
 }
 EXPORT_SYMBOL(dvb_dmxdev_init);
 

_



[Index of Archives]     [Linux Media]     [Video 4 Linux]     [Asterisk]     [Samba]     [Xorg]     [Xfree86]     [Linux USB]

  Powered by Linux