int a4l_ioctl_devcfg(a4l_cxt_t * cxt, void *arg) { int ret = 0; if (rtdm_in_rt_context()) return -ENOSYS; if (arg == NULL) { /* Basic checking */ if (!test_bit(A4L_DEV_ATTACHED_NR, &(a4l_get_dev(cxt)->flags))) { __a4l_err("a4l_ioctl_devcfg: " "free device, no driver to detach\n"); return -EINVAL; } /* Pre-cleanup of the transfer structure, we ensure that nothing is busy */ if ((ret = a4l_precleanup_transfer(cxt)) != 0) return ret; /* Remove the related proc file */ a4l_proc_detach(cxt); /* Free the transfer structure and its related data */ if ((ret = a4l_cleanup_transfer(cxt)) != 0) return ret; /* Free the device and the driver from each other */ if ((ret = a4l_device_detach(cxt)) == 0) clear_bit(A4L_DEV_ATTACHED_NR, &(a4l_get_dev(cxt)->flags)); } else { /* Basic checking */ if (test_bit (A4L_DEV_ATTACHED_NR, &(a4l_get_dev(cxt)->flags))) { __a4l_err("a4l_ioctl_devcfg: " "linked device, cannot attach more driver\n"); return -EINVAL; } /* Pre-initialization of the transfer structure */ a4l_presetup_transfer(cxt); /* Link the device with the driver */ if ((ret = a4l_device_attach(cxt, arg)) != 0) return ret; /* Create the transfer structure and the related proc file */ if ((ret = a4l_setup_transfer(cxt)) != 0 || (ret = a4l_proc_attach(cxt)) != 0) a4l_device_detach(cxt); else set_bit(A4L_DEV_ATTACHED_NR, &(a4l_get_dev(cxt)->flags)); } return ret; }
int a4l_ioctl_devcfg(a4l_cxt_t * cxt, void *arg) { int ret = 0; __a4l_dbg(1, core_dbg, "a4l_ioctl_devcfg: minor=%d\n", a4l_get_minor(cxt)); if (a4l_test_rt() != 0) return -EPERM; if (arg == NULL) { /* Basic checking */ if (!test_bit (A4L_DEV_ATTACHED, &(a4l_get_dev(cxt)->flags))) { __a4l_err("a4l_ioctl_devcfg: " "free device, no driver to detach\n"); return -EINVAL; } /* Removes the related proc file */ a4l_proc_detach(cxt); /* Frees the transfer structure and its related data */ if ((ret = a4l_cleanup_transfer(cxt)) != 0) return ret; /* Frees the device and the driver from each other */ if ((ret = a4l_device_detach(cxt)) == 0) clear_bit(A4L_DEV_ATTACHED, &(a4l_get_dev(cxt)->flags)); } else { /* Basic checking */ if (test_bit (A4L_DEV_ATTACHED, &(a4l_get_dev(cxt)->flags))) { __a4l_err("a4l_ioctl_devcfg: " "linked device, cannot attach more driver\n"); return -EINVAL; } /* Pre-initialization of the transfer structure */ a4l_presetup_transfer(cxt); /* Links the device with the driver */ if ((ret = a4l_device_attach(cxt, arg)) != 0) return ret; /* Creates the transfer structure and the related proc file */ if ((ret = a4l_setup_transfer(cxt)) != 0 || (ret = a4l_proc_attach(cxt)) != 0) a4l_device_detach(cxt); else set_bit(A4L_DEV_ATTACHED, &(a4l_get_dev(cxt)->flags)); } return ret; }