[PATCH 2/2] omap3-usb-loader: Fix for big endian hosts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



omap3-usb-loader does a "filelen = cpu_to_le32(file->size)" and does
arithmetic operations on filelen afterwards. Also it passes filelen
to omap_usb_write() as the number of bytes to upload. This obviously
only works on little endian hosts where cpu_to_le32() is a no-op.

Fix this by doing the cpu_to_le32() conversion after all arithmetic
operations and do not use filelen after it has been converted.

This is a drive-by fix, untested currently as I don't have any big
endian host to test it with.

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 scripts/omap3-usb-loader.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/scripts/omap3-usb-loader.c b/scripts/omap3-usb-loader.c
index d9422a0916..38cdbfac93 100644
--- a/scripts/omap3-usb-loader.c
+++ b/scripts/omap3-usb-loader.c
@@ -330,7 +330,7 @@ static int transfer_first_stage(libusb_device_handle * handle, struct arg_state
 
 	/* TODO determine buffer size based on endpoint */
 	buffer = calloc(bufsize, sizeof (unsigned char));
-	filelen = cpu_to_le32(file->size);
+	filelen = file->size;
 
 	data = file->data;
 	dbuf = data;
@@ -397,6 +397,8 @@ static int transfer_first_stage(libusb_device_handle * handle, struct arg_state
 		goto fail;
 	}
 
+	filelen = cpu_to_le32(filelen);
+
 	/* send the length of the first file (little endian) */
 	if (!omap_usb_write
 	    (handle, (unsigned char *) &filelen, sizeof (filelen))) {
@@ -406,9 +408,9 @@ static int transfer_first_stage(libusb_device_handle * handle, struct arg_state
 	}
 
 	/* send the file! */
-	if (!omap_usb_write(handle, data, filelen)) {
+	if (!omap_usb_write(handle, data, file->size)) {
 		log_error("failed to send file \'%s\' (size %u)\n",
-			  file->basename, filelen);
+			  file->basename, file->size);
 		goto fail;
 	}
 

-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux