Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1717475imm; Thu, 12 Jul 2018 06:46:50 -0700 (PDT) X-Google-Smtp-Source: AAOMgpda4x69684Rb0VmlcxpFbtiXY7Y+O9Tb3E2vv2V/ndHob1MIIMNF8irmZkQp8rEmQ+s4ts9 X-Received: by 2002:a63:6b03:: with SMTP id g3-v6mr2212808pgc.57.1531403210873; Thu, 12 Jul 2018 06:46:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531403210; cv=none; d=google.com; s=arc-20160816; b=ogBX6ykSkNGiRn++x5w1ZeBdo/qBI5WEiRB01xepE8W1iOyqYIYuP+SxypMQTWjpWE QY+q6BAkPgAfih21IfswEkpQwpxpNTsHfKILla5QbP3weG3JPJ2DC5RQ2ZKYJ2nte2nk 3ew9aXjeJF9DGvQUqH1YiG9znK1CAS5RstGM8hCLkIkrtfgQNLu3sCF17AHXso3xeb9p Y/Ri6Pi23jcMOd8AtOXlYJtXHls6/9rlectzp0trTnbEtI70zE/1YtCtvuDzg7s0tZwQ 8MM2W8JIB9Z6N4Qpl5p4lux/9z+C4JLi11kK9Hj2wgZ8ZP8n+LSsX5Z5OHfSQAd2mMdZ FOPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=tb+KxN/jtIEJbpUFVDx4pzKGivoIrQ1DA8spfIY0fGw=; b=kGPmJaJ5DJq0rAD0Xadjb8qodB4orwN7m4YGBm1uq/FDxKhM1/zbl/3IlUPZaRNH4J yfvcnrw3QbT9hCc9kzKzuABCg7lKIqCwtn/EaldZDCTlJC+kIoChlSlCyjw7/o+Vf96Y pI8aajCutLZU0BhyK0elf3TCMCIEk/WbmZWeBy6ALCe/9qngZIPWoC0e8Q2GqogWO9Gu jFgFl+uZ1JIIeuPPerjG7x5sUmhtzDrjARyxpEVE/TALG0nfg0aDOvrCSbI72ywfC0Lb 5tgfUb9VJvtifnpa0lvZoJCkXDqjlnLug8ebOjEt3FsiQ+tgANfbIjX8GCO2CoUP3iyH U36Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=fsRvDncG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11-v6si20088856plk.225.2018.07.12.06.46.34; Thu, 12 Jul 2018 06:46:50 -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; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=fsRvDncG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732341AbeGLNzg (ORCPT + 99 others); Thu, 12 Jul 2018 09:55:36 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:58780 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727366AbeGLNzg (ORCPT ); Thu, 12 Jul 2018 09:55:36 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6CDiAFL072585; Thu, 12 Jul 2018 13:44:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=tb+KxN/jtIEJbpUFVDx4pzKGivoIrQ1DA8spfIY0fGw=; b=fsRvDncGILqFTh5VlmrMtV26P3XsQNsUx2rx/LFutfZawzGdnlwFUiVgfOx8sh+/73Hd FwCoIxdz60CJDCYSoJP/OPJH7by71l7BEOnP7oryQv417l5l6eZAQ5MdCpYP0D+R06Nm f9weEAJu0l7aur6+bhu7Jg/cE88NwTuJwLrdZiviZePBvnVaioC0csqEX8PdcvMWHyU7 rZnOarDO6WHn2kp94L2okP9RknXiyQQYJUt0YyyQbqnDXjke0ZQXV+u0Fo8wzR3QWrB4 NNXfIX0CkIoa/9VRqRPrmk1XmgIDc4PzPmUdbGAnmgsbj8Nq/ZNrOozLCr/IqnNMwTcv bw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2k2p7e3q1p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Jul 2018 13:44:47 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w6CDij5R012091 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Jul 2018 13:44:45 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w6CDihBf002736; Thu, 12 Jul 2018 13:44:44 GMT Received: from mwanda (/41.202.241.62) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 12 Jul 2018 06:44:43 -0700 Date: Thu, 12 Jul 2018 16:44:21 +0300 From: Dan Carpenter To: Marcel Ziswiler Cc: "stefan@agner.ch" , "boris.brezillon@bootlin.com" , "miquel.raynal@bootlin.com" , "linux-kernel@vger.kernel.org" , "linux-mtd@lists.infradead.org" , "krzk@kernel.org" , "dev@lynxeye.de" , "benjamin.lindqvist@endian.se" , "digetx@gmail.com" , "mirza.krak@gmail.com" , "gaireg@gaireg.de" , "dwmw2@infradead.org" , "computersforpeace@gmail.com" , "linux-tegra@vger.kernel.org" , "marek.vasut@gmail.com" , "richard@nod.at" Subject: Re: [PATCH] mtd: rawnand: tegra: check bounds of die_nr properly Message-ID: <20180712134421.unczwgmvfdhezq3v@mwanda> References: <20180704091310.22003-1-stefan@agner.ch> <1531402315.1390.6.camel@toradex.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1531402315.1390.6.camel@toradex.com> User-Agent: NeoMutt/20170609 (1.8.3) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8951 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807120145 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 12, 2018 at 01:31:57PM +0000, Marcel Ziswiler wrote: > On Wed, 2018-07-04 at 11:13 +0200, Stefan Agner wrote: > > The Tegra driver currently only support a single chip select, hence > > check boundaries accordingly. This fixes a off by one issue catched > > with Smatch: > > drivers/mtd/nand/raw/tegra_nand.c:476 tegra_nand_select_chip() > > warn: array off by one? 'nand->cs[die_nr]' > > > > Also warn in case the stack asks for a chip select we currently do > > not support. > > > > Reported-by: Dan Carpenter > > Signed-off-by: Stefan Agner > > --- > > drivers/mtd/nand/raw/tegra_nand.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/mtd/nand/raw/tegra_nand.c > > b/drivers/mtd/nand/raw/tegra_nand.c > > index 4daa88d814134..e65ef584df0b9 100644 > > --- a/drivers/mtd/nand/raw/tegra_nand.c > > +++ b/drivers/mtd/nand/raw/tegra_nand.c > > @@ -468,7 +468,9 @@ static void tegra_nand_select_chip(struct > > mtd_info *mtd, int die_nr) > > struct tegra_nand_chip *nand = to_tegra_chip(chip); > > struct tegra_nand_controller *ctrl = to_tegra_ctrl(chip- > > >controller); > > > > - if (die_nr < 0 || die_nr > 1) { > > + WARN_ON(die_nr >= ARRAY_SIZE(nand->cs)); > > Unfortunately, that has a tiny little issue as die_nr is a signed > integer and ARRAY_SIZE of course is unsigned. While I could have sworn > my shirt off that the compiler would have to promote this to signed > this is not quite what happens and upon deselecting with -1 this > warning gets triggered! Sorry, I didn't realize we were passing -1 as die_nr. I should have reviewed the code more carefully. The type is promoted to the which ever side has more positive bits or a minimum of int. So if you compare an int to a long long it gets promoted to long long. If you compare an int to unsigned int, it is promoted to unsigned int. If both sides are smaller than int then it is type promoted to int. For compares, I can't think how type promoting to int can be a problem but where it might matter is that that people sometimes want 0xfe and they do "~(char)0x1" but it becomes 0xfffffffe. The other trickiness is that x << shift is type x. Sometime people think if they make shift a u64 and x an int, the result will be u64 but it's still int. I think that's basically everything with type promotion. regards, dan carpenter