All of lore.kernel.org
 help / color / mirror / Atom feed
From: Seung-Woo Kim <sw0312.kim@samsung.com>
To: u-boot@lists.denx.de
Subject: [PATCH] gadget: f_thor: fix wrong file size cast
Date: Fri, 16 Oct 2020 16:29:02 +0900	[thread overview]
Message-ID: <20201016072902.2837-1-sw0312.kim@samsung.com> (raw)
In-Reply-To: CGME20201016072733epcas1p4e912e3453206c2747f8d0cd1c8afc1a6@epcas1p4.samsung.com

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>
---
 drivers/usb/gadget/f_thor.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/f_thor.c b/drivers/usb/gadget/f_thor.c
index 88fc87f2e9..559ffb759e 100644
--- a/drivers/usb/gadget/f_thor.c
+++ b/drivers/usb/gadget/f_thor.c
@@ -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';
-- 
2.19.2

       reply	other threads:[~2020-10-16  7:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20201016072733epcas1p4e912e3453206c2747f8d0cd1c8afc1a6@epcas1p4.samsung.com>
2020-10-16  7:29 ` Seung-Woo Kim [this message]
2020-10-18 23:25   ` [PATCH] gadget: f_thor: fix wrong file size cast Jaehoon Chung

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201016072902.2837-1-sw0312.kim@samsung.com \
    --to=sw0312.kim@samsung.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.