The series was merged for Linux v6.9, so move it to backports.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
-From ffbbe7d66872ff8957dad2136133e28a1fd5d437 Mon Sep 17 00:00:00 2001
+From 25d88bfd35bac3196eafa666e3b05033b46ffa21 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
-Date: Mon, 7 Aug 2023 22:51:05 +0100
-Subject: [PATCH 01/15] dt-bindings: mtd: add basic bindings for UBI
+Date: Tue, 19 Dec 2023 02:32:00 +0000
+Subject: [PATCH 1/8] dt-bindings: mtd: add basic bindings for UBI
Add basic bindings for UBI devices and volumes.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+Reviewed-by: Rob Herring <robh@kernel.org>
+Signed-off-by: Richard Weinberger <richard@nod.at>
---
.../bindings/mtd/partitions/linux,ubi.yaml | 65 +++++++++++++++++++
.../bindings/mtd/partitions/ubi-volume.yaml | 35 ++++++++++
+
+properties:
+ volid:
-+ $ref: "/schemas/types.yaml#/definitions/uint32"
++ $ref: /schemas/types.yaml#/definitions/uint32
+ description:
+ Match UBI volume ID
+
+ volname:
-+ $ref: "/schemas/types.yaml#/definitions/string"
++ $ref: /schemas/types.yaml#/definitions/string
+ description:
+ Match UBI volume ID
+
+anyOf:
+ - required:
-+ - volid
++ - volid
+
+ - required:
-+ - volname
++ - volname
+
+# This is a generic file other binding inherit from and extend
+additionalProperties: true
-From e4dad3aa5c3ab9c553555dd23c0b85f725f2eb51 Mon Sep 17 00:00:00 2001
+From 95b113222b5164ac0887eb5c514ff3970a0136f0 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
-Date: Mon, 7 Aug 2023 22:53:01 +0100
-Subject: [PATCH 02/15] dt-bindings: mtd: ubi-volume: allow UBI volumes to
+Date: Tue, 19 Dec 2023 02:32:11 +0000
+Subject: [PATCH 2/8] dt-bindings: mtd: ubi-volume: allow UBI volumes to
provide NVMEM
UBI volumes may be used to contain NVMEM bits, typically device MAC
addresses or wireless radio calibration data.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+Reviewed-by: Rob Herring <robh@kernel.org>
+Signed-off-by: Richard Weinberger <richard@nod.at>
---
.../devicetree/bindings/mtd/partitions/linux,ubi.yaml | 10 ++++++++++
.../devicetree/bindings/mtd/partitions/ubi-volume.yaml | 5 +++++
+
anyOf:
- required:
- - volid
+ - volid
-From e5cf19bd8204925f3bd2067df9e867313eac388b Mon Sep 17 00:00:00 2001
+From 2bba1cdcfcd2907d0696cc0139f1bd078d36ee81 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
-Date: Mon, 1 May 2023 11:57:51 +0100
-Subject: [PATCH 03/15] mtd: ubi: block: use notifier to create ubiblock from
+Date: Tue, 19 Dec 2023 02:32:35 +0000
+Subject: [PATCH 3/8] mtd: ubi: block: use notifier to create ubiblock from
parameter
Use UBI_VOLUME_ADDED notification to create ubiblock device specified
Suggested-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+Signed-off-by: Richard Weinberger <richard@nod.at>
---
- drivers/mtd/ubi/block.c | 154 ++++++++++++++++++++++------------------
- 1 file changed, 85 insertions(+), 69 deletions(-)
+ drivers/mtd/ubi/block.c | 136 ++++++++++++++++++++--------------------
+ drivers/mtd/ubi/kapi.c | 54 +++++++++++-----
+ drivers/mtd/ubi/ubi.h | 1 +
+ 3 files changed, 106 insertions(+), 85 deletions(-)
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
-@@ -33,6 +33,7 @@
- #include <linux/kernel.h>
- #include <linux/list.h>
- #include <linux/mutex.h>
-+#include <linux/namei.h>
- #include <linux/slab.h>
- #include <linux/mtd/ubi.h>
- #include <linux/blkdev.h>
-@@ -65,10 +66,10 @@ struct ubiblock_pdu {
+@@ -65,10 +65,10 @@ struct ubiblock_pdu {
};
/* Numbers of elements set in the @ubiblock_param array */
struct ubiblock {
struct ubi_volume_desc *desc;
-@@ -469,7 +470,7 @@ int ubiblock_remove(struct ubi_volume_in
- }
-
- /* Found a device, let's lock it so we can check if it's busy */
-- mutex_lock(&dev->dev_mutex);
-+ mutex_lock_nested(&dev->dev_mutex, SINGLE_DEPTH_NESTING);
- if (dev->refcnt > 0) {
- ret = -EBUSY;
- goto out_unlock_dev;
-@@ -532,6 +533,85 @@ static int ubiblock_resize(struct ubi_vo
+@@ -532,6 +532,70 @@ static int ubiblock_resize(struct ubi_vo
return 0;
}
+static bool
+match_volume_desc(struct ubi_volume_info *vi, const char *name, int ubi_num, int vol_id)
+{
-+ int err, len;
-+ struct path path;
-+ struct kstat stat;
++ int err, len, cur_ubi_num, cur_vol_id;
+
+ if (ubi_num == -1) {
+ /* No ubi num, name must be a vol device path */
-+ err = kern_path(name, LOOKUP_FOLLOW, &path);
-+ if (err)
-+ return false;
-+
-+ err = vfs_getattr(&path, &stat, STATX_TYPE, AT_STATX_SYNC_AS_STAT);
-+ path_put(&path);
-+ if (err)
-+ return false;
-+
-+ if (!S_ISCHR(stat.mode))
-+ return false;
-+
-+ if (vi->ubi_num != ubi_major2num(MAJOR(stat.rdev)))
-+ return false;
-+
-+ if (vi->vol_id != MINOR(stat.rdev) - 1)
++ err = ubi_get_num_by_path(name, &cur_ubi_num, &cur_vol_id);
++ if (err || vi->ubi_num != cur_ubi_num || vi->vol_id != cur_vol_id)
+ return false;
+
+ return true;
+ }
+
+ if (vol_id == -1) {
++ /* Got ubi_num, but no vol_id, name must be volume name */
+ if (vi->ubi_num != ubi_num)
+ return false;
+
static int ubiblock_notify(struct notifier_block *nb,
unsigned long notification_type, void *ns_ptr)
{
-@@ -539,10 +619,7 @@ static int ubiblock_notify(struct notifi
+@@ -539,10 +603,7 @@ static int ubiblock_notify(struct notifi
switch (notification_type) {
case UBI_VOLUME_ADDED:
break;
case UBI_VOLUME_REMOVED:
ubiblock_remove(&nt->vi);
-@@ -568,56 +645,6 @@ static struct notifier_block ubiblock_no
+@@ -568,56 +629,6 @@ static struct notifier_block ubiblock_no
.notifier_call = ubiblock_notify,
};
static void ubiblock_remove_all(void)
{
struct ubiblock *next;
-@@ -643,18 +670,7 @@ int __init ubiblock_init(void)
+@@ -643,18 +654,7 @@ int __init ubiblock_init(void)
if (ubiblock_major < 0)
return ubiblock_major;
if (ret)
goto err_unreg;
return 0;
+--- a/drivers/mtd/ubi/kapi.c
++++ b/drivers/mtd/ubi/kapi.c
+@@ -280,6 +280,41 @@ struct ubi_volume_desc *ubi_open_volume_
+ EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
+
+ /**
++ * ubi_get_num_by_path - get UBI device and volume number from device path
++ * @pathname: volume character device node path
++ * @ubi_num: pointer to UBI device number to be set
++ * @vol_id: pointer to UBI volume ID to be set
++ *
++ * Returns 0 on success and sets ubi_num and vol_id, returns error otherwise.
++ */
++int ubi_get_num_by_path(const char *pathname, int *ubi_num, int *vol_id)
++{
++ int error;
++ struct path path;
++ struct kstat stat;
++
++ error = kern_path(pathname, LOOKUP_FOLLOW, &path);
++ if (error)
++ return error;
++
++ error = vfs_getattr(&path, &stat, STATX_TYPE, AT_STATX_SYNC_AS_STAT);
++ path_put(&path);
++ if (error)
++ return error;
++
++ if (!S_ISCHR(stat.mode))
++ return -EINVAL;
++
++ *ubi_num = ubi_major2num(MAJOR(stat.rdev));
++ *vol_id = MINOR(stat.rdev) - 1;
++
++ if (*vol_id < 0 || *ubi_num < 0)
++ return -ENODEV;
++
++ return 0;
++}
++
++/**
+ * ubi_open_volume_path - open UBI volume by its character device node path.
+ * @pathname: volume character device node path
+ * @mode: open mode
+@@ -290,32 +325,17 @@ EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
+ struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
+ {
+ int error, ubi_num, vol_id;
+- struct path path;
+- struct kstat stat;
+
+ dbg_gen("open volume %s, mode %d", pathname, mode);
+
+ if (!pathname || !*pathname)
+ return ERR_PTR(-EINVAL);
+
+- error = kern_path(pathname, LOOKUP_FOLLOW, &path);
+- if (error)
+- return ERR_PTR(error);
+-
+- error = vfs_getattr(&path, &stat, STATX_TYPE, AT_STATX_SYNC_AS_STAT);
+- path_put(&path);
++ error = ubi_get_num_by_path(pathname, &ubi_num, &vol_id);
+ if (error)
+ return ERR_PTR(error);
+
+- if (!S_ISCHR(stat.mode))
+- return ERR_PTR(-EINVAL);
+-
+- ubi_num = ubi_major2num(MAJOR(stat.rdev));
+- vol_id = MINOR(stat.rdev) - 1;
+-
+- if (vol_id >= 0 && ubi_num >= 0)
+- return ubi_open_volume(ubi_num, vol_id, mode);
+- return ERR_PTR(-ENODEV);
++ return ubi_open_volume(ubi_num, vol_id, mode);
+ }
+ EXPORT_SYMBOL_GPL(ubi_open_volume_path);
+
+--- a/drivers/mtd/ubi/ubi.h
++++ b/drivers/mtd/ubi/ubi.h
+@@ -956,6 +956,7 @@ void ubi_free_internal_volumes(struct ub
+ void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di);
+ void ubi_do_get_volume_info(struct ubi_device *ubi, struct ubi_volume *vol,
+ struct ubi_volume_info *vi);
++int ubi_get_num_by_path(const char *pathname, int *ubi_num, int *vol_id);
+ /* scan.c */
+ int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
+ int pnum, const struct ubi_vid_hdr *vid_hdr);
-From 471a17d8d1b838092d1a76e48cdce8b5b67ff809 Mon Sep 17 00:00:00 2001
+From 6e331888643887ce85657527bc03f97d46235e71 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
-Date: Mon, 27 Nov 2023 01:54:28 +0000
-Subject: [PATCH 04/15] mtd: ubi: attach from device tree
+Date: Tue, 19 Dec 2023 02:33:14 +0000
+Subject: [PATCH 4/8] mtd: ubi: attach from device tree
Introduce device tree compatible 'linux,ubi' and attach compatible MTD
devices using the MTD add notifier. This is needed for a UBI device to
volumes on them can be used eg. as NVMEM providers for other drivers.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+Signed-off-by: Richard Weinberger <richard@nod.at>
---
- drivers/mtd/ubi/build.c | 146 ++++++++++++++++++++++++++++------------
- drivers/mtd/ubi/cdev.c | 2 +-
- drivers/mtd/ubi/ubi.h | 2 +-
- 3 files changed, 106 insertions(+), 44 deletions(-)
+ drivers/mtd/ubi/build.c | 135 ++++++++++++++++++++++++++++------------
+ 1 file changed, 96 insertions(+), 39 deletions(-)
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
#include <linux/slab.h>
#include <linux/major.h>
#include "ubi.h"
-@@ -1072,6 +1073,7 @@ out_free:
- * ubi_detach_mtd_dev - detach an MTD device.
- * @ubi_num: UBI device number to detach from
- * @anyway: detach MTD even if device reference count is not zero
-+ * @have_lock: called by MTD notifier holding mtd_table_mutex
- *
- * This function destroys an UBI device number @ubi_num and detaches the
- * underlying MTD device. Returns zero in case of success and %-EBUSY if the
-@@ -1081,7 +1083,7 @@ out_free:
- * Note, the invocations of this function has to be serialized by the
- * @ubi_devices_mutex.
- */
--int ubi_detach_mtd_dev(int ubi_num, int anyway)
-+int ubi_detach_mtd_dev(int ubi_num, int anyway, bool have_lock)
- {
- struct ubi_device *ubi;
-
-@@ -1137,7 +1139,11 @@ int ubi_detach_mtd_dev(int ubi_num, int
- vfree(ubi->peb_buf);
- vfree(ubi->fm_buf);
- ubi_msg(ubi, "mtd%d is detached", ubi->mtd->index);
-- put_mtd_device(ubi->mtd);
-+ if (have_lock)
-+ __put_mtd_device(ubi->mtd);
-+ else
-+ put_mtd_device(ubi->mtd);
-+
- put_device(&ubi->dev);
- return 0;
- }
-@@ -1214,43 +1220,43 @@ static struct mtd_info * __init open_mtd
+@@ -1214,43 +1215,43 @@ static struct mtd_info * __init open_mtd
return mtd;
}
- }
+static void ubi_notify_remove(struct mtd_info *mtd)
+{
-+ WARN(1, "mtd%d removed despite UBI still being attached", mtd->index);
++ /* do nothing for now */
+}
- err = ubi_debugfs_init();
/* Attach MTD devices */
for (i = 0; i < mtd_devs; i++) {
-@@ -1298,25 +1304,79 @@ static int __init ubi_init(void)
+@@ -1298,25 +1299,79 @@ static int __init ubi_init(void)
}
}
+ for (k = 0; k < i; k++)
+ if (ubi_devices[k]) {
+ mutex_lock(&ubi_devices_mutex);
-+ ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1, false);
++ ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1);
+ mutex_unlock(&ubi_devices_mutex);
+ }
+ return err;
out_slab:
kmem_cache_destroy(ubi_wl_entry_slab);
out_dev_unreg:
-@@ -1326,18 +1386,20 @@ out:
+@@ -1326,13 +1381,15 @@ out:
pr_err("UBI error: cannot initialize UBI, error %d\n", err);
return err;
}
for (i = 0; i < UBI_MAX_DEVICES; i++)
if (ubi_devices[i]) {
- mutex_lock(&ubi_devices_mutex);
-- ubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1);
-+ ubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1, false);
- mutex_unlock(&ubi_devices_mutex);
- }
- ubi_debugfs_exit();
---- a/drivers/mtd/ubi/cdev.c
-+++ b/drivers/mtd/ubi/cdev.c
-@@ -1065,7 +1065,7 @@ static long ctrl_cdev_ioctl(struct file
- }
-
- mutex_lock(&ubi_devices_mutex);
-- err = ubi_detach_mtd_dev(ubi_num, 0);
-+ err = ubi_detach_mtd_dev(ubi_num, 0, false);
- mutex_unlock(&ubi_devices_mutex);
- break;
- }
---- a/drivers/mtd/ubi/ubi.h
-+++ b/drivers/mtd/ubi/ubi.h
-@@ -939,7 +939,7 @@ int ubi_io_write_vid_hdr(struct ubi_devi
- int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
- int vid_hdr_offset, int max_beb_per1024,
- bool disable_fm);
--int ubi_detach_mtd_dev(int ubi_num, int anyway);
-+int ubi_detach_mtd_dev(int ubi_num, int anyway, bool have_lock);
- struct ubi_device *ubi_get_device(int ubi_num);
- void ubi_put_device(struct ubi_device *ubi);
- struct ubi_device *ubi_get_by_major(int major);
-From 2d664266cfdd114cc7a1fa28dd64275e99222455 Mon Sep 17 00:00:00 2001
+From 924731fbed3247e3b82b8ab17db587ee28c2e781 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
-Date: Thu, 8 Jun 2023 17:18:09 +0100
-Subject: [PATCH 05/15] mtd: ubi: introduce pre-removal notification for UBI
+Date: Tue, 19 Dec 2023 02:33:24 +0000
+Subject: [PATCH 5/8] mtd: ubi: introduce pre-removal notification for UBI
volumes
Introduce a new notification type UBI_VOLUME_SHUTDOWN to inform users
NVMEM which otherwise WARNs on volume removal).
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+Signed-off-by: Richard Weinberger <richard@nod.at>
---
- drivers/mtd/ubi/block.c | 26 ++++++++++++++++++++++++++
- drivers/mtd/ubi/build.c | 20 +++++++++++++++-----
+ drivers/mtd/ubi/build.c | 19 ++++++++++++++-----
drivers/mtd/ubi/kapi.c | 2 +-
drivers/mtd/ubi/ubi.h | 2 ++
drivers/mtd/ubi/vmt.c | 17 +++++++++++++++--
include/linux/mtd/ubi.h | 2 ++
- 6 files changed, 61 insertions(+), 8 deletions(-)
+ 5 files changed, 34 insertions(+), 8 deletions(-)
---- a/drivers/mtd/ubi/block.c
-+++ b/drivers/mtd/ubi/block.c
-@@ -533,6 +533,29 @@ static int ubiblock_resize(struct ubi_vo
- return 0;
- }
-
-+static int ubiblock_shutdown(struct ubi_volume_info *vi)
-+{
-+ struct ubiblock *dev;
-+ struct gendisk *disk;
-+ int ret = 0;
-+
-+ mutex_lock(&devices_mutex);
-+ dev = find_dev_nolock(vi->ubi_num, vi->vol_id);
-+ if (!dev) {
-+ ret = -ENODEV;
-+ goto out_unlock;
-+ }
-+ disk = dev->gd;
-+
-+out_unlock:
-+ mutex_unlock(&devices_mutex);
-+
-+ if (!ret)
-+ blk_mark_disk_dead(disk);
-+
-+ return ret;
-+};
-+
- static bool
- match_volume_desc(struct ubi_volume_info *vi, const char *name, int ubi_num, int vol_id)
- {
-@@ -624,6 +647,9 @@ static int ubiblock_notify(struct notifi
- case UBI_VOLUME_REMOVED:
- ubiblock_remove(&nt->vi);
- break;
-+ case UBI_VOLUME_SHUTDOWN:
-+ ubiblock_shutdown(&nt->vi);
-+ break;
- case UBI_VOLUME_RESIZED:
- ubiblock_resize(&nt->vi);
- break;
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -91,7 +91,7 @@ static struct ubi_device *ubi_devices[UB
continue;
ubi_eba_replace_table(ubi->volumes[i], NULL);
ubi_fastmap_destroy_checkmap(ubi->volumes[i]);
-@@ -1095,10 +1098,10 @@ int ubi_detach_mtd_dev(int ubi_num, int
+@@ -1094,7 +1097,6 @@ int ubi_detach_mtd_dev(int ubi_num, int
return -EINVAL;
spin_lock(&ubi_devices_lock);
ubi->ref_count -= 1;
if (ubi->ref_count) {
if (!anyway) {
-+ ubi->ref_count += 1;
- spin_unlock(&ubi_devices_lock);
- return -EBUSY;
- }
-@@ -1106,6 +1109,13 @@ int ubi_detach_mtd_dev(int ubi_num, int
+@@ -1105,6 +1107,13 @@ int ubi_detach_mtd_dev(int ubi_num, int
ubi_err(ubi, "%s reference count %d, destroy anyway",
ubi->ubi_name, ubi->ref_count);
}
-From 3a041ee543cdf2e707a1dd72946cd6a583509b28 Mon Sep 17 00:00:00 2001
+From 1c54542170819e36baa43c17ca55bb3d7da89a53 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
-Date: Fri, 21 Jul 2023 19:26:37 +0100
-Subject: [PATCH 06/15] mtd: ubi: populate ubi volume fwnode
+Date: Tue, 19 Dec 2023 02:33:38 +0000
+Subject: [PATCH 6/8] mtd: ubi: populate ubi volume fwnode
Look for the 'volumes' subnode of an MTD partition attached to a UBI
device and attach matching child nodes to UBI volumes.
as NVMEM providers.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+Signed-off-by: Richard Weinberger <richard@nod.at>
---
drivers/mtd/ubi/vmt.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
-From 7eb6666348f3f2d1f7308c712fa5903cbe189401 Mon Sep 17 00:00:00 2001
+From 15fc7dc926c91c871f6c0305b2938dbdeb14203b Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
-Date: Thu, 8 Jun 2023 17:22:04 +0100
-Subject: [PATCH 07/15] mtd: ubi: provide NVMEM layer over UBI volumes
+Date: Tue, 19 Dec 2023 02:33:48 +0000
+Subject: [PATCH 7/8] mtd: ubi: provide NVMEM layer over UBI volumes
In an ideal world we would like UBI to be used where ever possible on a
NAND chip. And with UBI support in ARM Trusted Firmware and U-Boot it
access due to limitations of the NVMEM provider API.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+Signed-off-by: Richard Weinberger <richard@nod.at>
---
drivers/mtd/ubi/Kconfig | 12 +++
drivers/mtd/ubi/Makefile | 1 +
+obj-$(CONFIG_MTD_UBI_NVMEM) += nvmem.o
--- /dev/null
+++ b/drivers/mtd/ubi/nvmem.c
-@@ -0,0 +1,191 @@
+@@ -0,0 +1,188 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 Daniel Golle <daniel@makrotopia.org>
+static int ubi_nvmem_reg_read(void *priv, unsigned int from,
+ void *val, size_t bytes)
+{
-+ uint32_t offs, to_read, bytes_left;
++ int err = 0, lnum = from, offs, bytes_left = bytes, to_read;
+ struct ubi_nvmem *unv = priv;
+ struct ubi_volume_desc *desc;
-+ uint64_t lnum = from;
-+ int err = 0;
+
+ desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY);
+ if (IS_ERR(desc))
+ return PTR_ERR(desc);
+
-+ bytes_left = bytes;
+ offs = do_div(lnum, unv->usable_leb_size);
+ while (bytes_left) {
+ to_read = unv->usable_leb_size - offs;
--- /dev/null
+From 04231c61dcd51db0f12061e49bb761b197109f2f Mon Sep 17 00:00:00 2001
+From: Daniel Golle <daniel@makrotopia.org>
+Date: Thu, 29 Feb 2024 03:47:24 +0000
+Subject: [PATCH 8/8] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems
+
+A compiler warning related to sizeof(int) != 8 when calling do_div()
+is triggered when building on 32-bit platforms.
+Address this by using integer types having a well-defined size.
+
+Fixes: 3ce485803da1 ("mtd: ubi: provide NVMEM layer over UBI volumes")
+Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
+Tested-by: Randy Dunlap <rdunlap@infradead.org>
+Signed-off-by: Richard Weinberger <richard@nod.at>
+---
+ drivers/mtd/ubi/nvmem.c | 5 ++++-
+ 1 file changed, 4 insertions(+), 1 deletion(-)
+
+--- a/drivers/mtd/ubi/nvmem.c
++++ b/drivers/mtd/ubi/nvmem.c
+@@ -23,9 +23,12 @@ struct ubi_nvmem {
+ static int ubi_nvmem_reg_read(void *priv, unsigned int from,
+ void *val, size_t bytes)
+ {
+- int err = 0, lnum = from, offs, bytes_left = bytes, to_read;
++ size_t to_read, bytes_left = bytes;
+ struct ubi_nvmem *unv = priv;
+ struct ubi_volume_desc *desc;
++ uint32_t offs;
++ uint64_t lnum = from;
++ int err = 0;
+
+ desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY);
+ if (IS_ERR(desc))
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
-@@ -1264,6 +1264,74 @@ static struct mtd_notifier ubi_mtd_notif
+@@ -1258,6 +1258,74 @@ static struct mtd_notifier ubi_mtd_notif
.remove = ubi_notify_remove,
};
static int __init ubi_init_attach(void)
{
int err, i, k;
-@@ -1314,6 +1382,12 @@ static int __init ubi_init_attach(void)
+@@ -1308,6 +1376,12 @@ static int __init ubi_init_attach(void)
}
}
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
-@@ -609,10 +609,47 @@ match_volume_desc(struct ubi_volume_info
+@@ -570,10 +570,47 @@ match_volume_desc(struct ubi_volume_info
return true;
}
struct ubiblock_param *p;
/*
-@@ -625,6 +662,7 @@ ubiblock_create_from_param(struct ubi_vo
+@@ -586,6 +623,7 @@ ubiblock_create_from_param(struct ubi_vo
if (!match_volume_desc(vi, p->name, p->ubi_num, p->vol_id))
continue;
ret = ubiblock_create(vi);
if (ret) {
pr_err(
-@@ -633,6 +671,10 @@ ubiblock_create_from_param(struct ubi_vo
+@@ -594,6 +632,10 @@ ubiblock_create_from_param(struct ubi_vo
}
break;
}
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
-@@ -42,6 +42,7 @@
+@@ -41,6 +41,7 @@
#include <linux/scatterlist.h>
#include <linux/idr.h>
#include <asm/div64.h>
#include "ubi-media.h"
#include "ubi.h"
-@@ -429,6 +430,15 @@ int ubiblock_create(struct ubi_volume_in
+@@ -428,6 +429,15 @@ int ubiblock_create(struct ubi_volume_in
dev_info(disk_to_dev(dev->gd), "created from ubi%d:%d(%s)",
dev->ubi_num, dev->vol_id, vi->name);
mutex_unlock(&devices_mutex);
set_capacity(gd, ((u64)new->size * tr->blksize) >> 9);
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
-@@ -411,7 +411,9 @@ int ubiblock_create(struct ubi_volume_in
+@@ -410,7 +410,9 @@ int ubiblock_create(struct ubi_volume_in
ret = -ENODEV;
goto out_cleanup_disk;
}