diff mbox series

[v3] mtd: spi-nor: cast to u64 to avoid uint overflows

Message ID 1543392134-1443-1-git-send-email-huijin.park@samsung.com
State Accepted
Delegated to: Boris Brezillon
Headers show
Series [v3] mtd: spi-nor: cast to u64 to avoid uint overflows | expand

Commit Message

Huijin Park Nov. 28, 2018, 8:02 a.m. UTC
From: "huijin.park" <huijin.park@samsung.com>

The "params->size" is defined as "u64".
And "info->sector_size" and "info->n_sectors" are defined as
unsigned int and u16.
Thus, u64 data might have strange data(loss data) if the result
overflows an unsigned int.
This patch casts "info->sector_size" to an u64.

Signed-off-by: huijin.park <huijin.park@samsung.com>
---

Changes since v1:
 * Made commit subject and message more clear.
Changes since v2:
 * Adding the cast to only the first operand.
---
 drivers/mtd/spi-nor/spi-nor.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Geert Uytterhoeven Nov. 28, 2018, 8:41 a.m. UTC | #1
On Wed, Nov 28, 2018 at 9:03 AM Huijin Park <huijin.park@samsung.com> wrote:
> From: "huijin.park" <huijin.park@samsung.com>
>
> The "params->size" is defined as "u64".
> And "info->sector_size" and "info->n_sectors" are defined as
> unsigned int and u16.
> Thus, u64 data might have strange data(loss data) if the result
> overflows an unsigned int.
> This patch casts "info->sector_size" to an u64.
>
> Signed-off-by: huijin.park <huijin.park@samsung.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert
Boris Brezillon Dec. 3, 2018, 7:51 a.m. UTC | #2
On Wed, 2018-11-28 at 08:02:14 UTC, Huijin Park wrote:
> From: "huijin.park" <huijin.park@samsung.com>
> 
> The "params->size" is defined as "u64".
> And "info->sector_size" and "info->n_sectors" are defined as
> unsigned int and u16.
> Thus, u64 data might have strange data(loss data) if the result
> overflows an unsigned int.
> This patch casts "info->sector_size" to an u64.
> 
> Signed-off-by: huijin.park <huijin.park@samsung.com>
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Applied to http://git.infradead.org/linux-mtd.git mtd/next, thanks.

Boris
Rafał Miłecki Dec. 3, 2018, 8:12 a.m. UTC | #3
On Wed, 28 Nov 2018 at 09:03, Huijin Park <huijin.park@samsung.com> wrote:
> From: "huijin.park" <huijin.park@samsung.com>
>
> The "params->size" is defined as "u64".
> And "info->sector_size" and "info->n_sectors" are defined as
> unsigned int and u16.
> Thus, u64 data might have strange data(loss data) if the result
> overflows an unsigned int.
> This patch casts "info->sector_size" to an u64.
>
> Signed-off-by: huijin.park <huijin.park@samsung.com>

You may want to adjust your git's "user.name" config to avoid
"malforming" your name (From and Signed-off-by) in the further
contributions :)

Something like
git config --global user.name "John Foo"
Boris Brezillon Dec. 3, 2018, 10:34 a.m. UTC | #4
On Mon,  3 Dec 2018 08:51:54 +0100
Boris Brezillon <boris.brezillon@bootlin.com> wrote:

> On Wed, 2018-11-28 at 08:02:14 UTC, Huijin Park wrote:
> > From: "huijin.park" <huijin.park@samsung.com>
> > 
> > The "params->size" is defined as "u64".
> > And "info->sector_size" and "info->n_sectors" are defined as
> > unsigned int and u16.
> > Thus, u64 data might have strange data(loss data) if the result
> > overflows an unsigned int.
> > This patch casts "info->sector_size" to an u64.
> > 
> > Signed-off-by: huijin.park <huijin.park@samsung.com>
> > Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>  
> 
> Applied to http://git.infradead.org/linux-mtd.git mtd/next, thanks.

Oops, should I been queued to spi-nor/next. I dropped the patch and
will soon push it to spi-nor/next.
diff mbox series

Patch

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index d9c368c..59a1075 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -2459,7 +2459,7 @@  static int spi_nor_init_params(struct spi_nor *nor,
 	memset(params, 0, sizeof(*params));
 
 	/* Set SPI NOR sizes. */
-	params->size = info->sector_size * info->n_sectors;
+	params->size = (u64)info->sector_size * info->n_sectors;
 	params->page_size = info->page_size;
 
 	/* (Fast) Read settings. */