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

From: Yogesh Narayan Gaur
Date: Tue Nov 13 2018 - 01:39:16 EST


Hi Huijin,

I guess this is the v2 of previously send patch [1], please follow version information in patch submission.

--
Regards
Yogesh Gaur
[1] https://patchwork.ozlabs.org/patch/961197/


> -----Original Message-----
> From: linux-mtd [mailto:linux-mtd-bounces@xxxxxxxxxxxxxxxxxxx] On Behalf Of
> Huijin Park
> Sent: Tuesday, November 13, 2018 10:49 AM
> To: Boris Brezillon <boris.brezillon@xxxxxxxxxxx>
> Cc: Marek Vasut <marek.vasut@xxxxxxxxx>; linux-mtd@xxxxxxxxxxxxxxxxxxx;
> linux-kernel@xxxxxxxxxxxxxxx; bbanghj.park@xxxxxxxxx; Huijin Park
> <huijin.park@xxxxxxxxxxx>
> Subject: [PATCH] mtd: spi-nor: cast to u64 to avoid uint overflows
>
> From: "huijin.park" <huijin.park@xxxxxxxxxxx>
>
> 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" and "info->n_sectors" to an u64.
>
> Signed-off-by: huijin.park <huijin.park@xxxxxxxxxxx>
> ---
> drivers/mtd/spi-nor/spi-nor.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index
> d9c368c..527f281 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 * (u64)info->n_sectors;
> params->page_size = info->page_size;
>
> /* (Fast) Read settings. */
> --
> 1.7.9.5
>
>
> ______________________________________________________
> Linux MTD discussion mailing list
> https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.infr
> adead.org%2Fmailman%2Flistinfo%2Flinux-
> mtd%2F&amp;data=02%7C01%7Cyogeshnarayan.gaur%40nxp.com%7C5efd964
> 86c7244f430b408d649278b65%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%
> 7C1%7C636776831529836639&amp;sdata=A7hiJMpfxXKTyT6yacIougPRGdHg2o
> pL492y3sVtQek%3D&amp;reserved=0