Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp391433imu; Tue, 20 Nov 2018 00:36:29 -0800 (PST) X-Google-Smtp-Source: AJdET5cp6zvdcMITsmziC6VUgv2EwDZV2Wnj1OhKTTyBGQyXC4wa8hIba6yYU9lIOoDGYPQCgc5O X-Received: by 2002:a62:6001:: with SMTP id u1-v6mr1287333pfb.130.1542702989702; Tue, 20 Nov 2018 00:36:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542702989; cv=none; d=google.com; s=arc-20160816; b=XQQAvdJjCWFAJrla+5nUIfpmP0a9XarZFlwUn/ZzzeuzH2vrfH82Xfdui8MQj1Bnsn TP/KatQcpXkevUEAOAu6GYQyr7GS6szJQdPrAOXiQvUGxmgMagQosY4d2Xd5i1vum+hD B2VyS7rCNbWNNdBQurwtOS9ren39LkG6N5RFoJB/3AXKLJQtb/RKzTWmeF0OX8EMlQR3 +vWLn2m7n1SM1zAcKCMkK/dt5IP41FrviEgKUT2Gvv8F55vd1IjAV/t07amDMPoxdWXO J1dUnY1eCAGvWcptveScJwROum/fmsobDDe2jaio1Xs1t0m8UDmyKdbCxXMO6i8DQsga 5xDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=rcK6eBcd+OHabn/M+TbT7b9qeMTPFsAKfVdSDCMY5RE=; b=A6hX8LqSdEC+BndKBYjPD6oZrOxjlkVe6wyyfSxRDtND2Ocox3T5cFx/G1Q1M5CGiK nkp+LLztG99Io+89l89AHppcFRPkbl7CmjCqeWkc2r0cNxx5spv4M5NvMs1GtqbFcpnA p6VN+tUjUvMSVvRzao9ZqG9nHNQASBuwu6GSo9umw++yqJJUj8jTIsK33JpxuaSiwVZT qpoeqlv1ptnfu3AGDRw9qmxVtX4TpaOIIDbnfQ2SiC1/A/ADhljY0i0JOQDI+DnzKtbV +mpEv6FgXIgSZdWQ6/6mgoX8Dn7qgMXXkYluBwW+sw2XNm+BFHsV8dVzjfvR5Bn3RFDf rvZA== 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 cb2si20608818plb.298.2018.11.20.00.36.15; Tue, 20 Nov 2018 00:36:29 -0800 (PST) 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 S1726774AbeKTSpb (ORCPT + 99 others); Tue, 20 Nov 2018 13:45:31 -0500 Received: from mail-ua1-f65.google.com ([209.85.222.65]:35724 "EHLO mail-ua1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726075AbeKTSpb (ORCPT ); Tue, 20 Nov 2018 13:45:31 -0500 Received: by mail-ua1-f65.google.com with SMTP id d2so350740ual.2 for ; Tue, 20 Nov 2018 00:17:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rcK6eBcd+OHabn/M+TbT7b9qeMTPFsAKfVdSDCMY5RE=; b=imBMsBKuTRObDgGzhr8RUwvVJxY0h740nJgKZg15rnUpC0caJKkuH+nzb22Luj6Jkn wJgoxiF9QLOrZf9sR7bFESpeO7MHHW6qnai9rzTlwWnbfztCNq9aS/bSte3bh1jHlc+X jHjWSNk6o8R1CBGAf9YFSanM7AjD7GhBdBu6acl5r1vQ5woUgu3i8gaCyK6OehMc+/bP 113JCly4XIKr5bDLyZyv0MlOwginVi5jEC61igi3uG0KZdAtXdKyAMchQTBma+G1Zy6s m6Mi8z+f+hGeLZt96wwF8NkmnL5i7L8gtg65eMICVZNIvWPmIlQgmKpTBKy4AX493BTe Ie1w== X-Gm-Message-State: AA+aEWbvDySCA0O5zinTvn08QY/CRJM6qdHzIzwniplE9buUCYeAu3ks rYTN8q7A4cA3IU0+wCA0e8ugk2gahbJI1YPulFjKuQ== X-Received: by 2002:ab0:7251:: with SMTP id d17mr484260uap.0.1542701858839; Tue, 20 Nov 2018 00:17:38 -0800 (PST) MIME-Version: 1.0 References: <1542258449-19930-1-git-send-email-huijin.park@samsung.com> In-Reply-To: <1542258449-19930-1-git-send-email-huijin.park@samsung.com> From: Geert Uytterhoeven Date: Tue, 20 Nov 2018 09:17:26 +0100 Message-ID: Subject: Re: [PATCH v2] mtd: spi-nor: cast to u64 to avoid uint overflows To: huijin.park@samsung.com Cc: Boris Brezillon , Marek Vasut , MTD Maling List , Linux Kernel Mailing List , bbanghj.park@gmail.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Huijin, On Thu, Nov 15, 2018 at 6:08 AM Huijin Park wrote: > From: "huijin.park" > > 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 > --- > 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