401-mtd-don-t-register-NVMEM-devices-for-partitions-with.patch 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  2. Date: Tue, 31 Oct 2023 15:51:01 +0100
  3. Subject: [PATCH] mtd: don't register NVMEM devices for partitions with custom
  4. drivers
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. This fixes issue exposed by upstream commit f4cf4e5db331 ("Revert
  9. "nvmem: add new config option"").
  10. Signed-off-by: Rafał Miłecki <[email protected]>
  11. ---
  12. drivers/mtd/mtdcore.c | 23 +++++++++++++++++++++++
  13. 1 file changed, 23 insertions(+)
  14. --- a/drivers/mtd/mtdcore.c
  15. +++ b/drivers/mtd/mtdcore.c
  16. @@ -519,6 +519,29 @@ static int mtd_nvmem_add(struct mtd_info
  17. struct device_node *node = mtd_get_of_node(mtd);
  18. struct nvmem_config config = {};
  19. + /*
  20. + * Do NOT register NVMEM device for any partition that is meant to be
  21. + * handled by a U-Boot env driver. That would result in associating two
  22. + * different NVMEM devices with the same OF node.
  23. + *
  24. + * An example of unwanted behaviour of above (forwardtrace):
  25. + * of_get_mac_addr_nvmem()
  26. + * of_nvmem_cell_get()
  27. + * __nvmem_device_get()
  28. + *
  29. + * We can't have __nvmem_device_get() return "mtdX" NVMEM device instead
  30. + * of U-Boot env NVMEM device. That would result in failing to find
  31. + * NVMEM cell.
  32. + *
  33. + * This issue seems to affect U-Boot env case only and will go away with
  34. + * switch to NVMEM layouts.
  35. + */
  36. + if (of_device_is_compatible(node, "u-boot,env") ||
  37. + of_device_is_compatible(node, "u-boot,env-redundant-bool") ||
  38. + of_device_is_compatible(node, "u-boot,env-redundant-count") ||
  39. + of_device_is_compatible(node, "brcm,env"))
  40. + return 0;
  41. +
  42. config.id = NVMEM_DEVID_NONE;
  43. config.dev = &mtd->dev;
  44. config.name = dev_name(&mtd->dev);