Patchwork OneNAND: Fix test of unsigned in onenand_otp_walk()

login
register
mail settings
Submitter roel kluin
Date Dec. 16, 2009, 12:37 a.m.
Message ID <4B282BBD.4050106@gmail.com>
Download mbox | patch
Permalink /patch/41227/
State New, archived
Headers show

Comments

roel kluin - Dec. 16, 2009, 12:37 a.m.
mtd->writesize and len are unsigned so the test does not work.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
you can test this with:

#include <stdio.h>

int main()
{
        int c = 1, d = 1;
        unsigned a = 30;
        unsigned b = 10;

        if ((b * c) - (d + a) < 0)
                printf("good\n");
        else
                printf("bad\n");
        return 0;
}
Kyungmin Park - Dec. 16, 2009, 1:20 a.m.
Acked-by: Kyungmin Park <kyungmin.park@samsung.com>

> -----Original Message-----
> From: Roel Kluin [mailto:roel.kluin@gmail.com]
> Sent: Wednesday, December 16, 2009 9:37 AM
> To: Kyungmin Park; linux-mtd@lists.infradead.org; Andrew Morton; LKML
> Subject: [PATCH] OneNAND: Fix test of unsigned in onenand_otp_walk()
> 
> mtd->writesize and len are unsigned so the test does not work.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> you can test this with:
> 
> #include <stdio.h>
> 
> int main()
> {
>         int c = 1, d = 1;
>         unsigned a = 30;
>         unsigned b = 10;
> 
>         if ((b * c) - (d + a) < 0)
>                 printf("good\n");
>         else
>                 printf("bad\n");
>         return 0;
> }
> 
> 
> diff --git a/drivers/mtd/onenand/onenand_base.c
> b/drivers/mtd/onenand/onenand_base.c
> index ff66e43..cbe2711 100644
> --- a/drivers/mtd/onenand/onenand_base.c
> +++ b/drivers/mtd/onenand/onenand_base.c
> @@ -2725,7 +2725,7 @@ static int onenand_otp_walk(struct mtd_info *mtd,
> loff_t from, size_t len,
>  	}
> 
>  	/* Check User/Factory boundary */
> -	if (((mtd->writesize * otp_pages) - (from + len)) < 0)
> +	if (mtd->writesize * otp_pages < from + len)
>  		return 0;
> 
>  	onenand_get_device(mtd, FL_OTPING);

Patch

diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index ff66e43..cbe2711 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -2725,7 +2725,7 @@  static int onenand_otp_walk(struct mtd_info *mtd, loff_t from, size_t len,
 	}
 
 	/* Check User/Factory boundary */
-	if (((mtd->writesize * otp_pages) - (from + len)) < 0)
+	if (mtd->writesize * otp_pages < from + len)
 		return 0;
 
 	onenand_get_device(mtd, FL_OTPING);