diff mbox

[U-Boot] part: check each variable for capability calculation

Message ID 1352251992-7387-1-git-send-email-Chang-Ming.Huang@freescale.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Jerry Huang Nov. 7, 2012, 1:33 a.m. UTC
From: Jerry Huang <Chang-Ming.Huang@freescale.com>

In order to calculate the capability, we use the below expression to check:
((dev_desc->lba * dev_desc->blksz)>0L)
If the capability is greater than 4GB (e.g. 8GB = 8 * 1024 * 104 * 1024),
the result will overflow, the low 32bit may be zero.

Therefore, change to check each variable to fix this potential issue.

Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
---
 disk/part.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Changming Huang Dec. 6, 2012, 4:07 a.m. UTC | #1
Since last month, no any feedback.
Who can give some comment about this patch?

Best Regards
Jerry Huang


> -----Original Message-----
> From: Huang Changming-R66093
> Sent: Wednesday, November 07, 2012 9:33 AM
> To: u-boot@lists.denx.de
> Cc: Huang Changming-R66093
> Subject: [PATCH] part: check each variable for capability calculation
> 
> From: Jerry Huang <Chang-Ming.Huang@freescale.com>
> 
> In order to calculate the capability, we use the below expression to
> check:
> ((dev_desc->lba * dev_desc->blksz)>0L)
> If the capability is greater than 4GB (e.g. 8GB = 8 * 1024 * 104 * 1024),
> the result will overflow, the low 32bit may be zero.
> 
> Therefore, change to check each variable to fix this potential issue.
> 
> Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
> ---
>  disk/part.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/disk/part.c b/disk/part.c
> index 4646f68..7bdc90e 100644
> --- a/disk/part.c
> +++ b/disk/part.c
> @@ -199,7 +199,7 @@ void dev_print (block_dev_desc_t *dev_desc)
>  		break;
>  	}
>  	puts ("\n");
> -	if ((dev_desc->lba * dev_desc->blksz)>0L) {
> +	if (dev_desc->lba > 0L && dev_desc->blksz > 0L) {
>  		ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;
>  		lbaint_t lba;
> 
> --
> 1.7.9.5
Tom Rini Dec. 7, 2012, 3:49 p.m. UTC | #2
On Tue, Nov 06, 2012 at 03:33:12PM -0000, Jerry Huang wrote:

> From: Jerry Huang <Chang-Ming.Huang@freescale.com>
> 
> In order to calculate the capability, we use the below expression to check:
> ((dev_desc->lba * dev_desc->blksz)>0L)
> If the capability is greater than 4GB (e.g. 8GB = 8 * 1024 * 104 * 1024),
> the result will overflow, the low 32bit may be zero.
> 
> Therefore, change to check each variable to fix this potential issue.
> 
> Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/disk/part.c b/disk/part.c
index 4646f68..7bdc90e 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -199,7 +199,7 @@  void dev_print (block_dev_desc_t *dev_desc)
 		break;
 	}
 	puts ("\n");
-	if ((dev_desc->lba * dev_desc->blksz)>0L) {
+	if (dev_desc->lba > 0L && dev_desc->blksz > 0L) {
 		ulong mb, mb_quot, mb_rem, gb, gb_quot, gb_rem;
 		lbaint_t lba;