am7xxx-modeswitch: use libusb_set_auto_detach_kernel_driver()
[libam7xxx.git] / examples / am7xxx-modeswitch.c
index 9942d81..fd2be6d 100644 (file)
@@ -1,10 +1,10 @@
 /* am7xxx-modeswitch - a simple usb-modeswitch for am7xxx devices
  *
 /* am7xxx-modeswitch - a simple usb-modeswitch for am7xxx devices
  *
- * Copyright (C) 2012  Antonio Ospite <ospite@studenti.unina.it>
+ * Copyright (C) 2012-2014  Antonio Ospite <ao2@ao2.it>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -53,21 +53,14 @@ int main(void)
                goto out;
        }
 
                goto out;
        }
 
-       if (libusb_kernel_driver_active(usb_device, AM7XXX_STORAGE_INTERFACE)) {
-               ret = libusb_detach_kernel_driver(usb_device,
-                                                 AM7XXX_STORAGE_INTERFACE);
-               if (ret < 0)
-                       fprintf(stderr, "Warning: cannot detach kernel driver.\n");
-       } else {
-               fprintf(stderr, "kernel driver not active.\n");
-       }
-
        ret = libusb_set_configuration(usb_device, AM7XXX_STORAGE_CONFIGURATION);
        if (ret < 0) {
                fprintf(stderr, "cannot set configuration.\n");
                goto out_libusb_close;
        }
 
        ret = libusb_set_configuration(usb_device, AM7XXX_STORAGE_CONFIGURATION);
        if (ret < 0) {
                fprintf(stderr, "cannot set configuration.\n");
                goto out_libusb_close;
        }
 
+       libusb_set_auto_detach_kernel_driver(usb_device, 1);
+
        ret = libusb_claim_interface(usb_device, AM7XXX_STORAGE_INTERFACE);
        if (ret < 0) {
                fprintf(stderr, "cannot claim interface.\n");
        ret = libusb_claim_interface(usb_device, AM7XXX_STORAGE_INTERFACE);
        if (ret < 0) {
                fprintf(stderr, "cannot claim interface.\n");