linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mtd: spi-nor: cast to u64 to avoid uint overflows
       [not found] <CGME20181115050737eucas1p104ccec527d0713f9414bc75e0959feb6@eucas1p1.samsung.com>
@ 2018-11-15  5:07 ` Huijin Park
  2018-11-20  8:17   ` Geert Uytterhoeven
  0 siblings, 1 reply; 2+ messages in thread
From: Huijin Park @ 2018-11-15  5:07 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Marek Vasut, linux-mtd, linux-kernel, Huijin Park, bbanghj.park

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" and "info->n_sectors" to an u64.

Signed-off-by: huijin.park <huijin.park@samsung.com>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] mtd: spi-nor: cast to u64 to avoid uint overflows
  2018-11-15  5:07 ` [PATCH v2] mtd: spi-nor: cast to u64 to avoid uint overflows Huijin Park
@ 2018-11-20  8:17   ` Geert Uytterhoeven
  0 siblings, 0 replies; 2+ messages in thread
From: Geert Uytterhoeven @ 2018-11-20  8:17 UTC (permalink / raw)
  To: huijin.park
  Cc: Boris Brezillon, Marek Vasut, MTD Maling List,
	Linux Kernel Mailing List, bbanghj.park

Hi Huijin,

On Thu, Nov 15, 2018 at 6:08 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" and "info->n_sectors" to an u64.
>
> Signed-off-by: huijin.park <huijin.park@samsung.com>
> ---
>  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;

Adding the cast to only the first operand should be sufficient, and may lead
to faster code, as only a 64x16 multiplication needs to be done, instead of
a 64x64.

>         params->page_size = info->page_size;
>
>         /* (Fast) Read settings. */

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-11-20  8:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20181115050737eucas1p104ccec527d0713f9414bc75e0959feb6@eucas1p1.samsung.com>
2018-11-15  5:07 ` [PATCH v2] mtd: spi-nor: cast to u64 to avoid uint overflows Huijin Park
2018-11-20  8:17   ` Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).