kernel: 6.1: backport UBI device model improvements
authorDaniel Golle <daniel@makrotopia.org>
Tue, 5 Dec 2023 03:44:05 +0000 (03:44 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Thu, 15 Feb 2024 19:06:36 +0000 (19:06 +0000)
Backport two commits from Linux 6.3 wiring up device node parents of
ubi devices (pointing to their MTD parent) as well as ubiblock devices
(poiting to their parent UBI volume).

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
target/linux/bcm53xx/patches-6.1/500-UBI-Detect-EOF-mark-and-erase-all-remaining-blocks.patch
target/linux/generic/backport-6.1/424-v6.3-mtd-ubi-wire-up-parent-MTD-device.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/424-v6.4-0004-mtd-core-prepare-mtd_otp_nvmem_add-to-handle-EPROBE_.patch [deleted file]
target/linux/generic/backport-6.1/425-v6.3-mtd-ubi-block-wire-up-device-parent.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/426-v6.4-0004-mtd-core-prepare-mtd_otp_nvmem_add-to-handle-EPROBE_.patch [new file with mode: 0644]
target/linux/generic/pending-6.1/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch

index 209c57ca0bdbbc81daa76fdaf53d3c787d050649..e6140d9a704ba22e8654b9a6e7c97ff6c2de2f9b 100644 (file)
@@ -49,7 +49,7 @@ Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
                        return UBI_IO_BAD_HDR_EBADMSG;
 --- a/drivers/mtd/ubi/ubi.h
 +++ b/drivers/mtd/ubi/ubi.h
-@@ -820,6 +820,7 @@ extern struct mutex ubi_devices_mutex;
+@@ -822,6 +822,7 @@ extern struct mutex ubi_devices_mutex;
  extern struct blocking_notifier_head ubi_notifiers;
  
  /* attach.c */
diff --git a/target/linux/generic/backport-6.1/424-v6.3-mtd-ubi-wire-up-parent-MTD-device.patch b/target/linux/generic/backport-6.1/424-v6.3-mtd-ubi-wire-up-parent-MTD-device.patch
new file mode 100644 (file)
index 0000000..6574041
--- /dev/null
@@ -0,0 +1,33 @@
+From 1ecf9e390452e73a362ea7fbde8f3f0db83de856 Mon Sep 17 00:00:00 2001
+From: Daniel Golle <daniel@makrotopia.org>
+Date: Thu, 22 Dec 2022 19:33:04 +0000
+Subject: [PATCH] mtd: ubi: wire-up parent MTD device
+
+Wire up the device parent pointer of UBI devices to their lower MTD
+device, typically an MTD partition or whole-chip device.
+
+The most noticeable change is that in sysfs, previously ubi devices
+would be could in /sys/devices/virtual/ubi while after this change they
+would be correctly attached to their parent MTD device, e.g.
+
+/sys/devices/platform/1100d000.spi/spi_master/spi1/spi1.0/mtd/mtd2/ubi0.
+
+Locating UBI devices using /sys/class/ubi/ of course still works as
+well.
+
+Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+Signed-off-by: Richard Weinberger <richard@nod.at>
+---
+ drivers/mtd/ubi/build.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/drivers/mtd/ubi/build.c
++++ b/drivers/mtd/ubi/build.c
+@@ -929,6 +929,7 @@ int ubi_attach_mtd_dev(struct mtd_info *
+       ubi->dev.release = dev_release;
+       ubi->dev.class = &ubi_class;
+       ubi->dev.groups = ubi_dev_groups;
++      ubi->dev.parent = &mtd->dev;
+       ubi->mtd = mtd;
+       ubi->ubi_num = ubi_num;
diff --git a/target/linux/generic/backport-6.1/424-v6.4-0004-mtd-core-prepare-mtd_otp_nvmem_add-to-handle-EPROBE_.patch b/target/linux/generic/backport-6.1/424-v6.4-0004-mtd-core-prepare-mtd_otp_nvmem_add-to-handle-EPROBE_.patch
deleted file mode 100644 (file)
index 9ddda42..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-From 281f7a6c1a33fffcde32001bacbb4f672140fbf9 Mon Sep 17 00:00:00 2001
-From: Michael Walle <michael@walle.cc>
-Date: Wed, 8 Mar 2023 09:20:21 +0100
-Subject: [PATCH] mtd: core: prepare mtd_otp_nvmem_add() to handle
- -EPROBE_DEFER
-
-NVMEM soon will get the ability for nvmem layouts and these might
-not be ready when nvmem_register() is called and thus it might
-return -EPROBE_DEFER. Don't print the error message in this case.
-
-Signed-off-by: Michael Walle <michael@walle.cc>
-Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
-Link: https://lore.kernel.org/linux-mtd/20230308082021.870459-4-michael@walle.cc
----
- drivers/mtd/mtdcore.c | 7 +++----
- 1 file changed, 3 insertions(+), 4 deletions(-)
-
---- a/drivers/mtd/mtdcore.c
-+++ b/drivers/mtd/mtdcore.c
-@@ -953,8 +953,8 @@ static int mtd_otp_nvmem_add(struct mtd_
-                       nvmem = mtd_otp_nvmem_register(mtd, "user-otp", size,
-                                                      mtd_nvmem_user_otp_reg_read);
-                       if (IS_ERR(nvmem)) {
--                              dev_err(dev, "Failed to register OTP NVMEM device\n");
--                              return PTR_ERR(nvmem);
-+                              err = PTR_ERR(nvmem);
-+                              goto err;
-                       }
-                       mtd->otp_user_nvmem = nvmem;
-               }
-@@ -971,7 +971,6 @@ static int mtd_otp_nvmem_add(struct mtd_
-                       nvmem = mtd_otp_nvmem_register(mtd, "factory-otp", size,
-                                                      mtd_nvmem_fact_otp_reg_read);
-                       if (IS_ERR(nvmem)) {
--                              dev_err(dev, "Failed to register OTP NVMEM device\n");
-                               err = PTR_ERR(nvmem);
-                               goto err;
-                       }
-@@ -983,7 +982,7 @@ static int mtd_otp_nvmem_add(struct mtd_
- err:
-       nvmem_unregister(mtd->otp_user_nvmem);
--      return err;
-+      return dev_err_probe(dev, err, "Failed to register OTP NVMEM device\n");
- }
- /**
diff --git a/target/linux/generic/backport-6.1/425-v6.3-mtd-ubi-block-wire-up-device-parent.patch b/target/linux/generic/backport-6.1/425-v6.3-mtd-ubi-block-wire-up-device-parent.patch
new file mode 100644 (file)
index 0000000..48bf986
--- /dev/null
@@ -0,0 +1,49 @@
+From 05b8773ca33253ea562be145cf3145b05ef19f86 Mon Sep 17 00:00:00 2001
+From: Daniel Golle <daniel@makrotopia.org>
+Date: Thu, 22 Dec 2022 19:33:31 +0000
+Subject: [PATCH] mtd: ubi: block: wire-up device parent
+
+ubiblock devices were previously only identifyable by their name, but
+not connected to their parent UBI volume device e.g. in sysfs.
+Properly parent ubiblock device as descendant of a UBI volume device
+to reflect device model hierachy.
+
+Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+Signed-off-by: Richard Weinberger <richard@nod.at>
+---
+ drivers/mtd/ubi/block.c | 2 +-
+ drivers/mtd/ubi/kapi.c  | 1 +
+ include/linux/mtd/ubi.h | 1 +
+ 3 files changed, 3 insertions(+), 1 deletion(-)
+
+--- a/drivers/mtd/ubi/block.c
++++ b/drivers/mtd/ubi/block.c
+@@ -452,7 +452,7 @@ int ubiblock_create(struct ubi_volume_in
+       list_add_tail(&dev->list, &ubiblock_devices);
+       /* Must be the last step: anyone can call file ops from now on */
+-      ret = add_disk(dev->gd);
++      ret = device_add_disk(vi->dev, dev->gd, NULL);
+       if (ret)
+               goto out_destroy_wq;
+--- a/drivers/mtd/ubi/kapi.c
++++ b/drivers/mtd/ubi/kapi.c
+@@ -79,6 +79,7 @@ void ubi_do_get_volume_info(struct ubi_d
+       vi->name_len = vol->name_len;
+       vi->name = vol->name;
+       vi->cdev = vol->cdev.dev;
++      vi->dev = &vol->dev;
+ }
+ /**
+--- a/include/linux/mtd/ubi.h
++++ b/include/linux/mtd/ubi.h
+@@ -110,6 +110,7 @@ struct ubi_volume_info {
+       int name_len;
+       const char *name;
+       dev_t cdev;
++      struct device *dev;
+ };
+ /**
diff --git a/target/linux/generic/backport-6.1/426-v6.4-0004-mtd-core-prepare-mtd_otp_nvmem_add-to-handle-EPROBE_.patch b/target/linux/generic/backport-6.1/426-v6.4-0004-mtd-core-prepare-mtd_otp_nvmem_add-to-handle-EPROBE_.patch
new file mode 100644 (file)
index 0000000..9ddda42
--- /dev/null
@@ -0,0 +1,47 @@
+From 281f7a6c1a33fffcde32001bacbb4f672140fbf9 Mon Sep 17 00:00:00 2001
+From: Michael Walle <michael@walle.cc>
+Date: Wed, 8 Mar 2023 09:20:21 +0100
+Subject: [PATCH] mtd: core: prepare mtd_otp_nvmem_add() to handle
+ -EPROBE_DEFER
+
+NVMEM soon will get the ability for nvmem layouts and these might
+not be ready when nvmem_register() is called and thus it might
+return -EPROBE_DEFER. Don't print the error message in this case.
+
+Signed-off-by: Michael Walle <michael@walle.cc>
+Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
+Link: https://lore.kernel.org/linux-mtd/20230308082021.870459-4-michael@walle.cc
+---
+ drivers/mtd/mtdcore.c | 7 +++----
+ 1 file changed, 3 insertions(+), 4 deletions(-)
+
+--- a/drivers/mtd/mtdcore.c
++++ b/drivers/mtd/mtdcore.c
+@@ -953,8 +953,8 @@ static int mtd_otp_nvmem_add(struct mtd_
+                       nvmem = mtd_otp_nvmem_register(mtd, "user-otp", size,
+                                                      mtd_nvmem_user_otp_reg_read);
+                       if (IS_ERR(nvmem)) {
+-                              dev_err(dev, "Failed to register OTP NVMEM device\n");
+-                              return PTR_ERR(nvmem);
++                              err = PTR_ERR(nvmem);
++                              goto err;
+                       }
+                       mtd->otp_user_nvmem = nvmem;
+               }
+@@ -971,7 +971,6 @@ static int mtd_otp_nvmem_add(struct mtd_
+                       nvmem = mtd_otp_nvmem_register(mtd, "factory-otp", size,
+                                                      mtd_nvmem_fact_otp_reg_read);
+                       if (IS_ERR(nvmem)) {
+-                              dev_err(dev, "Failed to register OTP NVMEM device\n");
+                               err = PTR_ERR(nvmem);
+                               goto err;
+                       }
+@@ -983,7 +982,7 @@ static int mtd_otp_nvmem_add(struct mtd_
+ err:
+       nvmem_unregister(mtd->otp_user_nvmem);
+-      return err;
++      return dev_err_probe(dev, err, "Failed to register OTP NVMEM device\n");
+ }
+ /**
index 765eecd9d713fff92c87708420ea1a3a394609a9..2601281bf7b7e1d123c265ec6bb4ffcafb261e65 100644 (file)
@@ -8,7 +8,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
 
 --- a/drivers/mtd/ubi/build.c
 +++ b/drivers/mtd/ubi/build.c
-@@ -1212,6 +1212,73 @@ static struct mtd_info * __init open_mtd
+@@ -1213,6 +1213,73 @@ static struct mtd_info * __init open_mtd
        return mtd;
  }
  
@@ -82,7 +82,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
  static int __init ubi_init(void)
  {
        int err, i, k;
-@@ -1296,6 +1363,12 @@ static int __init ubi_init(void)
+@@ -1297,6 +1364,12 @@ static int __init ubi_init(void)
                }
        }