et61x251_show_i2c_val, et61x251_store_i2c_val);
 
 
-static void et61x251_create_sysfs(struct et61x251_device* cam)
+static int et61x251_create_sysfs(struct et61x251_device* cam)
 {
        struct video_device *v4ldev = cam->v4ldev;
+       int rc;
 
-       video_device_create_file(v4ldev, &class_device_attr_reg);
-       video_device_create_file(v4ldev, &class_device_attr_val);
+       rc = video_device_create_file(v4ldev, &class_device_attr_reg);
+       if (rc) goto err;
+       rc = video_device_create_file(v4ldev, &class_device_attr_val);
+       if (rc) goto err_reg;
        if (cam->sensor.sysfs_ops) {
-               video_device_create_file(v4ldev, &class_device_attr_i2c_reg);
-               video_device_create_file(v4ldev, &class_device_attr_i2c_val);
+               rc = video_device_create_file(v4ldev, &class_device_attr_i2c_reg);
+               if (rc) goto err_val;
+               rc = video_device_create_file(v4ldev, &class_device_attr_i2c_val);
+               if (rc) goto err_i2c_reg;
        }
+
+       return 0;
+
+err_i2c_reg:
+       video_device_remove_file(v4ldev, &class_device_attr_i2c_reg);
+err_val:
+       video_device_remove_file(v4ldev, &class_device_attr_val);
+err_reg:
+       video_device_remove_file(v4ldev, &class_device_attr_reg);
+err:
+       return rc;
 }
 #endif /* CONFIG_VIDEO_ADV_DEBUG */
 
        dev_nr = (dev_nr < ET61X251_MAX_DEVICES-1) ? dev_nr+1 : 0;
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       et61x251_create_sysfs(cam);
+       err = et61x251_create_sysfs(cam);
+       if (err)
+               goto fail2;
        DBG(2, "Optional device control through 'sysfs' interface ready");
 #endif
 
 
        return 0;
 
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+fail2:
+       video_nr[dev_nr] = -1;
+       dev_nr = (dev_nr < ET61X251_MAX_DEVICES-1) ? dev_nr+1 : 0;
+       mutex_unlock(&cam->dev_mutex);
+       video_unregister_device(cam->v4ldev);
+#endif
 fail:
        if (cam) {
                kfree(cam->control_buffer);
 
 static CLASS_DEVICE_ATTR(button, S_IRUGO | S_IWUSR, show_snapshot_button_status,
                         NULL);
 
-static void pwc_create_sysfs_files(struct video_device *vdev)
+static int pwc_create_sysfs_files(struct video_device *vdev)
 {
        struct pwc_device *pdev = video_get_drvdata(vdev);
-       if (pdev->features & FEATURE_MOTOR_PANTILT)
-               video_device_create_file(vdev, &class_device_attr_pan_tilt);
-       video_device_create_file(vdev, &class_device_attr_button);
+       int rc;
+
+       rc = video_device_create_file(vdev, &class_device_attr_button);
+       if (rc)
+               goto err;
+       if (pdev->features & FEATURE_MOTOR_PANTILT) {
+               rc = video_device_create_file(vdev,&class_device_attr_pan_tilt);
+               if (rc) goto err_button;
+       }
+
+       return 0;
+
+err_button:
+       video_device_remove_file(vdev, &class_device_attr_button);
+err:
+       return rc;
 }
 
 static void pwc_remove_sysfs_files(struct video_device *vdev)
        struct usb_device *udev = interface_to_usbdev(intf);
        struct pwc_device *pdev = NULL;
        int vendor_id, product_id, type_id;
-       int i, hint;
+       int i, hint, rc;
        int features = 0;
        int video_nr = -1; /* default: use next available device */
        char serial_number[30], *name;
        i = video_register_device(pdev->vdev, VFL_TYPE_GRABBER, video_nr);
        if (i < 0) {
                PWC_ERROR("Failed to register as video device (%d).\n", i);
-               video_device_release(pdev->vdev); /* Drip... drip... drip... */
-               kfree(pdev); /* Oops, no memory leaks please */
-               return -EIO;
+               rc = i;
+               goto err;
        }
        else {
                PWC_INFO("Registered as /dev/video%d.\n", pdev->vdev->minor & 0x3F);
 
        PWC_DEBUG_PROBE("probe() function returning struct at 0x%p.\n", pdev);
        usb_set_intfdata (intf, pdev);
-       pwc_create_sysfs_files(pdev->vdev);
+       rc = pwc_create_sysfs_files(pdev->vdev);
+       if (rc)
+               goto err_unreg;
 
        /* Set the leds off */
        pwc_set_leds(pdev, 0, 0);
        pwc_camera_power(pdev, 0);
 
        return 0;
+
+err_unreg:
+       if (hint < MAX_DEV_HINTS)
+               device_hint[hint].pdev = NULL;
+       video_unregister_device(pdev->vdev);
+err:
+       video_device_release(pdev->vdev); /* Drip... drip... drip... */
+       kfree(pdev); /* Oops, no memory leaks please */
+       return rc;
 }
 
 /* The user janked out the cable... */
 
                         sn9c102_show_frame_header, NULL);
 
 
