linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Marcel Ziswiler <marcel.ziswiler@toradex.com>
To: "stefan@agner.ch" <stefan@agner.ch>,
	"boris.brezillon@bootlin.com" <boris.brezillon@bootlin.com>,
	"miquel.raynal@bootlin.com" <miquel.raynal@bootlin.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
	"dan.carpenter@oracle.com" <dan.carpenter@oracle.com>,
	"krzk@kernel.org" <krzk@kernel.org>,
	"dev@lynxeye.de" <dev@lynxeye.de>,
	"benjamin.lindqvist@endian.se" <benjamin.lindqvist@endian.se>,
	"digetx@gmail.com" <digetx@gmail.com>,
	"mirza.krak@gmail.com" <mirza.krak@gmail.com>,
	"gaireg@gaireg.de" <gaireg@gaireg.de>,
	"dwmw2@infradead.org" <dwmw2@infradead.org>,
	"computersforpeace@gmail.com" <computersforpeace@gmail.com>,
	"linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>,
	"marek.vasut@gmail.com" <marek.vasut@gmail.com>,
	"richard@nod.at" <richard@nod.at>
Subject: Re: [PATCH] mtd: rawnand: tegra: check bounds of die_nr properly
Date: Thu, 12 Jul 2018 13:31:57 +0000	[thread overview]
Message-ID: <1531402315.1390.6.camel@toradex.com> (raw)
In-Reply-To: <20180704091310.22003-1-stefan@agner.ch>

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 <dan.carpenter@oracle.com>
> Signed-off-by: Stefan Agner <stefan@agner.ch>
> ---
>  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!

I will send an updated patch explicitly casting the ARRAY_SIZE side to
int as well shortly.

> +
> +	if (die_nr < 0 || die_nr > 0) {
>  		ctrl->cur_cs = -1;
>  		return;
>  	}

  parent reply	other threads:[~2018-07-12 13:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-04  9:13 [PATCH] mtd: rawnand: tegra: check bounds of die_nr properly Stefan Agner
2018-07-08 21:51 ` Miquel Raynal
2018-07-12 13:31 ` Marcel Ziswiler [this message]
2018-07-12 13:44   ` Dan Carpenter

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=1531402315.1390.6.camel@toradex.com \
    --to=marcel.ziswiler@toradex.com \
    --cc=benjamin.lindqvist@endian.se \
    --cc=boris.brezillon@bootlin.com \
    --cc=computersforpeace@gmail.com \
    --cc=dan.carpenter@oracle.com \
    --cc=dev@lynxeye.de \
    --cc=digetx@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=gaireg@gaireg.de \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=marek.vasut@gmail.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=mirza.krak@gmail.com \
    --cc=richard@nod.at \
    --cc=stefan@agner.ch \
    /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).