summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Agner <stefan@agner.ch>2018-07-17 11:46:18 +0300
committerMiquel Raynal <miquel.raynal@bootlin.com>2018-07-20 00:14:13 +0300
commitd535934a9ad4dc435884958ac44a7d6ecb6278ce (patch)
treee1e655a818b78cce1707169d16fb8ceb7d5d0536
parent6a943386ee364155727f62711f6f3e898d824cdd (diff)
downloadlinux-d535934a9ad4dc435884958ac44a7d6ecb6278ce.tar.xz
mtd: rawnand: tegra: check bounds of die_nr properly
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>
-rw-r--r--drivers/mtd/nand/raw/tegra_nand.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/mtd/nand/raw/tegra_nand.c b/drivers/mtd/nand/raw/tegra_nand.c
index 9f7de36be893..56c0aa1bc81f 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 >= (int)ARRAY_SIZE(nand->cs));
+
+ if (die_nr < 0 || die_nr > 0) {
ctrl->cur_cs = -1;
return;
}