Skip to contentSkip to conversation

mtd: rawnand: tegra: check bounds of die_nr properly

PATCH In review Marcel Ziswiler 2 participants 2 messages Jul 17, 2018 – Jul 18, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mtd: rawnand: tegra: check bounds of die_nr properly

From: Stefan Agner <[email protected]>

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.

---

Changes in v2:
- Fixed comparison between signed integer die_nr and unsigned ARRAY_SIZE.

 drivers/mtd/nand/raw/tegra_nand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/nand/raw/tegra_nand.c +3 -1
index 9f7de36be893..56c0aa1bc81f 100644
@@ -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;
 	}
Signature · 1 line
2.14.4
maintainer
#1 lore raw

Hi Marcel,

Marcel Ziswiler <[email protected]> wrote on Tue, 17 Jul 2018 10:46:18 +0200:

Quoted 8 lines

From: Stefan Agner <[email protected]>

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]'
Quoted 7 lines

Also warn in case the stack asks for a chip select we currently do not support.

Applied on nand/next in place of the previous one (with my SoB after yours).

Thanks,
Miquèl