[PATCH dfu-util] main: Simplify --detach handling by reusing existing code

Tormod Volden lists.tormod at gmail.com
Sun Nov 13 23:02:12 CET 2011


From: Tormod Volden <debian.tormod at gmail.com>

Signed-off-by: Tormod Volden <debian.tormod at gmail.com>
---

Hi,

I have some issues with the recent --detach option addition:
* It duplicates the existing detach code
* It sends requests to an interface without claiming it first
* It resets the device without checking bitWillDetach

Can't we simply do it like this, use existing code instead?
I do not have any devices that do the mode transition correctly,
so I can not verify that it works.

If the main motivation for this option is to inquire about devices
which only show alternate interfaces after switching to DFU mode,
then an alternative would be to list those if the user has not 
specified one of them with the -a option. This way we may avoid
adding the -e option altogether. Patch to follow.

Regards,
Tormod

 src/main.c |   18 +++++-------------
 1 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/src/main.c b/src/main.c
index 4c96f88..3624069 100644
--- a/src/main.c
+++ b/src/main.c
@@ -804,19 +804,6 @@ int main(int argc, char **argv)
 	printf("Run-time device DFU version %04x\n",
 	       libusb_le16_to_cpu(func_dfu_rt.bcdDFUVersion));
 
-	if (mode == MODE_DETACH) {
-		if (dfu_detach(_rt_dif.dev_handle, _rt_dif.interface, 1000) < 0) {
-			fprintf(stderr, "error detaching\n");
-			exit(1);
-		}
-		libusb_release_interface(_rt_dif.dev_handle, _rt_dif.interface);
-		ret = libusb_reset_device(_rt_dif.dev_handle);
-		if (ret < 0 && ret != LIBUSB_ERROR_NOT_FOUND)
-			fprintf(stderr, "error resetting "
-				"after detach\n");
-		exit(0);
-	}
-
 	/* Transition from run-Time mode to DFU mode */
 	if (!(_rt_dif.flags & DFU_IFF_DFU)) {
 		/* In the 'first round' during runtime mode, there can only be one
@@ -889,6 +876,11 @@ int main(int argc, char **argv)
 					 _rt_dif.interface);
 		libusb_close(_rt_dif.dev_handle);
 
+		if (mode == MODE_DETACH) {
+			libusb_exit(ctx);
+			exit(0);
+		}
+
 		/* now we need to re-scan the bus and locate our device */
 //		if (usb_find_devices() < 2)
 //			printf("not at least 2 device changes found ?!?\n");
-- 
1.7.5.4




More information about the devel mailing list