[PATCH] sam7dfu_do_dnload(): Verify sending of completion packet

Tormod Volden lists.tormod at gmail.com
Sat Nov 13 10:45:21 CET 2010


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

If the completion packet is not received properly it is not
sure anything will be written.

Also return the total number of bytes written in case of success.

Some trivial, cosmetic fixes:
- Remove a stray perror.
- Remove a trailing newline.

---

I left the two NOP fixes in the patch to save us time.

 src/sam7dfu.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/sam7dfu.c b/src/sam7dfu.c
index d839952..177ba7b 100644
--- a/src/sam7dfu.c
+++ b/src/sam7dfu.c
@@ -104,7 +104,6 @@ int sam7dfu_do_dnload(struct usb_dev_handle *usb_handle, int interface,
 	if (ret < 0) {
 		perror(fname);
 		goto out_close;
-		perror(fname);
 	}
 
 	if (st.st_size <= 0 /* + DFU_HDR */) {
@@ -164,8 +163,10 @@ int sam7dfu_do_dnload(struct usb_dev_handle *usb_handle, int interface,
 
 	/* send one zero sized download request to signalize end */
 	ret = dfu_download(usb_handle, interface, 0, NULL);
-	if (ret >= 0)
-		ret = bytes_sent;
+	if (ret < 0) {
+			fprintf(stderr, "Error sending completion packet\n");
+			goto out_close;
+	}
 
 	printf("] finished!\n");
 	fflush(stdout);
@@ -206,7 +207,7 @@ out_close:
 out_free:
 	free(buf);
 
-	return ret;
+	return bytes_sent;
 }
 
 void sam7dfu_init()
@@ -215,4 +216,3 @@ void sam7dfu_init()
     dfu_init( 5000 );
 }
 
-
-- 
1.7.0.4




More information about the devel mailing list