Re: [PATCH v2 1/2] mtd: rawnand: macronix: serialize OTP access with NAND operations

From: Miquel Raynal

Date: Tue Nov 24 2026 - 09:55:20 EST



> OTP I/O can also run while the chip is suspended.

Really? Where does that come from?

[...]

> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(nand_deselect_target);
> *
> * Release chip lock and wake up anyone waiting on the device.
> */
> -static void nand_release_device(struct nand_chip *chip)
> +void nand_release_device(struct nand_chip *chip)

You export a core helper...

> {
> /* Release the controller and the chip */
> mutex_unlock(&chip->controller->lock);
> @@ -336,7 +336,7 @@ static int nand_isbad_bbm(struct nand_chip *chip, loff_t ofs)
> *
> * Lock the device and its controller for exclusive access
> */
> -static void nand_get_device(struct nand_chip *chip)
> +void nand_get_device(struct nand_chip *chip)
> {
> /* Wait until the device is resumed. */
> while (1) {
> diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c
> index 16847f28b19d..d7f5a9e7c240 100644
> --- a/drivers/mtd/nand/raw/nand_macronix.c
> +++ b/drivers/mtd/nand/raw/nand_macronix.c
> @@ -380,6 +380,7 @@ static int __macronix_30lfxg18ac_rw_otp(struct mtd_info *mtd,
> int ret, cleanup_ret;
>
> nand = mtd_to_nand(mtd);
> + nand_get_device(nand);

...and you use it across the entire OTP operation...

> nand_select_target(nand, 0);
>
> ret = macronix_30lfxg18ac_otp_enable(nand);
> @@ -426,6 +427,7 @@ static int __macronix_30lfxg18ac_rw_otp(struct mtd_info *mtd,
> write ? "write" : "read");
>
> nand_deselect_target(nand);
> + nand_release_device(nand);
>
> return ret ? ret : cleanup_ret;
> }

...and in the commit log you mention:

> Make the existing NAND serialization helpers available within the raw
> NAND core and hold them across the entire OTP transaction

Why are you doing the serialization in one vendor driver then? Aren't
all the vendors affected by the exact same issue? Why isn't taking the
lock once for all in the core a better idea?

Miquèl