mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mtd: rawnand: propagate timing-mode recovery failures
@ 2026-11-04  6:13 James Hilliard
  2026-11-18 10:28 ` Miquel Raynal
  0 siblings, 1 reply; 4+ messages in thread
From: James Hilliard @ 2026-11-04  6:13 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, Boris Brezillon
  Cc: linux-mtd, linux-kernel, James Hilliard

When GET_FEATURES succeeds but the chip does not acknowledge the requested
timing mode, nand_setup_interface() falls back to mode 0. Both the
controller-interface reset and the NAND RESET command can fail, but their
return values are discarded. The function then returns the successful
GET_FEATURES status even though the fallback did not complete.

Check the controller reset before issuing RESET and propagate either
recovery error when there was no earlier error. Preserve an earlier
GET_FEATURES failure and keep returning success when a timing mismatch
is recovered by a successful mode-0 fallback.

Fixes: 415ae78ffb5d ("mtd: rawnand: check ONFI timings have been acked by the chip")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 drivers/mtd/nand/raw/nand_base.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index a5b278ab9384..cb57a7d81810 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -840,7 +840,7 @@ static int nand_setup_interface(struct nand_chip *chip, int chipnr)
 {
 	const struct nand_controller_ops *ops = chip->controller->ops;
 	u8 tmode_param[ONFI_SUBFEATURE_PARAM_LEN] = { }, request;
-	int ret;
+	int ret, reset_ret;
 
 	if (!nand_controller_can_setup_interface(chip))
 		return 0;
@@ -909,12 +909,15 @@ static int nand_setup_interface(struct nand_chip *chip, int chipnr)
 	 * Fallback to mode 0 if the chip explicitly did not ack the chosen
 	 * timing mode.
 	 */
-	nand_reset_interface(chip, chipnr);
+	reset_ret = nand_reset_interface(chip, chipnr);
+	if (reset_ret)
+		return ret ?: reset_ret;
+
 	nand_select_target(chip, chipnr);
-	nand_reset_op(chip);
+	reset_ret = nand_reset_op(chip);
 	nand_deselect_target(chip);
 
-	return ret;
+	return ret ?: reset_ret;
 }
 
 /**

---
base-commit: 30daaf3e7897b4a8d9b72e5b0c86dd6e2a4d7d85
change-id: 20261103-submit-rawnand-timing-recovery-v1-a64432f26f3c

Best regards,
--  
James Hilliard <james.hilliard1@gmail.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mtd: rawnand: propagate timing-mode recovery failures
  2026-11-04  6:13 [PATCH] mtd: rawnand: propagate timing-mode recovery failures James Hilliard
@ 2026-11-18 10:28 ` Miquel Raynal
  2026-11-18 16:49   ` James Hilliard
  0 siblings, 1 reply; 4+ messages in thread
From: Miquel Raynal @ 2026-11-18 10:28 UTC (permalink / raw)
  To: James Hilliard
  Cc: Richard Weinberger, Vignesh Raghavendra, Boris Brezillon,
	linux-mtd, linux-kernel

On 03/11/2026 at 23:13:18 -07, James Hilliard <james.hilliard1@gmail.com> wrote:

> When GET_FEATURES succeeds but the chip does not acknowledge the requested
> timing mode, nand_setup_interface() falls back to mode 0. Both the
> controller-interface reset and the NAND RESET command can fail, but their
> return values are discarded. The function then returns the successful
> GET_FEATURES status even though the fallback did not complete.
>
> Check the controller reset before issuing RESET and propagate either
> recovery error when there was no earlier error. Preserve an earlier
> GET_FEATURES failure and keep returning success when a timing mismatch
> is recovered by a successful mode-0 fallback.

You are carrying a return value in an error path of an error path. If
the reset actually fails, the very next attempt will fail and probe will
be aborted anyway. So while the fix is not inherently wrong, the title
and commit log overstate the problem.

My proposal:

mtd: rawnand: propagate mode-0 fallback failures

When a chip does not acknowledge the requested timing mode,
nand_setup_interface() falls back to mode 0 by resetting the controller
interface and issuing a NAND RESET. Either step can fail; returning
success will likely lead to any later attempt at talking to the chip to
fail.

Make sure the error path propagates those failures in the mode-0
fallback case.

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mtd: rawnand: propagate timing-mode recovery failures
  2026-11-18 10:28 ` Miquel Raynal
@ 2026-11-18 16:49   ` James Hilliard
  2026-11-18 17:15     ` Miquel Raynal
  0 siblings, 1 reply; 4+ messages in thread
