[4.19,14/15] mtd: spi-nor: cast to u64 to avoid uint overflows

Message ID 20191202103050.2668-14-lee.jones@linaro.org
State New
Headers show
Series
  • [4.19,01/15] clk: at91: fix update bit maps on CFG_MOR write
Related show

Commit Message

Lee Jones Dec. 2, 2019, 10:30 a.m.
From: "huijin.park" <huijin.park@samsung.com>


[ Upstream commit 84a1c2109d23df3543d96231c4fee1757299bb1a ]

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>

Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>

Signed-off-by: Lee Jones <lee.jones@linaro.org>

---
 drivers/mtd/spi-nor/spi-nor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.24.0

Patch

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index f028277fb1ce..2e183425facd 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. */