Skip to contentSkip to conversation

mtd: rawnand: fix an error code in nand_setup_interface()

PATCH In review Dan Carpenter 2 participants 4 messages Apr 14, 2021 – Apr 17, 2021

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

PATCH 1/1 mtd: rawnand: fix an error code in nand_setup_interface()

We should return an error code if the timing mode is not acknowledged by the NAND chip.

Fixes 415ae78ffb5d ("mtd: rawnand: check ONFI timings have been acked by the chip")

---
From static analysis. Not tested.

 drivers/mtd/nand/raw/nand_base.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/nand_base.c +1 -0
index fb072c444495..d83c0503f96f 100644
@@ -880,6 +880,7 @@ static int nand_setup_interface(struct nand_chip *chip, int chipnr)
 	if (tmode_param[0] != chip->best_interface_config->timings.mode) {
 		pr_warn("timing mode %d not acknowledged by the NAND chip\n",
 			chip->best_interface_config->timings.mode);
+		ret = -EINVAL;
 		goto err_reset_chip;
 	}
 
Signature · 1 line
2.30.2
maintainer
#1 lore raw

Hi Dan,

Dan Carpenter <[email protected]> wrote on Wed, 14 Apr 2021 08:56:33 +0300:

Quoted 2 lines

We should return an error code if the timing mode is not acknowledged by the NAND chip.

This truly is questionable (and I am not yet decided whether the answer should be yes or no).

Returning an error here would produce the entire boot sequence to fail, even though the NAND chip would work in mode 0.

Not returning an error would print the below warning (so the user/developer is warned) and continue the boot with the slowest timing interface.

Honestly I would be more in favor of letting things as they are because I don't think this may be considered as a buggy situation, but I am open to discussion.

Quoted 13 lines
Fixes 415ae78ffb5d ("mtd: rawnand: check ONFI timings have been acked by the chip")

---
From static analysis. Not tested.

 drivers/mtd/nand/raw/nand_base.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/nand_base.c +0 -0
index fb072c444495..d83c0503f96f 100644

drivers/mtd/nand/raw/nand_base.c static int nand_setup_interface(struct nand_chip *chip, int chipnr) · line 886

Quoted 7 lines
drivers/mtd/nand/raw/nand_base.c +1 -0
@@ -880,6 +880,7 @@ static int nand_setup_interface(struct nand_chip *chip, int chipnr)
 	if (tmode_param[0] != chip->best_interface_config->timings.mode) {
 		pr_warn("timing mode %d not acknowledged by the NAND chip\n",
 			chip->best_interface_config->timings.mode);
+		ret = -EINVAL;
 		goto err_reset_chip;
 	}
 

Thanks,
Miquèl

#2 lore raw
Quoted 14 lines · Miquel Raynal

Hi Dan,

Dan Carpenter <[email protected]> wrote on Wed, 14 Apr 2021 08:56:33 +0300:

Quoted 2 lines

We should return an error code if the timing mode is not acknowledged by the NAND chip.

This truly is questionable (and I am not yet decided whether the answer should be yes or no).

Returning an error here would produce the entire boot sequence to fail, even though the NAND chip would work in mode 0.

Quoted 8 lines

Not returning an error would print the below warning (so the user/developer is warned) and continue the boot with the slowest timing interface.

Honestly I would be more in favor of letting things as they are because I don't think this may be considered as a buggy situation, but I am open to discussion.

If we decided that the original code is correct then one way to silence the warning would be to do:

	if (tmode_param[0] != chip->best_interface_config->timings.mode) {
		pr_warn("timing mode %d not acknowledged by the NAND chip\n",
 			chip->best_interface_config->timings.mode);
		ret = 0;
		goto err_reset_chip;
	}

Setting "ret = 0;" right before the goto makes the code look more intentional to human readers as well.

regards,
dan carpenter

maintainer
#3 lore raw

Hi Dan,

Dan Carpenter <[email protected]> wrote on Sat, 17 Apr 2021 13:24:26 +0300:

Quoted 34 lines · Miquel Raynal
Quoted 14 lines

Hi Dan,

Dan Carpenter <[email protected]> wrote on Wed, 14 Apr 2021 08:56:33 +0300:

Quoted 2 lines

We should return an error code if the timing mode is not acknowledged by the NAND chip.

This truly is questionable (and I am not yet decided whether the answer should be yes or no).

Returning an error here would produce the entire boot sequence to fail, even though the NAND chip would work in mode 0.

Quoted 8 lines

Not returning an error would print the below warning (so the user/developer is warned) and continue the boot with the slowest timing interface.

Honestly I would be more in favor of letting things as they are because I don't think this may be considered as a buggy situation, but I am open to discussion.

If we decided that the original code is correct then one way to silence the warning would be to do:

	if (tmode_param[0] != chip->best_interface_config->timings.mode) {
		pr_warn("timing mode %d not acknowledged by the NAND chip\n",
 			chip->best_interface_config->timings.mode);
		ret = 0;
		goto err_reset_chip;
	}
Quoted 2 lines

Setting "ret = 0;" right before the goto makes the code look more intentional to human readers as well.

Absolutely right. Let's got for it then.

Cheers,
Miquèl