kernel: fix mtd/NVMEM regression affecting U-Boot env NVMEM driver
authorRafał Miłecki <rafal@milecki.pl>
Tue, 31 Oct 2023 16:09:45 +0000 (17:09 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Tue, 31 Oct 2023 16:33:28 +0000 (17:33 +0100)
Fixes: b5956700702b ("kernel: backport nvmem v6.6 fixes and v6.7 changes")
Fixes: https://github.com/openwrt/openwrt/issues/13831
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
target/linux/ath79/patches-5.15/400-mtd-nor-support-mtd-name-from-device-tree.patch
target/linux/ath79/patches-6.1/400-mtd-nor-support-mtd-name-from-device-tree.patch
target/linux/generic/hack-5.15/402-mtd-blktrans-call-add-disks-after-mtd-device.patch
target/linux/generic/hack-5.15/420-mtd-support-OpenWrt-s-MTD_ROOTFS_ROOT_DEV.patch
target/linux/generic/hack-6.1/402-mtd-blktrans-call-add-disks-after-mtd-device.patch
target/linux/generic/hack-6.1/420-mtd-support-OpenWrt-s-MTD_ROOTFS_ROOT_DEV.patch
target/linux/generic/pending-5.15/401-mtd-don-t-register-NVMEM-devices-for-partitions-with.patch [new file with mode: 0644]
target/linux/generic/pending-6.1/401-mtd-don-t-register-NVMEM-devices-for-partitions-with.patch [new file with mode: 0644]
target/linux/pistachio/patches-5.15/401-mtd-nor-support-mtd-name-from-device-tree.patch

index 7db6346c37e4180d998ae82c0e2b92a015c6a36a..36f5331bd017f9727185889f33f0575c93397952 100644 (file)
@@ -34,7 +34,7 @@ Signed-off-by: Abhimanyu Vishwakarma <Abhimanyu.Vishwakarma@imgtec.com>
        mtd->type = MTD_NORFLASH;
 --- a/drivers/mtd/mtdcore.c
 +++ b/drivers/mtd/mtdcore.c
-@@ -847,6 +847,17 @@ out_error:
+@@ -870,6 +870,17 @@ out_error:
   */
  static void mtd_set_dev_defaults(struct mtd_info *mtd)
  {
index 3546696a23a5d6457a86a63e96076b6ec4784b92..119868eddb33bb7b8b12f46edd11d4d7c092bf87 100644 (file)
@@ -33,7 +33,7 @@ Signed-off-by: Abhimanyu Vishwakarma <Abhimanyu.Vishwakarma@imgtec.com>
        mtd->flags = MTD_CAP_NORFLASH;
 --- a/drivers/mtd/mtdcore.c
 +++ b/drivers/mtd/mtdcore.c
-@@ -840,6 +840,17 @@ out_error:
+@@ -863,6 +863,17 @@ out_error:
   */
  static void mtd_set_dev_defaults(struct mtd_info *mtd)
  {
index 62737aa779f3bceeab99747c3e9feadadcca8183..1df6f2f18bfcfb0ed900afb821fe66121947ee7c 100644 (file)
@@ -77,7 +77,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
  
  #include "mtdcore.h"
  
-@@ -1083,6 +1084,8 @@ int mtd_device_parse_register(struct mtd
+@@ -1106,6 +1107,8 @@ int mtd_device_parse_register(struct mtd
                register_reboot_notifier(&mtd->reboot_notifier);
        }
  
index 947b2c262f339029728b10a2cb3c443af9ef70a3..ed46301b0ee77c8889da3bb58f3b05fa835b2cc1 100644 (file)
@@ -12,7 +12,7 @@ Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
 
 --- a/drivers/mtd/mtdcore.c
 +++ b/drivers/mtd/mtdcore.c
-@@ -761,7 +761,8 @@ int add_mtd_device(struct mtd_info *mtd)
+@@ -784,7 +784,8 @@ int add_mtd_device(struct mtd_info *mtd)
  
        mutex_unlock(&mtd_table_mutex);
  
index 295da11eb48dcbcb329749aeca122a15e482e201..c82ca3edd8402e24a2e4192f96e64f998369d641 100644 (file)
@@ -91,7 +91,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
  
  #include "mtdcore.h"
  
-@@ -1075,6 +1076,8 @@ int mtd_device_parse_register(struct mtd
+@@ -1098,6 +1099,8 @@ int mtd_device_parse_register(struct mtd
                register_reboot_notifier(&mtd->reboot_notifier);
        }
  
index 8e8e5cea8d6af28f09b0942048f18bb80f5abd40..7c7e4c814e611b093fadef27df032f1779fb14b3 100644 (file)
@@ -12,7 +12,7 @@ Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
 
 --- a/drivers/mtd/mtdcore.c
 +++ b/drivers/mtd/mtdcore.c
-@@ -750,7 +750,8 @@ int add_mtd_device(struct mtd_info *mtd)
+@@ -773,7 +773,8 @@ int add_mtd_device(struct mtd_info *mtd)
  
        mutex_unlock(&mtd_table_mutex);
  
diff --git a/target/linux/generic/pending-5.15/401-mtd-don-t-register-NVMEM-devices-for-partitions-with.patch b/target/linux/generic/pending-5.15/401-mtd-don-t-register-NVMEM-devices-for-partitions-with.patch
new file mode 100644 (file)
index 0000000..650e10a
--- /dev/null
@@ -0,0 +1,48 @@
+From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
+Date: Tue, 31 Oct 2023 15:51:01 +0100
+Subject: [PATCH] mtd: don't register NVMEM devices for partitions with custom
+ drivers
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This fixes issue exposed by upstream commit f4cf4e5db331 ("Revert
+"nvmem: add new config option"").
+
+Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
+---
+ drivers/mtd/mtdcore.c | 23 +++++++++++++++++++++++
+ 1 file changed, 23 insertions(+)
+
+--- a/drivers/mtd/mtdcore.c
++++ b/drivers/mtd/mtdcore.c
+@@ -537,6 +537,29 @@ static int mtd_nvmem_add(struct mtd_info
+       struct device_node *node = mtd_get_of_node(mtd);
+       struct nvmem_config config = {};
++      /*
++       * Do NOT register NVMEM device for any partition that is meant to be
++       * handled by a U-Boot env driver. That would result in associating two
++       * different NVMEM devices with the same OF node.
++       *
++       * An example of unwanted behaviour of above (forwardtrace):
++       * of_get_mac_addr_nvmem()
++       * of_nvmem_cell_get()
++       * __nvmem_device_get()
++       *
++       * We can't have __nvmem_device_get() return "mtdX" NVMEM device instead
++       * of U-Boot env NVMEM device. That would result in failing to find
++       * NVMEM cell.
++       *
++       * This issue seems to affect U-Boot env case only and will go away with
++       * switch to NVMEM layouts.
++       */
++      if (of_device_is_compatible(node, "u-boot,env") ||
++          of_device_is_compatible(node, "u-boot,env-redundant-bool") ||
++          of_device_is_compatible(node, "u-boot,env-redundant-count") ||
++          of_device_is_compatible(node, "brcm,env"))
++              return 0;
++
+       config.id = -1;
+       config.dev = &mtd->dev;
+       config.name = dev_name(&mtd->dev);
diff --git a/target/linux/generic/pending-6.1/401-mtd-don-t-register-NVMEM-devices-for-partitions-with.patch b/target/linux/generic/pending-6.1/401-mtd-don-t-register-NVMEM-devices-for-partitions-with.patch
new file mode 100644 (file)
index 0000000..42b5a56
--- /dev/null
@@ -0,0 +1,48 @@
+From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
+Date: Tue, 31 Oct 2023 15:51:01 +0100
+Subject: [PATCH] mtd: don't register NVMEM devices for partitions with custom
+ drivers
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This fixes issue exposed by upstream commit f4cf4e5db331 ("Revert
+"nvmem: add new config option"").
+
+Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
+---
+ drivers/mtd/mtdcore.c | 23 +++++++++++++++++++++++
+ 1 file changed, 23 insertions(+)
+
+--- a/drivers/mtd/mtdcore.c
++++ b/drivers/mtd/mtdcore.c
+@@ -519,6 +519,29 @@ static int mtd_nvmem_add(struct mtd_info
+       struct device_node *node = mtd_get_of_node(mtd);
+       struct nvmem_config config = {};
++      /*
++       * Do NOT register NVMEM device for any partition that is meant to be
++       * handled by a U-Boot env driver. That would result in associating two
++       * different NVMEM devices with the same OF node.
++       *
++       * An example of unwanted behaviour of above (forwardtrace):
++       * of_get_mac_addr_nvmem()
++       * of_nvmem_cell_get()
++       * __nvmem_device_get()
++       *
++       * We can't have __nvmem_device_get() return "mtdX" NVMEM device instead
++       * of U-Boot env NVMEM device. That would result in failing to find
++       * NVMEM cell.
++       *
++       * This issue seems to affect U-Boot env case only and will go away with
++       * switch to NVMEM layouts.
++       */
++      if (of_device_is_compatible(node, "u-boot,env") ||
++          of_device_is_compatible(node, "u-boot,env-redundant-bool") ||
++          of_device_is_compatible(node, "u-boot,env-redundant-count") ||
++          of_device_is_compatible(node, "brcm,env"))
++              return 0;
++
+       config.id = -1;
+       config.dev = &mtd->dev;
+       config.name = dev_name(&mtd->dev);
index 7db6346c37e4180d998ae82c0e2b92a015c6a36a..36f5331bd017f9727185889f33f0575c93397952 100644 (file)
@@ -34,7 +34,7 @@ Signed-off-by: Abhimanyu Vishwakarma <Abhimanyu.Vishwakarma@imgtec.com>
        mtd->type = MTD_NORFLASH;
 --- a/drivers/mtd/mtdcore.c
 +++ b/drivers/mtd/mtdcore.c
-@@ -847,6 +847,17 @@ out_error:
+@@ -870,6 +870,17 @@ out_error:
   */
  static void mtd_set_dev_defaults(struct mtd_info *mtd)
  {