Skip to contentSkip to conversation

mtd: rawnand: meson: Fix a limit test in meson_nfc_select_chip()

PATCH In review Dan Carpenter 3 participants 5 messages Feb 1, 2019 – Feb 5, 2019

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

PATCH 1/3 mtd: rawnand: meson: Fix a limit test in meson_nfc_select_chip()

This test is off by one because the > should be >= and it's also testing against the wrong limit. The MAX_CE_NUM is the maximum size that meson_chip->sels[] is allowed to be but meson_chip->nsels is the actual size.

Fixes 2d570b34b41a ("mtd: rawnand: meson: add support for Amlogic NAND flash controller ")
---
 drivers/mtd/nand/raw/meson_nand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/meson_nand.c +1 -1
index e858d58d97b0..94c90be7e1e0 100644
@@ -225,7 +225,7 @@ static void meson_nfc_select_chip(struct nand_chip *nand, int chip)
 	struct meson_nfc *nfc = nand_get_controller_data(nand);
 	int ret, value;
 
-	if (chip < 0 || WARN_ON_ONCE(chip > MAX_CE_NUM))
+	if (chip < 0 || WARN_ON_ONCE(chip >= meson_chip->nsels))
 		return;
 
 	nfc->param.chip_select = meson_chip->sels[chip] ? NAND_CE1 : NAND_CE0;
Signature · 1 line
2.17.1
maintainer Acked-by on v1 1/3
#1 lore raw

Hi Dan,

Quoted 16 lines · Dan Carpenter

This test is off by one because the > should be >= and it's also testing against the wrong limit. The MAX_CE_NUM is the maximum size that meson_chip->sels[] is allowed to be but meson_chip->nsels is the actual size.

Fixes 2d570b34b41a ("mtd: rawnand: meson: add support for Amlogic NAND flash controller ")
---
  drivers/mtd/nand/raw/meson_nand.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/meson_nand.c +0 -0
index e858d58d97b0..94c90be7e1e0 100644

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_select_chip(struct nand_chip *nand, int chip) · line 230

Quoted 7 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
@@ -225,7 +225,7 @@ static void meson_nfc_select_chip(struct nand_chip *nand, int chip)
  	struct meson_nfc *nfc = nand_get_controller_data(nand);
  	int ret, value;
 
-	if (chip < 0 || WARN_ON_ONCE(chip > MAX_CE_NUM))
+	if (chip < 0 || WARN_ON_ONCE(chip >= meson_chip->nsels))
  		return;
 

Thank you.

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_select_chip(struct nand_chip *nand, int chip) · line 231

Quoted 2 lines
drivers/mtd/nand/raw/meson_nand.c +0 -0
  	nfc->param.chip_select = meson_chip->sels[chip] ? NAND_CE1 : NAND_CE0;

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

maintainer
#2 lore raw
In reply to Dan Carpenter

Hi Dan,

Dan Carpenter <[email protected]> wrote on Fri, 1 Feb 2019 11:29:22 +0300:

Quoted 16 lines

This test is off by one because the > should be >= and it's also testing against the wrong limit. The MAX_CE_NUM is the maximum size that meson_chip->sels[] is allowed to be but meson_chip->nsels is the actual size.

Fixes 2d570b34b41a ("mtd: rawnand: meson: add support for Amlogic NAND flash controller ")
---
 drivers/mtd/nand/raw/meson_nand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/meson_nand.c +0 -0
index e858d58d97b0..94c90be7e1e0 100644

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_select_chip(struct nand_chip *nand, int chip) · line 231

Quoted 8 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
@@ -225,7 +225,7 @@ static void meson_nfc_select_chip(struct nand_chip *nand, int chip)
 	struct meson_nfc *nfc = nand_get_controller_data(nand);
 	int ret, value;
 
-	if (chip < 0 || WARN_ON_ONCE(chip > MAX_CE_NUM))
+	if (chip < 0 || WARN_ON_ONCE(chip >= meson_chip->nsels))
 		return;
 
 	nfc->param.chip_select = meson_chip->sels[chip] ? NAND_CE1 : NAND_CE0;

I am gonna fold this three patches if this is fine for you with the original patch adding the driver which is currently in my next branch.

Thanks,
Miquèl

#3 lore raw
Quoted 8 lines · Miquel Raynal

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_select_chip(struct nand_chip *nand, int chip) · line 231

Quoted 5 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
-	if (chip < 0 || WARN_ON_ONCE(chip > MAX_CE_NUM))
+	if (chip < 0 || WARN_ON_ONCE(chip >= meson_chip->nsels))
 		return;
 
 	nfc->param.chip_select = meson_chip->sels[chip] ? NAND_CE1 : NAND_CE0;

I am gonna fold this three patches if this is fine for you with the original patch adding the driver which is currently in my next branch.

No problem.

regards,
dan carpenter

maintainer
#4 lore raw
In reply to Dan Carpenter

Hi Dan,

Dan Carpenter <[email protected]> wrote on Fri, 1 Feb 2019 11:29:22 +0300:

Quoted 11 lines

This test is off by one because the > should be >= and it's also testing against the wrong limit. The MAX_CE_NUM is the maximum size that meson_chip->sels[] is allowed to be but meson_chip->nsels is the actual size.

Fixes 2d570b34b41a ("mtd: rawnand: meson: add support for Amlogic NAND flash controller ")
---
 drivers/mtd/nand/raw/meson_nand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Series merged in nand/next with the original commit.

Thanks,
Miquèl