linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@bootlin.com>
To: Huijin Park <huijin.park@samsung.com>
Cc: Marek Vasut <marek.vasut@gmail.com>,
	linux-mtd@lists.infradead.org, bbanghj.park@gmail.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mtd: cast to u64 to avoid unexpected error
Date: Wed, 31 Oct 2018 14:55:05 +0100	[thread overview]
Message-ID: <20181031145505.6b034b84@bbrezillon> (raw)
In-Reply-To: <1535009282-1480-1-git-send-email-huijin.park@samsung.com>

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

  reply	other threads:[~2018-10-31 13:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 [this message]
2018-11-12 16:12     ` Huijin Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181031145505.6b034b84@bbrezillon \
    --to=boris.brezillon@bootlin.com \
    --cc=bbanghj.park@gmail.com \
    --cc=huijin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).