OSDN Git Service

mtd: spi-nor: cast to u64 to avoid uint overflows
authorhuijin.park <huijin.park@samsung.com>
Wed, 28 Nov 2018 08:02:14 +0000 (03:02 -0500)
committerBoris Brezillon <boris.brezillon@bootlin.com>
Mon, 10 Dec 2018 20:59:07 +0000 (21:59 +0100)
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>
drivers/mtd/spi-nor/spi-nor.c

index 9ad2c83..1423bba 100644 (file)
@@ -3270,7 +3270,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. */