Skip to content

Commit

Permalink
mtd: rawnand: tegra: check bounds of die_nr properly
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
  • Loading branch information
Stefan Agner authored and Miquel Raynal committed Jul 19, 2018
1 parent 6a94338 commit d535934
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/mtd/nand/raw/tegra_nand.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 >= (int)ARRAY_SIZE(nand->cs));

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

0 comments on commit d535934

Please sign in to comment.