if (!dev)
                return -ENOMEM;
 
+       pdev_id = of_id ? of_id->data : platform_get_device_id(pdev);
+
+       if (of_id)
+               dev->devtype = of_id->data;
+       else if (pdev_id)
+               dev->devtype = &coda_devdata[pdev_id->driver_data];
+       else
+               return -EINVAL;
+
        spin_lock_init(&dev->irqlock);
        INIT_LIST_HEAD(&dev->instances);
 
        mutex_init(&dev->dev_mutex);
        mutex_init(&dev->coda_mutex);
 
-       pdev_id = of_id ? of_id->data : platform_get_device_id(pdev);
-
-       if (of_id) {
-               dev->devtype = of_id->data;
-       } else if (pdev_id) {
-               dev->devtype = &coda_devdata[pdev_id->driver_data];
-       } else {
-               v4l2_device_unregister(&dev->v4l2_dev);
-               return -EINVAL;
-       }
-
        dev->debugfs_root = debugfs_create_dir("coda", NULL);
        if (!dev->debugfs_root)
                dev_warn(&pdev->dev, "failed to create debugfs root\n");