]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
gadget: f_thor: fix wrong file size cast
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Fri, 16 Oct 2020 07:29:02 +0000 (16:29 +0900)
committerMarek Vasut <marex@denx.de>
Sun, 31 Jan 2021 13:08:56 +0000 (14:08 +0100)
Casting 32bit int value directly into 64bit unsigned type causes
wrong value for file size equal or larger than 2GB. Fix the wrong
file size by casting uint32_t first.

Fixes: commit 1fe9ae76b113 ("gadget: f_thor: update to support more than 4GB file as thor 5.0")
Reported-by: Junghoon Kim <jhoon20.kim@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>
drivers/usb/gadget/f_thor.c

index 88fc87f2e907c8ef33e225a96421f62a4de6402c..559ffb759ed7c4b6b25d325a91f0328332464c6a 100644 (file)
@@ -266,8 +266,8 @@ static long long int process_rqt_download(const struct rqt_box *rqt)
 
        switch (rqt->rqt_data) {
        case RQT_DL_INIT:
-               thor_file_size = (unsigned long long int)rqt->int_data[0] +
-                                (((unsigned long long int)rqt->int_data[1])
+               thor_file_size = (uint64_t)(uint32_t)rqt->int_data[0] +
+                                (((uint64_t)(uint32_t)rqt->int_data[1])
                                  << 32);
                debug("INIT: total %llu bytes\n", thor_file_size);
                break;
@@ -280,8 +280,8 @@ static long long int process_rqt_download(const struct rqt_box *rqt)
                        break;
                }
 
-               thor_file_size = (unsigned long long int)rqt->int_data[1] +
-                                (((unsigned long long int)rqt->int_data[2])
+               thor_file_size = (uint64_t)(uint32_t)rqt->int_data[1] +
+                                (((uint64_t)(uint32_t)rqt->int_data[2])
                                  << 32);
                memcpy(f_name, rqt->str_data[0], F_NAME_BUF_SIZE);
                f_name[F_NAME_BUF_SIZE] = '\0';