mtd/nvmem: don't defer forever on absent NVMEM suppliers
Subsystems (3)
v2 cover mtd/nvmem: don't defer forever on absent NVMEM suppliers
A consumer that gets its MAC address from an NVMEM cell can be deferred forever when the cell will never appear, instead of falling back to another address source. These came up while testing the SFDP EUI-48 series [1], where macb reads its MAC address from a cell exposed by the QSPI flash, but both are generic:
- 1/2: when the SPI NOR flash is not populated or not reachable, nothing below its node is ever registered, yet fw_devlink keeps the consumer from probing. Drop the fw_devlink links below a flash that failed to probe.
- 2/2: the NVMEM lookup keeps returning -EPROBE_DEFER for a provider that never shows up, or for a cell that a bound layout did not add, e.g. when the data it describes is not programmed on the device. Once the deferred probe timeout has expired, return -ENOENT instead.
In both cases the consumer then falls back once the deferred probe timeout has expired (10 seconds by default),
e.g. macb uses the address left by the bootloader or a random one.
This series depends on the SFDP EUI-48 series [1] and applies on top of it.
Changes in v2:
- 1/2 - Drop the FWNODE_FLAG_NOT_DEVICE check in of_nvmem_cell_get():
The patch now only touches the SPI NOR core.
- 2/2 - Replace the "layout is bound" check with a fallback once the deferred probe timeout has expired. This covers both the absent flash and the missing cell without touching the layout device, so it no longer races with the layout probe or removal. Renamed from "nvmem: core: don't defer for a missing cell once the layout is bound".
v1: https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/all/[email protected]/
Manikandan Muralidharan (2):
mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to
probe
nvmem: core: stop deferring for a cell after the deferred probe
timeout
drivers/mtd/spi-nor/core.c | 26 +++++++++++++++++++++++++- drivers/nvmem/core.c | 9 +++++++++ 2 files changed, 34 insertions(+), 1 deletion(-)
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
prerequisite-patch-id: 76d8b1168f88c3e7912ac2ce01a705f7e69d8a3b
prerequisite-patch-id: b360d0d00ac1a6feb76d4b3f9412b6f1741f6161
prerequisite-patch-id: 659801d6f415ba79ce51f21b3a4f5e132348c150
prerequisite-patch-id: 902c67d8bcfad07fc6424ee551557eeab87efaa4
prerequisite-patch-id: 94ede38b6c2480cb1e0e102e9bbeb6ffd5b276ef
prerequisite-patch-id: ae3977b6c56c5bd4f352d77bd8a7883a69d390af
prerequisite-patch-id: 58d0ad25e81f16f60864d624eed7ff481607e960
prerequisite-patch-id: ba140b71fdbfc992861ae4c34b6acc737d4e4528
Signature · 1 line
2.43.0
PATCH v2 1/2 mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe
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.
--- drivers/mtd/spi-nor/core.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/core.c +25 -1
@@ -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);
Signature · 1 line
2.43.0
PATCH v2 2/2 nvmem: core: stop deferring for a cell after the deferred probe timeout
In reply to Manikandan Muralidharannvmem_cell_get() returns -EPROBE_DEFER for as long as the nvmem device providing a DT cell is not registered. When that device never shows up, for instance because the flash holding the cell is not populated on the board, the consumer is deferred forever instead of falling back to another source.
Once the deferred probe timeout has expired, as reported by driver_deferred_probe_check_state(), return -ENOENT instead, so that the consumer treats the cell as missing. A provider that is merely late is still waited for until then.
--- drivers/nvmem/core.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/nvmem/core.c +9 -0
@@ -1508,6 +1508,15 @@ struct nvmem_cell *nvmem_cell_get(struct device *dev, const char *id)if (dev->of_node) {/* try dt first */ cell =of_nvmem_cell_get (dev->of_node, id); +/* +* Don't wait forever for a provider that never shows up, e.g. +* when the device holding it is not populated. Once the +* deferred probe timeout has expired, report the cell as +* missing so that the consumer can fall back. +*/ +if (PTR_ERR (cell) == -EPROBE_DEFER && +driver_deferred_probe_check_state (dev) != -EPROBE_DEFER ) +return ERR_PTR (-ENOENT );if (!IS_ERR (cell) ||PTR_ERR (cell) == -EPROBE_DEFER )return cell; }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v2 1/2] mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe
In reply to Manikandan MuralidharanThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] mtd: spi-nor: missing deferred probe trigger in spi_nor_probe() error path - [Medium] mtd: spi-nor…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] mtd: spi-nor: missing deferred probe trigger in spi_nor_probe() error path
- [Medium] mtd: spi-nor: incomplete supplier purging in spi_nor_probe() on error paths
--
commit c60e9abc61b54c89108b300ba9fa15df3cb4bd41
Author: Manikandan Muralidharan <[email protected]>
mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe
This commit calls fw_devlink_purge_absent_suppliers() on child fwnodes of a SPI NOR flash when spi_nor_scan() fails with a non-deferral error so that consumers waiting on child nodes are not blocked forever by fw_devlink.
Quoted 4 lines
drivers/mtd/spi-nor/core.c +0
-0
[ ... ]
Quoted 12 lines
drivers/mtd/spi-nor/core.c +8
-0@@ -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
drivers/mtd/spi-nor/core.c static int spi_nor_create_write_dirmap(struct spi_nor *nor) · line 3645
Quoted 10 lines
drivers/mtd/spi-nor/core.c +10
-0+* 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); +}
[Severity: High]
Does purging the fwnode links on a failed probe wake consumers that are already on deferred_probe_pending_list?
fw_devlink_purge_absent_suppliers() drops the consumer fwnode links via fwnode_links_purge_consumers(), which does not call driver_deferred_probe_trigger(). Because spi_nor_probe() then returns a non-zero error, really_probe() jumps to probe_failed without calling driver_bound() or driver_deferred_probe_trigger().
If the consumer already deferred in device_links_check_suppliers() before spi_nor_probe() ran (for example, when spi-nor or the SPI controller driver is loaded as a module after the deferred probe timeout, or when the flash is probed after the consumer during the final deferred_probe_work_func() pass), nothing moves the consumer from deferred_probe_pending_list to deferred_probe_active_list unless an unrelated device binds later.
Quoted 4 lines
drivers/mtd/spi-nor/core.c +0
-0static int spi_nor_probe (struct spi_mem *spimem) {struct spi_device *spi = spimem->spi;
drivers/mtd/spi-nor/core.c static int spi_nor_probe(struct spi_mem *spimem) · line 3700
Quoted 10 lines
drivers/mtd/spi-nor/core.c +5
-1@@ -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; + }
[Severity: Medium]
Can spi_nor_purge_absent_suppliers() miss the nvmem-layout child nodes when spi_nor_scan() fails after registering the SFDP NVMEM device?
Inside spi_nor_scan(), spi_nor_init_params() calls spi_nor_register_sfdp_nvmem() before spi_nor_late_init_params(), spi_nor_setup(), spi_nor_init() and spi_nor_set_mtd_info(). spi_nor_register_sfdp_nvmem() uses devm_nvmem_register(), which populates the nvmem-layout child device and sets fwnode->dev on the nvmem-layout fwnode via nvmem_layout_create_device().
If a later step in spi_nor_scan() fails, spi_nor_purge_absent_suppliers() runs before really_probe() calls devres_release_all(). At that point fwnode->dev is still non-NULL on the nvmem-layout fwnode, so fw_devlink_purge_absent_suppliers() returns early at the "if (fwnode->dev) return;" check without purging consumer links on the layout node or recursing into its child cell nodes (such as mac-address).
Also, if spi_nor_probe() fails with a permanent error outside spi_nor_scan() (such as in devm_regulator_get_enable(), dirmap creation, or mtd_device_register()), spi_nor_purge_absent_suppliers() is not called at all.
Signature · 5 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v2 1/2] mtd: spi-nor: drop fw_devlink suppliers below a flash that failed to probe
Hi,
+Cc Saravana.
Quoted 42 lines · On 11/30/26 1:47 PM, [email protected] wrote:
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] mtd: spi-nor: missing deferred probe trigger inspi_nor_probe()error path
- [Medium] mtd: spi-nor: incomplete supplier purging inspi_nor_probe()on error paths
--commit
c60e9abc61b54c89108b300ba9fa15df3cb4bd41
Author: Manikandan Muralidharan <[email protected]>mtd: spi-nor: drop
fw_devlinksuppliers below a flash that failed to probeThis commit calls
fw_devlink_purge_absent_suppliers()on child fwnodes of a SPI NOR flash whenspi_nor_scan()fails with a non-deferral error so that consumers waiting on child nodes are not blocked forever byfw_devlink.Quoted 4 lines
drivers/mtd/spi-nor/core.c +0
-0[ ... ]
Quoted 18 lines
drivers/mtd/spi-nor/core.c +14
-0@@ -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;
Quoted 9 lines
drivers/mtd/spi-nor/core.c static int spi_nor_create_write_dirmap(struct spi_nor *nor) · line 3645
Quoted 4 lines
drivers/mtd/spi-nor/core.c +4
-0+ +device_for_each_child_node (dev, child) +fw_devlink_purge_absent_suppliers (child); +}[Severity: High]
Does purging the fwnode links on a failed probe wake consumers that are already ondeferred_probe_pending_list?
Not from spi-nor itself. A consumer that deferred earlier is retried by the deferred probe timeout, or by the controller binding when the flash is probed from its probe.
Quoted 19 lines
fw_devlink_purge_absent_suppliers()drops the consumer fwnode links viafwnode_links_purge_consumers(), which does not calldriver_deferred_probe_trigger(). Becausespi_nor_probe()then returns a non-zero error,really_probe()jumps toprobe_failedwithout callingdriver_bound()ordriver_deferred_probe_trigger().If the consumer already deferred in
device_links_check_suppliers()beforespi_nor_probe()ran (for example, when spi-nor or the SPI controller driver is loaded as a module after the deferred probe timeout, or when the flash is probed after the consumer during the finaldeferred_probe_work_func()pass), nothing moves the consumer fromdeferred_probe_pending_listtodeferred_probe_active_listunless an unrelated device binds later.Quoted 6 lines
drivers/mtd/spi-nor/core.c +0
-0static 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;
Quoted 12 lines
drivers/mtd/spi-nor/core.c static int spi_nor_probe(struct spi_mem *spimem) · line 3700
Quoted 8 lines
drivers/mtd/spi-nor/core.c +5
-1ret =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; + }[Severity: Medium]
Canspi_nor_purge_absent_suppliers()miss the nvmem-layout child nodes whenspi_nor_scan()fails after registering the SFDP NVMEM device?
This series targets a flash that is not populated or not reachable, which fails before anything below its node is registered. A flash that is detected but then fails setup, or fails later in spi_nor_probe(), is out of scope.
Quoted 22 lines
Inside
spi_nor_scan(),spi_nor_init_params()callsspi_nor_register_sfdp_nvmem()beforespi_nor_late_init_params(),spi_nor_setup(),spi_nor_init()andspi_nor_set_mtd_info().spi_nor_register_sfdp_nvmem()usesdevm_nvmem_register(), which populates the nvmem-layout child device and setsfwnode->devon the nvmem-layout fwnode vianvmem_layout_create_device().If a later step in
spi_nor_scan()fails,spi_nor_purge_absent_suppliers()runs beforereally_probe()callsdevres_release_all(). At that pointfwnode->devis still non-NULL on the nvmem-layout fwnode, sofw_devlink_purge_absent_suppliers()returns early at the "if (fwnode->dev) return;" check without purging consumer links on the layout node or recursing into its child cell nodes (such as mac-address).Also, if
spi_nor_probe()fails with a permanent error outsidespi_nor_scan()(such as indevm_regulator_get_enable(), dirmap creation, ormtd_device_register()),spi_nor_purge_absent_suppliers()is not called at all.--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Signature · 2 lines
Thanks and Regards, Manikandan M.