linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: cast to u64 to avoid unexpected error
       [not found] <CGME20180823072813eucas1p2a534b4be94a3a2bc3480adcefca2ca22@eucas1p2.samsung.com>
@ 2018-08-23  7:28 ` Huijin Park
  2018-10-31 13:55   ` Boris Brezillon
  0 siblings, 1 reply; 3+ messages in thread
From: Huijin Park @ 2018-08-23  7:28 UTC (permalink / raw)
  To: Marek Vasut
  Cc: Boris Brezillon, Huijin Park, bbanghj.park, linux-mtd, linux-kernel

From: "huijin.park" <huijin.park@samsung.com>

the params->size is defined as "u64"
and, "info->sector_size" and "info->n_sectors" is defined as unsgined and u16
thus, u64 data might have strange data(loss data) if data is overflow.
this patch cast it to 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] 3+ messages in thread

* Re: [PATCH] mtd: cast to u64 to avoid unexpected error
  2018-08-23  7:28 ` [PATCH] mtd: cast to u64 to avoid unexpected error Huijin Park
@ 2018-10-31 13:55   ` Boris Brezillon
  2018-11-12 16:12     ` Huijin Park
  0 siblings, 1 reply; 3+ messages in thread
From: Boris Brezillon @ 2018-10-31 13:55 UTC (permalink / raw)
  To: Huijin Park; +Cc: Marek Vasut, linux-mtd, bbanghj.park, linux-kernel

Hi Huijin,

Subject prefix should be "mtd: spi-nor: ...", and please replace
"unexpected error" by "unsigned int overflows".

On Thu, 23 Aug 2018 03:28:02 -0400
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" is defined as unsgined and u16

						 ^ are		^ unsigned

> thus, u64 data might have strange data(loss data) if data is overflow.

						    ^ if the result
overflows an unsigned int.

> this patch cast it to u64.

	     ^casts info->sector_size 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;

						^ this cast is not needed.

BTW, I doubt we'll ever have to deal with NORs that are more than 4GB,
but making static code analysis tools happy and enforcing code
correctness is important too.

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

Regards,

Boris

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

* Re: [PATCH] mtd: cast to u64 to avoid unexpected error
  2018-10-31 13:55   ` Boris Brezillon
@ 2018-11-12 16:12     ` Huijin Park
  0 siblings, 0 replies; 3+ messages in thread
From: Huijin Park @ 2018-11-12 16:12 UTC (permalink / raw)
  To: boris.brezillon; +Cc: huijin.park, marek.vasut, linux-mtd, linux-kernel

Hi Boris

Thanks for review.
I will send patch again.

On Wed, Oct 31, 2018 at 10:55 PM Boris Brezillon
<boris.brezillon@bootlin.com> wrote:
>
> Hi Huijin,
>
> Subject prefix should be "mtd: spi-nor: ...", and please replace
> "unexpected error" by "unsigned int overflows".
>
> On Thu, 23 Aug 2018 03:28:02 -0400
> 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" is defined as unsgined and u16
>
>                                                  ^ are          ^ unsigned
>
> > thus, u64 data might have strange data(loss data) if data is overflow.
>
>                                                     ^ if the result
> overflows an unsigned int.
>
> > this patch cast it to u64.
>
>              ^casts info->sector_size 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;
>
>                                                 ^ this cast is not needed.
>
> BTW, I doubt we'll ever have to deal with NORs that are more than 4GB,
> but making static code analysis tools happy and enforcing code
> correctness is important too.
>

I agree that enforcing code correctness is important as your said too.

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

Thanks & best regards,

Huijin

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

end of thread, other threads:[~2018-11-12 16:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20180823072813eucas1p2a534b4be94a3a2bc3480adcefca2ca22@eucas1p2.samsung.com>
2018-08-23  7:28 ` [PATCH] mtd: cast to u64 to avoid unexpected error Huijin Park
2018-10-31 13:55   ` Boris Brezillon
2018-11-12 16:12     ` Huijin Park

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).