[PATCH v2 1/2] mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe

From: Manikandan Muralidharan

Date: Mon Nov 30 2026 - 02:45:24 EST


When a SPI NOR flash is not populated or not reachable, spi_nor_scan()
fails and nothing described below the flash node (the SFDP NVMEM device,
its nvmem-layout, partitions) is ever registered. fw_devlink still holds
links from consumers of those nodes, so a consumer such as an Ethernet
MAC whose "nvmem-cells" points at the SFDP EUI-48 cell waits for its
supplier forever and is never probed:

platform f8008000.ethernet: deferred probe pending: platform: wait for
supplier /ahb/apb/spi@f0024000/flash@0/sfdp/nvmem-layout/mac-address

On a permanent spi_nor_scan() failure, call
fw_devlink_purge_absent_suppliers() on each child of the flash node to
drop their consumer links, so the consumer is probed. Keep the links on
-EPROBE_DEFER, as the flash may still probe once the reset GPIO or
regulator is available.

Signed-off-by: Manikandan Muralidharan <manikandan.m@xxxxxxxxxxxxx>
---
drivers/mtd/spi-nor/core.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 99584ee0ecb3..c2661dc2395b 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -12,6 +12,7 @@
#include <linux/device.h>
#include <linux/err.h>
#include <linux/errno.h>
+#include <linux/fwnode.h>
#include <linux/math64.h>
#include <linux/module.h>
#include <linux/mtd/mtd.h>
@@ -3624,6 +3625,25 @@ static int spi_nor_create_write_dirmap(struct spi_nor *nor)
return PTR_ERR_OR_ZERO(nor->dirmap.wdesc);
}

+/**
+ * spi_nor_purge_absent_suppliers() - drop fw_devlink links below a missing
+ * flash
+ * @dev: pointer to the flash 'struct device'
+ *
+ * When the flash cannot be probed (e.g. it is not populated or not
+ * reachable), nothing described below its node, such as the SFDP NVMEM
+ * device or the partitions, is ever registered. Mark those nodes as never
+ * becoming devices and drop their consumer links, so that consumers such as
+ * an Ethernet MAC using an NVMEM cell are not deferred forever.
+ */
+static void spi_nor_purge_absent_suppliers(struct device *dev)
+{
+ struct fwnode_handle *child;
+
+ device_for_each_child_node(dev, child)
+ fw_devlink_purge_absent_suppliers(child);
+}
+
static int spi_nor_probe(struct spi_mem *spimem)
{
struct spi_device *spi = spimem->spi;
@@ -3672,8 +3692,12 @@ static int spi_nor_probe(struct spi_mem *spimem)
flash_name = spi->modalias;

ret = spi_nor_scan(nor, flash_name, &hwcaps);
- if (ret)
+ if (ret) {
+ /* A deferred probe (e.g. on the reset GPIO) may still succeed. */
+ if (ret != -EPROBE_DEFER)
+ spi_nor_purge_absent_suppliers(dev);
return ret;
+ }

spi_nor_debugfs_register(nor);

--
2.43.0