From: James Hilliard @ 2026-11-18 16:49 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Richard Weinberger, Vignesh Raghavendra, Boris Brezillon,
	linux-mtd, linux-kernel

On Wed, Nov 18, 2026 at 3:28 AM Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
> On 03/11/2026 at 23:13:18 -07, James Hilliard <james.hilliard1@gmail.com> wrote:
>
> > When GET_FEATURES succeeds but the chip does not acknowledge the requested
> > timing mode, nand_setup_interface() falls back to mode 0. Both the
> > controller-interface reset and the NAND RESET command can fail, but their
> > return values are discarded. The function then returns the successful
> > GET_FEATURES status even though the fallback did not complete.
> >
> > Check the controller reset before issuing RESET and propagate either
> > recovery error when there was no earlier error. Preserve an earlier
> > GET_FEATURES failure and keep returning success when a timing mismatch
> > is recovered by a successful mode-0 fallback.
>
> You are carrying a return value in an error path of an error path. If
> the reset actually fails, the very next attempt will fail and probe will
> be aborted anyway. So while the fix is not inherently wrong, the title
> and commit log overstate the problem.
>
> My proposal:
>
> mtd: rawnand: propagate mode-0 fallback failures
>
> When a chip does not acknowledge the requested timing mode,
> nand_setup_interface() falls back to mode 0 by resetting the controller
> interface and issuing a NAND RESET. Either step can fail; returning
> success will likely lead to any later attempt at talking to the chip to
> fail.
>
> Make sure the error path propagates those failures in the mode-0
> fallback case.

There is also a caller outside probe: nand_do_write_oob() calls
nand_reset(), which calls nand_setup_interface(). If GET_FEATURES
reports a different timing mode and the fallback fails, nand_reset()
currently returns success and the OOB write continues past its reset
check. Propagating the fallback error lets the write stop there.

>
> Thanks,
> Miquèl

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mtd: rawnand: propagate timing-mode recovery failures
  2026-11-18 16:49   ` James Hilliard
@ 2026-11-18 17:15     ` Miquel Raynal
  0 siblings, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2026-11-18 17:15 UTC (permalink / raw)
  To: James Hilliard
  Cc: Richard Weinberger, Vignesh Raghavendra, Boris Brezillon,
	linux-mtd, linux-kernel

On 18/11/2026 at 09:49:52 -07, James Hilliard <james.hilliard1@gmail.com> wrote:

> On Wed, Nov 18, 2026 at 3:28 AM Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>>
>> On 03/11/2026 at 23:13:18 -07, James Hilliard <james.hilliard1@gmail.com> wrote:
>>
>> > When GET_FEATURES succeeds but the chip does not acknowledge the requested
>> > timing mode, nand_setup_interface() falls back to mode 0. Both the
>> > controller-interface reset and the NAND RESET command can fail, but their
>> > return values are discarded. The function then returns the successful
>> > GET_FEATURES status even though the fallback did not complete.
>> >
>> > Check the controller reset before issuing RESET and propagate either
>> > recovery error when there was no earlier error. Preserve an earlier
>> > GET_FEATURES failure and keep returning success when a timing mismatch
>> > is recovered by a successful mode-0 fallback.
>>
>> You are carrying a return value in an error path of an error path. If
>> the reset actually fails, the very next attempt will fail and probe will
>> be aborted anyway. So while the fix is not inherently wrong, the title
>> and commit log overstate the problem.
>>
>> My proposal:
>>
>> mtd: rawnand: propagate mode-0 fallback failures
>>
>> When a chip does not acknowledge the requested timing mode,
>> nand_setup_interface() falls back to mode 0 by resetting the controller
>> interface and issuing a NAND RESET. Either step can fail; returning
>> success will likely lead to any later attempt at talking to the chip to
>> fail.
>>
>> Make sure the error path propagates those failures in the mode-0
>> fallback case.
>
> There is also a caller outside probe: nand_do_write_oob() calls
> nand_reset(), which calls nand_setup_interface(). If GET_FEATURES
> reports a different timing mode and the fallback fails, nand_reset()
> currently returns success and the OOB write continues past its reset
> check. Propagating the fallback error lets the write stop there.

If you are at using nand_do_write_oob() there is no reason you would end
up in the error path of the setup interface step. This reset is super
legacy anyway, the comment says August 1999. This path is also not so
useful anymore. You can mention it at the end of the commit log though.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-18 17:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04  6:13 [PATCH] mtd: rawnand: propagate timing-mode recovery failures James Hilliard
2026-11-18 10:28 ` Miquel Raynal
2026-11-18 16:49   ` James Hilliard
2026-11-18 17:15     ` Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®