From: huijin.park Date: Wed, 28 Nov 2018 08:02:14 +0000 (-0500) Subject: mtd: spi-nor: cast to u64 to avoid uint overflows X-Git-Tag: for-4.21~65^2^2~11 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=84a1c2109d23df3543d96231c4fee1757299bb1a;p=uclinux-h8%2Flinux.git mtd: spi-nor: cast to u64 to avoid uint overflows 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 Reviewed-by: Geert Uytterhoeven Signed-off-by: Boris Brezillon --- diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 9ad2c8329931..1423bbaa9762 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -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. */