Detach kernel driver

Peter Stuge peter at stuge.se
Mon Apr 23 17:11:23 UTC 2012


Michal Demin wrote:
> Subject: [PATCH 1/2] Detach the device kernel driver when kernel driver loaded.
..
> @@ -689,6 +690,15 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
>  
>  	libusb_free_device_list(list, 0);
>  
> +	if (libusb_kernel_driver_active(dev->devh, 0)) {
> +		// reattach later
> +		dev->reattach = 1;
> +		if (libusb_detach_kernel_driver(dev->devh, 0)) {
> +			fprintf(stderr, "Error detaching kernel driver \n");
> +			goto err;
> +		}
> +	}
> +
>  	r = libusb_claim_interface(dev->devh, 0);
>  	if (r < 0) {
>  		fprintf(stderr, "usb_claim_interface error %d\n", r);

This is racy. It's better to call libusb_detach_kernel_driver() when
libusb_claim_interface() returns an error.


//Peter




More information about the osmocom-sdr mailing list