mtd: nand: cadence: Fix device assignment to avoid warm reset issue
authorDinesh Maniyam <dinesh.maniyam@altera.com>
Tue, 19 Aug 2025 08:35:09 +0000 (16:35 +0800)
committerMichael Trimarchi <michael@amarulasolutions.com>
Sat, 23 Aug 2025 14:37:05 +0000 (16:37 +0200)
The driver currently does:
    mtd->dev->parent = cadence->dev;

This works in Linux because `struct mtd_info` embeds a `struct device`,
so `mtd->dev` is always valid and its `.parent` can be set.

In U-Boot, however, `mtd->dev` is only a pointer to a `struct udevice`.
Dereferencing it before assignment is invalid, which breaks the device
hierarchy. As a result, consumers relying on `mtd->dev` (e.g. partition
parser, reset and re-init paths) operate on a dangling pointer. This
leads to failures during warm reset when the NAND device is accessed
again.

Fix by assigning the device pointer directly:
    mtd->dev = cadence->dev;

This matches U-Boot’s device model, preserves a valid hierarchy, and
resolves the warm reset issue on Cadence NAND.

Fixes: ebc41cad ("drivers: mtd: nand: Add driver for Cadence Nand")
Signed-off-by: Dinesh Maniyam <dinesh.maniyam@altera.com>
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
drivers/mtd/nand/raw/cadence_nand.c

index 27aa7f9..4771440 100644 (file)
@@ -2196,7 +2196,7 @@ static int cadence_nand_chip_init(struct cadence_nand_info *cadence, ofnode node
        chip->controller = &cadence->controller;
        nand_set_flash_node(chip, node);
        mtd = nand_to_mtd(chip);
-       mtd->dev->parent = cadence->dev;
+       mtd->dev = cadence->dev;
 
        chip->options |= NAND_BUSWIDTH_AUTO;
        chip->select_chip = cadence_nand_select_chip;