All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gadget: f_thor: fix wrong file size cast
       [not found] <CGME20201016072733epcas1p4e912e3453206c2747f8d0cd1c8afc1a6@epcas1p4.samsung.com>
@ 2020-10-16  7:29 ` Seung-Woo Kim
  2020-10-18 23:25   ` Jaehoon Chung
  0 siblings, 1 reply; 2+ messages in thread
From: Seung-Woo Kim @ 2020-10-16  7:29 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] gadget: f_thor: fix wrong file size cast
  2020-10-16  7:29 ` [PATCH] gadget: f_thor: fix wrong file size cast Seung-Woo Kim
@ 2020-10-18 23:25   ` Jaehoon Chung
  0 siblings, 0 replies; 2+ messages in thread
From: Jaehoon Chung @ 2020-10-18 23:25 UTC (permalink / raw)
  To: u-boot

On 10/16/20 4:29 PM, Seung-Woo Kim wrote:
> 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>

Best Regards,
Jaehoon Chung

> ---
>  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';
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-18 23:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20201016072733epcas1p4e912e3453206c2747f8d0cd1c8afc1a6@epcas1p4.samsung.com>
2020-10-16  7:29 ` [PATCH] gadget: f_thor: fix wrong file size cast Seung-Woo Kim
2020-10-18 23:25   ` Jaehoon Chung

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.