-static void sn9c102_create_sysfs(struct sn9c102_device* cam)
+static int sn9c102_create_sysfs(struct sn9c102_device* cam)
 {
        struct video_device *v4ldev = cam->v4ldev;
+       int rc;
+
+       rc = video_device_create_file(v4ldev, &class_device_attr_reg);
+       if (rc) goto err;
+       rc = video_device_create_file(v4ldev, &class_device_attr_val);
+       if (rc) goto err_reg;
+       rc = video_device_create_file(v4ldev, &class_device_attr_frame_header);
+       if (rc) goto err_val;
 
-       video_device_create_file(v4ldev, &class_device_attr_reg);
-       video_device_create_file(v4ldev, &class_device_attr_val);
-       video_device_create_file(v4ldev, &class_device_attr_frame_header);
-       if (cam->bridge == BRIDGE_SN9C101 || cam->bridge == BRIDGE_SN9C102)
-               video_device_create_file(v4ldev, &class_device_attr_green);
-       else if (cam->bridge == BRIDGE_SN9C103) {
-               video_device_create_file(v4ldev, &class_device_attr_blue);
-               video_device_create_file(v4ldev, &class_device_attr_red);
-       }
        if (cam->sensor.sysfs_ops) {
-               video_device_create_file(v4ldev, &class_device_attr_i2c_reg);
-               video_device_create_file(v4ldev, &class_device_attr_i2c_val);
+               rc = video_device_create_file(v4ldev, &class_device_attr_i2c_reg);
+               if (rc) goto err_frhead;
+               rc = video_device_create_file(v4ldev, &class_device_attr_i2c_val);
+               if (rc) goto err_i2c_reg;
+       }
+
+       if (cam->bridge == BRIDGE_SN9C101 || cam->bridge == BRIDGE_SN9C102) {
+               rc = video_device_create_file(v4ldev, &class_device_attr_green);
+               if (rc) goto err_i2c_val;
+       } else if (cam->bridge == BRIDGE_SN9C103) {
+               rc = video_device_create_file(v4ldev, &class_device_attr_blue);
+               if (rc) goto err_i2c_val;
+               rc = video_device_create_file(v4ldev, &class_device_attr_red);
+               if (rc) goto err_blue;
        }
+
+       return 0;
+
+err_blue:
+       video_device_remove_file(v4ldev, &class_device_attr_blue);
+err_i2c_val:
+       if (cam->sensor.sysfs_ops)
+               video_device_remove_file(v4ldev, &class_device_attr_i2c_val);
+err_i2c_reg:
+       if (cam->sensor.sysfs_ops)
+               video_device_remove_file(v4ldev, &class_device_attr_i2c_reg);
+err_frhead:
+       video_device_remove_file(v4ldev, &class_device_attr_frame_header);
+err_val:
+       video_device_remove_file(v4ldev, &class_device_attr_val);
+err_reg:
+       video_device_remove_file(v4ldev, &class_device_attr_reg);
+err:
+       return rc;
 }
 #endif /* CONFIG_VIDEO_ADV_DEBUG */
 
                DBG(1, "V4L2 device registration failed");
                if (err == -ENFILE && video_nr[dev_nr] == -1)
                        DBG(1, "Free /dev/videoX node not found");
-               video_nr[dev_nr] = -1;
-               dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0;
-               mutex_unlock(&cam->dev_mutex);
-               goto fail;
+               goto fail2;
        }
 
        DBG(2, "V4L2 device registered as /dev/video%d", cam->v4ldev->minor);
        dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0;
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       sn9c102_create_sysfs(cam);
+       err = sn9c102_create_sysfs(cam);
+       if (err)
+               goto fail3;
        DBG(2, "Optional device control through 'sysfs' interface ready");
 #endif
 
 
        return 0;
 
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+fail3:
+       video_unregister_device(cam->v4ldev);
+#endif
+fail2:
+       video_nr[dev_nr] = -1;
+       dev_nr = (dev_nr < SN9C102_MAX_DEVICES-1) ? dev_nr+1 : 0;
+       mutex_unlock(&cam->dev_mutex);
 fail:
        if (cam) {
                kfree(cam->control_buffer);