Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp6103398imd; Wed, 31 Oct 2018 06:56:42 -0700 (PDT) X-Google-Smtp-Source: AJdET5fzEnngcYyi43/oKW+34BK1D78sQf7BSj1eZWgvu5fhBoD75daCdKxDsnxEidN7j8UGUQGy X-Received: by 2002:a17:902:7587:: with SMTP id j7-v6mr3520226pll.67.1540994202854; Wed, 31 Oct 2018 06:56:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540994202; cv=none; d=google.com; s=arc-20160816; b=Fz3yCU/m3AAK93XKGhW96Iv6pdA61RpzLSbmmBq2gJFuMbIjtdCOzwKTdV6Zs+wzbF j2mKd1NSNJ0VJ0Kowp1tcbs4c1XxiMZlc1H7rmAD5xOMT72EUtvTI3FyWuCbEbOXpn4R W1Xg0gN/YJxlZq5hpg2BKeC+lmX6SDnNL73hVP6mLif+1wMK9KXeZw3nV+71Am91ZTQ6 EdGIF60uW1au4tzEr2gEUjHTodCv6tU87CNXC7hwkiAb8j+I0zc6DqkDcFPG7/8zkdg1 gvjgRHDkH1C59jswZZx5IWR/fmwvfrwlUIpK+hOvhKaSU7UhEhJkhUXo81yPP92JdjIf lJ4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=GzIqEruW0J4FP0dYvtkwMO3ND3dDGVseOkfSeT7CBjI=; b=tbw6+Tu9Y37C+YUdDwUkDAC9hZ4e+rDIdn/3U1i7kD865gGhY5zUVLiwZZp48v5uli 7k8/iw91bPE8ep5Pdg//jN9Z788Nz812quJmOuJk2IbSob9a4Px0fOyW7RXjGlr9J0ui dobuHc+mrThF4om+WGQQMRDRaYuXlB7yldwlyGuBKX7cDnz3de+ep3NCAoGjGe2y8Qff Hxyfb6lkWUNeavD+y4AOyWhB74OO4AI+8tkITTlHT/TaFYOIiTBJyZ5ltiKTWrViX/Xz /bczJ8b+vNTSONGbpFRPrg7i/LxOkbH6mfCWk4aQpsU5bMFWao1Pz7zuQ3WaoM0UAcis usfA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u19-v6si17259782pfj.137.2018.10.31.06.56.03; Wed, 31 Oct 2018 06:56:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729387AbeJaWx0 (ORCPT + 99 others); Wed, 31 Oct 2018 18:53:26 -0400 Received: from mail.bootlin.com ([62.4.15.54]:33953 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729271AbeJaWx0 (ORCPT ); Wed, 31 Oct 2018 18:53:26 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id D0ACD20884; Wed, 31 Oct 2018 14:55:15 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (aaubervilliers-681-1-12-210.w90-88.abo.wanadoo.fr [90.88.133.210]) by mail.bootlin.com (Postfix) with ESMTPSA id 990B1207F4; Wed, 31 Oct 2018 14:55:05 +0100 (CET) Date: Wed, 31 Oct 2018 14:55:05 +0100 From: Boris Brezillon To: Huijin Park Cc: Marek Vasut , 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 Message-ID: <20181031145505.6b034b84@bbrezillon> In-Reply-To: <1535009282-1480-1-git-send-email-huijin.park@samsung.com> References: <1535009282-1480-1-git-send-email-huijin.park@samsung.com> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 wrote: > From: "huijin.park" > > 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 > --- > 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