printk(KERN_ERR "%s() failed (errno = %d), NO PCI configuration\n",
                        __func__, result);
                result = -ENOMEM;
-               goto failed;
+               goto fail_pci;
        }
 
        /* Establish encoder defaults here */
                          100000, ENCODER_DEF_BITRATE);
        if (hdl->error) {
                result = hdl->error;
-               goto failed;
+               goto fail_hdl;
        }
 
        port->std = V4L2_STD_NTSC_M;
                printk(KERN_INFO "%s: can't allocate mpeg device\n",
                        dev->name);
                result = -ENOMEM;
-               goto failed;
+               goto fail_hdl;
        }
 
        port->v4l_device->ctrl_handler = hdl;
        if (result < 0) {
                printk(KERN_INFO "%s: can't register mpeg device\n",
                        dev->name);
-               /* TODO: We're going to leak here if we don't dealloc
-                The buffers above. The unreg function can't deal wit it.
-               */
-               goto failed;
+               goto fail_reg;
        }
 
        printk(KERN_INFO "%s: registered device video%d [mpeg]\n",
 
        saa7164_api_set_encoder(port);
        saa7164_api_get_encoder(port);
+       return 0;
 
-       result = 0;
-failed:
+fail_reg:
+       video_device_release(port->v4l_device);
+       port->v4l_device = NULL;
+fail_hdl:
+       v4l2_ctrl_handler_free(hdl);
+fail_pci:
        return result;
 }