kernel: backport nvmem changes from v6.11
authorRafał Miłecki <rafal@milecki.pl>
Tue, 10 Sep 2024 11:43:03 +0000 (13:43 +0200)
committerRafał Miłecki <rafal@milecki.pl>
Tue, 10 Sep 2024 11:43:03 +0000 (13:43 +0200)
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
41 files changed:
target/linux/generic/backport-5.15/838-v6.11-0001-nvmem-add-missing-MODULE_DESCRIPTION-macros.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/838-v6.11-0002-nvmem-meson-efuse-Replacing-the-use-of-of_node_put-t.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/838-v6.11-0003-nvmem-rockchip-otp-set-add_legacy_fixed_of_cells-con.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/838-v6.11-0004-nvmem-rockchip-otp-Set-type-to-OTP.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/838-v6.11-0005-nvmem-rockchip-efuse-set-type-to-OTP.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/838-v6.11-0006-nvmem-core-add-single-sysfs-group.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/838-v6.11-0007-nvmem-core-remove-global-nvmem_cells_group.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/838-v6.11-0008-nvmem-core-drop-unnecessary-range-checks-in-sysfs-ca.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/838-v6.11-0009-nvmem-Use-sysfs_emit-for-type-attribute.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/838-v6.11-0010-nvmem-core-Implement-force_ro-sysfs-attribute.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/838-v6.11-0011-nvmem-u-boot-env-error-if-NVMEM-device-is-too-small.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/838-v6.11-0012-nvmem-Fix-return-type-of-devm_nvmem_device_get-in-ke.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/840-v6.11-0001-nvmem-add-missing-MODULE_DESCRIPTION-macros.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/840-v6.11-0002-nvmem-meson-efuse-Replacing-the-use-of-of_node_put-t.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/840-v6.11-0003-nvmem-rockchip-otp-set-add_legacy_fixed_of_cells-con.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/840-v6.11-0004-nvmem-rockchip-otp-Set-type-to-OTP.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/840-v6.11-0005-nvmem-rockchip-efuse-set-type-to-OTP.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/840-v6.11-0006-nvmem-core-add-single-sysfs-group.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/840-v6.11-0007-nvmem-core-remove-global-nvmem_cells_group.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/840-v6.11-0008-nvmem-core-drop-unnecessary-range-checks-in-sysfs-ca.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/840-v6.11-0009-nvmem-Use-sysfs_emit-for-type-attribute.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/840-v6.11-0010-nvmem-core-Implement-force_ro-sysfs-attribute.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/840-v6.11-0011-nvmem-u-boot-env-error-if-NVMEM-device-is-too-small.patch [new file with mode: 0644]
target/linux/generic/backport-6.1/840-v6.11-0012-nvmem-Fix-return-type-of-devm_nvmem_device_get-in-ke.patch [new file with mode: 0644]
target/linux/generic/backport-6.6/822-v6.11-0001-nvmem-add-missing-MODULE_DESCRIPTION-macros.patch [new file with mode: 0644]
target/linux/generic/backport-6.6/822-v6.11-0002-nvmem-meson-efuse-Replacing-the-use-of-of_node_put-t.patch [new file with mode: 0644]
target/linux/generic/backport-6.6/822-v6.11-0004-nvmem-rockchip-otp-Set-type-to-OTP.patch [new file with mode: 0644]
target/linux/generic/backport-6.6/822-v6.11-0005-nvmem-rockchip-efuse-set-type-to-OTP.patch [new file with mode: 0644]
target/linux/generic/backport-6.6/822-v6.11-0006-nvmem-core-add-single-sysfs-group.patch [new file with mode: 0644]
target/linux/generic/backport-6.6/822-v6.11-0007-nvmem-core-remove-global-nvmem_cells_group.patch [new file with mode: 0644]
target/linux/generic/backport-6.6/822-v6.11-0008-nvmem-core-drop-unnecessary-range-checks-in-sysfs-ca.patch [new file with mode: 0644]
target/linux/generic/backport-6.6/822-v6.11-0009-nvmem-Use-sysfs_emit-for-type-attribute.patch [new file with mode: 0644]
target/linux/generic/backport-6.6/822-v6.11-0010-nvmem-core-Implement-force_ro-sysfs-attribute.patch [new file with mode: 0644]
target/linux/generic/backport-6.6/822-v6.11-0011-nvmem-u-boot-env-error-if-NVMEM-device-is-too-small.patch [new file with mode: 0644]
target/linux/generic/backport-6.6/822-v6.11-0012-nvmem-Fix-return-type-of-devm_nvmem_device_get-in-ke.patch [new file with mode: 0644]
target/linux/generic/pending-5.15/802-nvmem-u-boot-env-align-endianness-of-crc32-values.patch
target/linux/generic/pending-5.15/804-nvmem-core-support-mac-base-fixed-layout-cells.patch
target/linux/generic/pending-6.1/802-nvmem-u-boot-env-align-endianness-of-crc32-values.patch
target/linux/generic/pending-6.1/804-nvmem-core-support-mac-base-fixed-layout-cells.patch
target/linux/generic/pending-6.6/802-nvmem-u-boot-env-align-endianness-of-crc32-values.patch
target/linux/generic/pending-6.6/804-nvmem-core-support-mac-base-fixed-layout-cells.patch

diff --git a/target/linux/generic/backport-5.15/838-v6.11-0001-nvmem-add-missing-MODULE_DESCRIPTION-macros.patch b/target/linux/generic/backport-5.15/838-v6.11-0001-nvmem-add-missing-MODULE_DESCRIPTION-macros.patch
new file mode 100644 (file)
index 0000000..a8ce832
--- /dev/null
@@ -0,0 +1,48 @@
+From c553bad4c5fc5ae44bd2fcaa73e1d6bedfb1c35c Mon Sep 17 00:00:00 2001
+From: Jeff Johnson <quic_jjohnson@quicinc.com>
+Date: Fri, 5 Jul 2024 08:48:38 +0100
+Subject: [PATCH] nvmem: add missing MODULE_DESCRIPTION() macros
+
+make allmodconfig && make W=1 C=1 reports:
+WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvmem/nvmem-apple-efuses.o
+WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvmem/nvmem_brcm_nvram.o
+WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvmem/nvmem_u-boot-env.o
+
+Add the missing invocations of the MODULE_DESCRIPTION() macro.
+
+Signed-off-by: Jeff Johnson <quic_jjohnson@quicinc.com>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-2-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/apple-efuses.c | 1 +
+ drivers/nvmem/brcm_nvram.c   | 1 +
+ drivers/nvmem/u-boot-env.c   | 1 +
+ 3 files changed, 3 insertions(+)
+
+--- a/drivers/nvmem/apple-efuses.c
++++ b/drivers/nvmem/apple-efuses.c
+@@ -78,4 +78,5 @@ static struct platform_driver apple_efus
+ module_platform_driver(apple_efuses_driver);
+ MODULE_AUTHOR("Sven Peter <sven@svenpeter.dev>");
++MODULE_DESCRIPTION("Apple SoC eFuse driver");
+ MODULE_LICENSE("GPL");
+--- a/drivers/nvmem/brcm_nvram.c
++++ b/drivers/nvmem/brcm_nvram.c
+@@ -253,5 +253,6 @@ static int __init brcm_nvram_init(void)
+ subsys_initcall_sync(brcm_nvram_init);
+ MODULE_AUTHOR("Rafał Miłecki");
++MODULE_DESCRIPTION("Broadcom I/O-mapped NVRAM support driver");
+ MODULE_LICENSE("GPL");
+ MODULE_DEVICE_TABLE(of, brcm_nvram_of_match_table);
+--- a/drivers/nvmem/u-boot-env.c
++++ b/drivers/nvmem/u-boot-env.c
+@@ -249,5 +249,6 @@ static struct platform_driver u_boot_env
+ module_platform_driver(u_boot_env_driver);
+ MODULE_AUTHOR("Rafał Miłecki");
++MODULE_DESCRIPTION("U-Boot environment variables support module");
+ MODULE_LICENSE("GPL");
+ MODULE_DEVICE_TABLE(of, u_boot_env_of_match_table);
diff --git a/target/linux/generic/backport-5.15/838-v6.11-0002-nvmem-meson-efuse-Replacing-the-use-of-of_node_put-t.patch b/target/linux/generic/backport-5.15/838-v6.11-0002-nvmem-meson-efuse-Replacing-the-use-of-of_node_put-t.patch
new file mode 100644 (file)
index 0000000..05c82db
--- /dev/null
@@ -0,0 +1,48 @@
+From 5fecb932607d83d37a703c731268e9d9051457f5 Mon Sep 17 00:00:00 2001
+From: MarileneGarcia <marilene.agarcia@gmail.com>
+Date: Fri, 5 Jul 2024 08:48:40 +0100
+Subject: [PATCH] nvmem: meson-efuse: Replacing the use of of_node_put to
+ __free
+
+Use __free for device_node values, and thus drop calls to
+of_node_put.
+
+The goal is to reduce memory management issues by using this
+scope-based of_node_put() cleanup to simplify function exit
+handling. When using __free a resource is allocated within a
+block, it is automatically freed at the end of the block.
+
+Suggested-by: Julia Lawall <julia.lawall@inria.fr>
+Signed-off-by: MarileneGarcia <marilene.agarcia@gmail.com>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-4-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/meson-efuse.c | 5 ++---
+ 1 file changed, 2 insertions(+), 3 deletions(-)
+
+--- a/drivers/nvmem/meson-efuse.c
++++ b/drivers/nvmem/meson-efuse.c
+@@ -48,20 +48,19 @@ static int meson_efuse_probe(struct plat
+ {
+       struct device *dev = &pdev->dev;
+       struct meson_sm_firmware *fw;
+-      struct device_node *sm_np;
+       struct nvmem_device *nvmem;
+       struct nvmem_config *econfig;
+       struct clk *clk;
+       unsigned int size;
++      struct device_node *sm_np __free(device_node) =
++                      of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
+-      sm_np = of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
+       if (!sm_np) {
+               dev_err(&pdev->dev, "no secure-monitor node\n");
+               return -ENODEV;
+       }
+       fw = meson_sm_get(sm_np);
+-      of_node_put(sm_np);
+       if (!fw)
+               return -EPROBE_DEFER;
diff --git a/target/linux/generic/backport-5.15/838-v6.11-0003-nvmem-rockchip-otp-set-add_legacy_fixed_of_cells-con.patch b/target/linux/generic/backport-5.15/838-v6.11-0003-nvmem-rockchip-otp-set-add_legacy_fixed_of_cells-con.patch
new file mode 100644 (file)
index 0000000..a8a30fc
--- /dev/null
@@ -0,0 +1,28 @@
+From 2933e79db3c00a8cdc56f6bb050a857fec1875ad Mon Sep 17 00:00:00 2001
+From: Heiko Stuebner <heiko.stuebner@cherry.de>
+Date: Fri, 5 Jul 2024 08:48:41 +0100
+Subject: [PATCH] nvmem: rockchip-otp: set add_legacy_fixed_of_cells config
+ option
+
+The Rockchip OTP describes its layout via devicetree subnodes,
+so set the appropriate property.
+
+Fixes: 2cc3b37f5b6d ("nvmem: add explicit config option to read old syntax fixed OF cells")
+Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-5-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/rockchip-otp.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/drivers/nvmem/rockchip-otp.c
++++ b/drivers/nvmem/rockchip-otp.c
+@@ -255,6 +255,7 @@ static int rockchip_otp_read(void *conte
+ static struct nvmem_config otp_config = {
+       .name = "rockchip-otp",
+       .owner = THIS_MODULE,
++      .add_legacy_fixed_of_cells = true,
+       .read_only = true,
+       .stride = 1,
+       .word_size = 1,
diff --git a/target/linux/generic/backport-5.15/838-v6.11-0004-nvmem-rockchip-otp-Set-type-to-OTP.patch b/target/linux/generic/backport-5.15/838-v6.11-0004-nvmem-rockchip-otp-Set-type-to-OTP.patch
new file mode 100644 (file)
index 0000000..8491eb3
--- /dev/null
@@ -0,0 +1,25 @@
+From 39f95600d8c53355b212a117e91a6ba15e0cac47 Mon Sep 17 00:00:00 2001
+From: Heiko Stuebner <heiko.stuebner@cherry.de>
+Date: Fri, 5 Jul 2024 08:48:42 +0100
+Subject: [PATCH] nvmem: rockchip-otp: Set type to OTP
+
+The Rockchip OTP is obviously an OTP memory, so document this fact.
+
+Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-6-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/rockchip-otp.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/drivers/nvmem/rockchip-otp.c
++++ b/drivers/nvmem/rockchip-otp.c
+@@ -256,6 +256,7 @@ static struct nvmem_config otp_config =
+       .name = "rockchip-otp",
+       .owner = THIS_MODULE,
+       .add_legacy_fixed_of_cells = true,
++      .type = NVMEM_TYPE_OTP,
+       .read_only = true,
+       .stride = 1,
+       .word_size = 1,
diff --git a/target/linux/generic/backport-5.15/838-v6.11-0005-nvmem-rockchip-efuse-set-type-to-OTP.patch b/target/linux/generic/backport-5.15/838-v6.11-0005-nvmem-rockchip-efuse-set-type-to-OTP.patch
new file mode 100644 (file)
index 0000000..260b03e
--- /dev/null
@@ -0,0 +1,26 @@
+From ba64a04474d2989f397982c48e405cfd785e2dd5 Mon Sep 17 00:00:00 2001
+From: Heiko Stuebner <heiko.stuebner@cherry.de>
+Date: Fri, 5 Jul 2024 08:48:43 +0100
+Subject: [PATCH] nvmem: rockchip-efuse: set type to OTP
+
+This device currently reports an "Unknown" type in sysfs.
+Since it is an eFuse hardware device, set its type to OTP.
+
+Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-7-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/rockchip-efuse.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/drivers/nvmem/rockchip-efuse.c
++++ b/drivers/nvmem/rockchip-efuse.c
+@@ -206,6 +206,7 @@ static int rockchip_rk3399_efuse_read(vo
+ static struct nvmem_config econfig = {
+       .name = "rockchip-efuse",
+       .add_legacy_fixed_of_cells = true,
++      .type = NVMEM_TYPE_OTP,
+       .stride = 1,
+       .word_size = 1,
+       .read_only = true,
diff --git a/target/linux/generic/backport-5.15/838-v6.11-0006-nvmem-core-add-single-sysfs-group.patch b/target/linux/generic/backport-5.15/838-v6.11-0006-nvmem-core-add-single-sysfs-group.patch
new file mode 100644 (file)
index 0000000..4fb2afd
--- /dev/null
@@ -0,0 +1,42 @@
+From 6188f233161c6a5b2d1c396a221dfafc77dc9eec Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <linux@weissschuh.net>
+Date: Fri, 5 Jul 2024 08:48:46 +0100
+Subject: [PATCH] nvmem: core: add single sysfs group
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The sysfs core provides a function to easily register a single group.
+Use it and remove the now unnecessary nvmem_cells_groups array.
+
+Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-10-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 7 +------
+ 1 file changed, 1 insertion(+), 6 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -368,11 +368,6 @@ static const struct attribute_group *nvm
+       NULL,
+ };
+-static const struct attribute_group *nvmem_cells_groups[] = {
+-      &nvmem_cells_group,
+-      NULL,
+-};
+-
+ static struct bin_attribute bin_attr_nvmem_eeprom_compat = {
+       .attr   = {
+               .name   = "eeprom",
+@@ -477,7 +472,7 @@ static int nvmem_populate_sysfs_cells(st
+       nvmem_cells_group.bin_attrs = cells_attrs;
+-      ret = device_add_groups(&nvmem->dev, nvmem_cells_groups);
++      ret = device_add_group(&nvmem->dev, &nvmem_cells_group);
+       if (ret)
+               goto unlock_mutex;
diff --git a/target/linux/generic/backport-5.15/838-v6.11-0007-nvmem-core-remove-global-nvmem_cells_group.patch b/target/linux/generic/backport-5.15/838-v6.11-0007-nvmem-core-remove-global-nvmem_cells_group.patch
new file mode 100644 (file)
index 0000000..ef626d3
--- /dev/null
@@ -0,0 +1,83 @@
+From 6839fed062b7898665983368c88269a6fb1fc10f Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <linux@weissschuh.net>
+Date: Fri, 5 Jul 2024 08:48:47 +0100
+Subject: [PATCH] nvmem: core: remove global nvmem_cells_group
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+nvmem_cells_groups is a global variable that is also mutated.
+This is complicated and error-prone.
+
+Instead use a normal stack variable.
+
+Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-11-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 26 ++++++++++----------------
+ 1 file changed, 10 insertions(+), 16 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -358,11 +358,6 @@ static const struct attribute_group nvme
+       .is_bin_visible = nvmem_bin_attr_is_visible,
+ };
+-/* Cell attributes will be dynamically allocated */
+-static struct attribute_group nvmem_cells_group = {
+-      .name           = "cells",
+-};
+-
+ static const struct attribute_group *nvmem_dev_groups[] = {
+       &nvmem_bin_group,
+       NULL,
+@@ -424,23 +419,24 @@ static void nvmem_sysfs_remove_compat(st
+ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
+ {
+-      struct bin_attribute **cells_attrs, *attrs;
++      struct attribute_group group = {
++              .name   = "cells",
++      };
+       struct nvmem_cell_entry *entry;
++      struct bin_attribute *attrs;
+       unsigned int ncells = 0, i = 0;
+       int ret = 0;
+       mutex_lock(&nvmem_mutex);
+-      if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated) {
+-              nvmem_cells_group.bin_attrs = NULL;
++      if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated)
+               goto unlock_mutex;
+-      }
+       /* Allocate an array of attributes with a sentinel */
+       ncells = list_count_nodes(&nvmem->cells);
+-      cells_attrs = devm_kcalloc(&nvmem->dev, ncells + 1,
+-                                 sizeof(struct bin_attribute *), GFP_KERNEL);
+-      if (!cells_attrs) {
++      group.bin_attrs = devm_kcalloc(&nvmem->dev, ncells + 1,
++                                     sizeof(struct bin_attribute *), GFP_KERNEL);
++      if (!group.bin_attrs) {
+               ret = -ENOMEM;
+               goto unlock_mutex;
+       }
+@@ -466,13 +462,11 @@ static int nvmem_populate_sysfs_cells(st
+                       goto unlock_mutex;
+               }
+-              cells_attrs[i] = &attrs[i];
++              group.bin_attrs[i] = &attrs[i];
+               i++;
+       }
+-      nvmem_cells_group.bin_attrs = cells_attrs;
+-
+-      ret = device_add_group(&nvmem->dev, &nvmem_cells_group);
++      ret = device_add_group(&nvmem->dev, &group);
+       if (ret)
+               goto unlock_mutex;
diff --git a/target/linux/generic/backport-5.15/838-v6.11-0008-nvmem-core-drop-unnecessary-range-checks-in-sysfs-ca.patch b/target/linux/generic/backport-5.15/838-v6.11-0008-nvmem-core-drop-unnecessary-range-checks-in-sysfs-ca.patch
new file mode 100644 (file)
index 0000000..9b6251b
--- /dev/null
@@ -0,0 +1,61 @@
+From 588773802c386d38f9c4e91acd47369e89d95a30 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <linux@weissschuh.net>
+Date: Fri, 5 Jul 2024 08:48:48 +0100
+Subject: [PATCH] nvmem: core: drop unnecessary range checks in sysfs callbacks
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The same checks have already been done in sysfs_kf_bin_write() and
+sysfs_kf_bin_read() just before the callbacks are invoked.
+
+Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-12-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 14 --------------
+ 1 file changed, 14 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -204,19 +204,12 @@ static ssize_t bin_attr_nvmem_read(struc
+               dev = kobj_to_dev(kobj);
+       nvmem = to_nvmem_device(dev);
+-      /* Stop the user from reading */
+-      if (pos >= nvmem->size)
+-              return 0;
+-
+       if (!IS_ALIGNED(pos, nvmem->stride))
+               return -EINVAL;
+       if (count < nvmem->word_size)
+               return -EINVAL;
+-      if (pos + count > nvmem->size)
+-              count = nvmem->size - pos;
+-
+       count = round_down(count, nvmem->word_size);
+       if (!nvmem->reg_read)
+@@ -244,19 +237,12 @@ static ssize_t bin_attr_nvmem_write(stru
+               dev = kobj_to_dev(kobj);
+       nvmem = to_nvmem_device(dev);
+-      /* Stop the user from writing */
+-      if (pos >= nvmem->size)
+-              return -EFBIG;
+-
+       if (!IS_ALIGNED(pos, nvmem->stride))
+               return -EINVAL;
+       if (count < nvmem->word_size)
+               return -EINVAL;
+-      if (pos + count > nvmem->size)
+-              count = nvmem->size - pos;
+-
+       count = round_down(count, nvmem->word_size);
+       if (!nvmem->reg_write)
diff --git a/target/linux/generic/backport-5.15/838-v6.11-0009-nvmem-Use-sysfs_emit-for-type-attribute.patch b/target/linux/generic/backport-5.15/838-v6.11-0009-nvmem-Use-sysfs_emit-for-type-attribute.patch
new file mode 100644 (file)
index 0000000..3da1feb
--- /dev/null
@@ -0,0 +1,30 @@
+From 08c367e45b6d322956878774f0b88bf5e52c6d54 Mon Sep 17 00:00:00 2001
+From: Marek Vasut <marex@denx.de>
+Date: Fri, 5 Jul 2024 08:48:51 +0100
+Subject: [PATCH] nvmem: Use sysfs_emit() for type attribute
+
+Use sysfs_emit() instead of sprintf() to follow best practice per
+Documentation/filesystems/sysfs.rst
+"
+show() should only use sysfs_emit()...
+"
+
+Signed-off-by: Marek Vasut <marex@denx.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-15-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -180,7 +180,7 @@ static ssize_t type_show(struct device *
+ {
+       struct nvmem_device *nvmem = to_nvmem_device(dev);
+-      return sprintf(buf, "%s\n", nvmem_type_str[nvmem->type]);
++      return sysfs_emit(buf, "%s\n", nvmem_type_str[nvmem->type]);
+ }
+ static DEVICE_ATTR_RO(type);
diff --git a/target/linux/generic/backport-5.15/838-v6.11-0010-nvmem-core-Implement-force_ro-sysfs-attribute.patch b/target/linux/generic/backport-5.15/838-v6.11-0010-nvmem-core-Implement-force_ro-sysfs-attribute.patch
new file mode 100644 (file)
index 0000000..ac7dda1
--- /dev/null
@@ -0,0 +1,122 @@
+From 9d7eb234ac7a56b88aea8a52ed81553a730fe25c Mon Sep 17 00:00:00 2001
+From: Marek Vasut <marex@denx.de>
+Date: Fri, 5 Jul 2024 08:48:52 +0100
+Subject: [PATCH] nvmem: core: Implement force_ro sysfs attribute
+
+Implement "force_ro" sysfs attribute to allow users to set read-write
+devices as read-only and back to read-write from userspace. The choice
+of the name is based on MMC core 'force_ro' attribute.
+
+This solves a situation where an AT24 I2C EEPROM with GPIO based nWP
+signal may have to be occasionally updated. Such I2C EEPROM device is
+usually set as read-only during most of the regular system operation,
+but in case it has to be updated in a controlled manner, it could be
+unlocked using this new "force_ro" sysfs attribute and then re-locked
+again.
+
+The "read-only" DT property and config->read_only configuration is
+respected and is used to set default state of the device, read-only
+or read-write, for devices which do implement .reg_write function.
+For devices which do not implement .reg_write function, the device
+is unconditionally read-only and the "force_ro" attribute is not
+visible.
+
+Signed-off-by: Marek Vasut <marex@denx.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-16-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ Documentation/ABI/stable/sysfs-bus-nvmem | 17 ++++++++++
+ drivers/nvmem/core.c                     | 43 ++++++++++++++++++++++++
+ 2 files changed, 60 insertions(+)
+
+--- a/Documentation/ABI/stable/sysfs-bus-nvmem
++++ b/Documentation/ABI/stable/sysfs-bus-nvmem
+@@ -1,3 +1,20 @@
++What:         /sys/bus/nvmem/devices/.../force_ro
++Date:         June 2024
++KernelVersion:        6.11
++Contact:      Marek Vasut <marex@denx.de>
++Description:
++              This read/write attribute allows users to set read-write
++              devices as read-only and back to read-write from userspace.
++              This can be used to unlock and relock write-protection of
++              devices which are generally locked, except during sporadic
++              programming operation.
++              Read returns '0' or '1' for read-write or read-only modes
++              respectively.
++              Write parses one of 'YyTt1NnFf0', or [oO][NnFf] for "on"
++              and "off", i.e. what kstrbool() supports.
++              Note: This file is only present if CONFIG_NVMEM_SYSFS
++              is enabled.
++
+ What:         /sys/bus/nvmem/devices/.../nvmem
+ Date:         July 2015
+ KernelVersion:  4.2
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -185,7 +185,30 @@ static ssize_t type_show(struct device *
+ static DEVICE_ATTR_RO(type);
++static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr,
++                           char *buf)
++{
++      struct nvmem_device *nvmem = to_nvmem_device(dev);
++
++      return sysfs_emit(buf, "%d\n", nvmem->read_only);
++}
++
++static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr,
++                            const char *buf, size_t count)
++{
++      struct nvmem_device *nvmem = to_nvmem_device(dev);
++      int ret = kstrtobool(buf, &nvmem->read_only);
++
++      if (ret < 0)
++              return ret;
++
++      return count;
++}
++
++static DEVICE_ATTR_RW(force_ro);
++
+ static struct attribute *nvmem_attrs[] = {
++      &dev_attr_force_ro.attr,
+       &dev_attr_type.attr,
+       NULL,
+ };
+@@ -286,6 +309,25 @@ static umode_t nvmem_bin_attr_is_visible
+       return nvmem_bin_attr_get_umode(nvmem);
+ }
++static umode_t nvmem_attr_is_visible(struct kobject *kobj,
++                                   struct attribute *attr, int i)
++{
++      struct device *dev = kobj_to_dev(kobj);
++      struct nvmem_device *nvmem = to_nvmem_device(dev);
++
++      /*
++       * If the device has no .reg_write operation, do not allow
++       * configuration as read-write.
++       * If the device is set as read-only by configuration, it
++       * can be forced into read-write mode using the 'force_ro'
++       * attribute.
++       */
++      if (attr == &dev_attr_force_ro.attr && !nvmem->reg_write)
++              return 0;       /* Attribute not visible */
++
++      return attr->mode;
++}
++
+ static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry,
+                                           const char *id, int index);
+@@ -342,6 +384,7 @@ static const struct attribute_group nvme
+       .bin_attrs      = nvmem_bin_attributes,
+       .attrs          = nvmem_attrs,
+       .is_bin_visible = nvmem_bin_attr_is_visible,
++      .is_visible     = nvmem_attr_is_visible,
+ };
+ static const struct attribute_group *nvmem_dev_groups[] = {
diff --git a/target/linux/generic/backport-5.15/838-v6.11-0011-nvmem-u-boot-env-error-if-NVMEM-device-is-too-small.patch b/target/linux/generic/backport-5.15/838-v6.11-0011-nvmem-u-boot-env-error-if-NVMEM-device-is-too-small.patch
new file mode 100644 (file)
index 0000000..70d420f
--- /dev/null
@@ -0,0 +1,40 @@
+From 8679e8b4a1ebdb40c4429e49368d29353e07b601 Mon Sep 17 00:00:00 2001
+From: John Thomson <git@johnthomson.fastmail.com.au>
+Date: Mon, 2 Sep 2024 15:25:08 +0100
+Subject: [PATCH] nvmem: u-boot-env: error if NVMEM device is too small
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Verify data size before trying to parse it to avoid reading out of
+buffer. This could happen in case of problems at MTD level or invalid DT
+bindings.
+
+Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
+Cc: stable <stable@kernel.org>
+Fixes: d5542923f200 ("nvmem: add driver handling U-Boot environment variables")
+[rmilecki: simplify commit description & rebase]
+Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240902142510.71096-2-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/u-boot-env.c | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+--- a/drivers/nvmem/u-boot-env.c
++++ b/drivers/nvmem/u-boot-env.c
+@@ -176,6 +176,13 @@ static int u_boot_env_parse(struct u_boo
+               data_offset = offsetof(struct u_boot_env_image_broadcom, data);
+               break;
+       }
++
++      if (dev_size < data_offset) {
++              dev_err(dev, "Device too small for u-boot-env\n");
++              err = -EIO;
++              goto err_kfree;
++      }
++
+       crc32_addr = (__le32 *)(buf + crc32_offset);
+       crc32 = le32_to_cpu(*crc32_addr);
+       crc32_data_len = dev_size - crc32_data_offset;
diff --git a/target/linux/generic/backport-5.15/838-v6.11-0012-nvmem-Fix-return-type-of-devm_nvmem_device_get-in-ke.patch b/target/linux/generic/backport-5.15/838-v6.11-0012-nvmem-Fix-return-type-of-devm_nvmem_device_get-in-ke.patch
new file mode 100644 (file)
index 0000000..08f6278
--- /dev/null
@@ -0,0 +1,37 @@
+From c69f37f6559a8948d70badd2b179db7714dedd62 Mon Sep 17 00:00:00 2001
+From: Geert Uytterhoeven <geert+renesas@glider.be>
+Date: Mon, 2 Sep 2024 15:25:09 +0100
+Subject: [PATCH] nvmem: Fix return type of devm_nvmem_device_get() in
+ kerneldoc
+
+devm_nvmem_device_get() returns an nvmem device, not an nvmem cell.
+
+Fixes: e2a5402ec7c6d044 ("nvmem: Add nvmem_device based consumer apis.")
+Cc: stable <stable@kernel.org>
+Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240902142510.71096-3-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -1276,13 +1276,13 @@ void nvmem_device_put(struct nvmem_devic
+ EXPORT_SYMBOL_GPL(nvmem_device_put);
+ /**
+- * devm_nvmem_device_get() - Get nvmem cell of device form a given id
++ * devm_nvmem_device_get() - Get nvmem device of device form a given id
+  *
+  * @dev: Device that requests the nvmem device.
+  * @id: name id for the requested nvmem device.
+  *
+- * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_cell
+- * on success.  The nvmem_cell will be freed by the automatically once the
++ * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_device
++ * on success.  The nvmem_device will be freed by the automatically once the
+  * device is freed.
+  */
+ struct nvmem_device *devm_nvmem_device_get(struct device *dev, const char *id)
diff --git a/target/linux/generic/backport-6.1/840-v6.11-0001-nvmem-add-missing-MODULE_DESCRIPTION-macros.patch b/target/linux/generic/backport-6.1/840-v6.11-0001-nvmem-add-missing-MODULE_DESCRIPTION-macros.patch
new file mode 100644 (file)
index 0000000..a8ce832
--- /dev/null
@@ -0,0 +1,48 @@
+From c553bad4c5fc5ae44bd2fcaa73e1d6bedfb1c35c Mon Sep 17 00:00:00 2001
+From: Jeff Johnson <quic_jjohnson@quicinc.com>
+Date: Fri, 5 Jul 2024 08:48:38 +0100
+Subject: [PATCH] nvmem: add missing MODULE_DESCRIPTION() macros
+
+make allmodconfig && make W=1 C=1 reports:
+WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvmem/nvmem-apple-efuses.o
+WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvmem/nvmem_brcm_nvram.o
+WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvmem/nvmem_u-boot-env.o
+
+Add the missing invocations of the MODULE_DESCRIPTION() macro.
+
+Signed-off-by: Jeff Johnson <quic_jjohnson@quicinc.com>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-2-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/apple-efuses.c | 1 +
+ drivers/nvmem/brcm_nvram.c   | 1 +
+ drivers/nvmem/u-boot-env.c   | 1 +
+ 3 files changed, 3 insertions(+)
+
+--- a/drivers/nvmem/apple-efuses.c
++++ b/drivers/nvmem/apple-efuses.c
+@@ -78,4 +78,5 @@ static struct platform_driver apple_efus
+ module_platform_driver(apple_efuses_driver);
+ MODULE_AUTHOR("Sven Peter <sven@svenpeter.dev>");
++MODULE_DESCRIPTION("Apple SoC eFuse driver");
+ MODULE_LICENSE("GPL");
+--- a/drivers/nvmem/brcm_nvram.c
++++ b/drivers/nvmem/brcm_nvram.c
+@@ -253,5 +253,6 @@ static int __init brcm_nvram_init(void)
+ subsys_initcall_sync(brcm_nvram_init);
+ MODULE_AUTHOR("Rafał Miłecki");
++MODULE_DESCRIPTION("Broadcom I/O-mapped NVRAM support driver");
+ MODULE_LICENSE("GPL");
+ MODULE_DEVICE_TABLE(of, brcm_nvram_of_match_table);
+--- a/drivers/nvmem/u-boot-env.c
++++ b/drivers/nvmem/u-boot-env.c
+@@ -249,5 +249,6 @@ static struct platform_driver u_boot_env
+ module_platform_driver(u_boot_env_driver);
+ MODULE_AUTHOR("Rafał Miłecki");
++MODULE_DESCRIPTION("U-Boot environment variables support module");
+ MODULE_LICENSE("GPL");
+ MODULE_DEVICE_TABLE(of, u_boot_env_of_match_table);
diff --git a/target/linux/generic/backport-6.1/840-v6.11-0002-nvmem-meson-efuse-Replacing-the-use-of-of_node_put-t.patch b/target/linux/generic/backport-6.1/840-v6.11-0002-nvmem-meson-efuse-Replacing-the-use-of-of_node_put-t.patch
new file mode 100644 (file)
index 0000000..05c82db
--- /dev/null
@@ -0,0 +1,48 @@
+From 5fecb932607d83d37a703c731268e9d9051457f5 Mon Sep 17 00:00:00 2001
+From: MarileneGarcia <marilene.agarcia@gmail.com>
+Date: Fri, 5 Jul 2024 08:48:40 +0100
+Subject: [PATCH] nvmem: meson-efuse: Replacing the use of of_node_put to
+ __free
+
+Use __free for device_node values, and thus drop calls to
+of_node_put.
+
+The goal is to reduce memory management issues by using this
+scope-based of_node_put() cleanup to simplify function exit
+handling. When using __free a resource is allocated within a
+block, it is automatically freed at the end of the block.
+
+Suggested-by: Julia Lawall <julia.lawall@inria.fr>
+Signed-off-by: MarileneGarcia <marilene.agarcia@gmail.com>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-4-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/meson-efuse.c | 5 ++---
+ 1 file changed, 2 insertions(+), 3 deletions(-)
+
+--- a/drivers/nvmem/meson-efuse.c
++++ b/drivers/nvmem/meson-efuse.c
+@@ -48,20 +48,19 @@ static int meson_efuse_probe(struct plat
+ {
+       struct device *dev = &pdev->dev;
+       struct meson_sm_firmware *fw;
+-      struct device_node *sm_np;
+       struct nvmem_device *nvmem;
+       struct nvmem_config *econfig;
+       struct clk *clk;
+       unsigned int size;
++      struct device_node *sm_np __free(device_node) =
++                      of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
+-      sm_np = of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
+       if (!sm_np) {
+               dev_err(&pdev->dev, "no secure-monitor node\n");
+               return -ENODEV;
+       }
+       fw = meson_sm_get(sm_np);
+-      of_node_put(sm_np);
+       if (!fw)
+               return -EPROBE_DEFER;
diff --git a/target/linux/generic/backport-6.1/840-v6.11-0003-nvmem-rockchip-otp-set-add_legacy_fixed_of_cells-con.patch b/target/linux/generic/backport-6.1/840-v6.11-0003-nvmem-rockchip-otp-set-add_legacy_fixed_of_cells-con.patch
new file mode 100644 (file)
index 0000000..a8a30fc
--- /dev/null
@@ -0,0 +1,28 @@
+From 2933e79db3c00a8cdc56f6bb050a857fec1875ad Mon Sep 17 00:00:00 2001
+From: Heiko Stuebner <heiko.stuebner@cherry.de>
+Date: Fri, 5 Jul 2024 08:48:41 +0100
+Subject: [PATCH] nvmem: rockchip-otp: set add_legacy_fixed_of_cells config
+ option
+
+The Rockchip OTP describes its layout via devicetree subnodes,
+so set the appropriate property.
+
+Fixes: 2cc3b37f5b6d ("nvmem: add explicit config option to read old syntax fixed OF cells")
+Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-5-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/rockchip-otp.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/drivers/nvmem/rockchip-otp.c
++++ b/drivers/nvmem/rockchip-otp.c
+@@ -255,6 +255,7 @@ static int rockchip_otp_read(void *conte
+ static struct nvmem_config otp_config = {
+       .name = "rockchip-otp",
+       .owner = THIS_MODULE,
++      .add_legacy_fixed_of_cells = true,
+       .read_only = true,
+       .stride = 1,
+       .word_size = 1,
diff --git a/target/linux/generic/backport-6.1/840-v6.11-0004-nvmem-rockchip-otp-Set-type-to-OTP.patch b/target/linux/generic/backport-6.1/840-v6.11-0004-nvmem-rockchip-otp-Set-type-to-OTP.patch
new file mode 100644 (file)
index 0000000..8491eb3
--- /dev/null
@@ -0,0 +1,25 @@
+From 39f95600d8c53355b212a117e91a6ba15e0cac47 Mon Sep 17 00:00:00 2001
+From: Heiko Stuebner <heiko.stuebner@cherry.de>
+Date: Fri, 5 Jul 2024 08:48:42 +0100
+Subject: [PATCH] nvmem: rockchip-otp: Set type to OTP
+
+The Rockchip OTP is obviously an OTP memory, so document this fact.
+
+Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-6-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/rockchip-otp.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/drivers/nvmem/rockchip-otp.c
++++ b/drivers/nvmem/rockchip-otp.c
+@@ -256,6 +256,7 @@ static struct nvmem_config otp_config =
+       .name = "rockchip-otp",
+       .owner = THIS_MODULE,
+       .add_legacy_fixed_of_cells = true,
++      .type = NVMEM_TYPE_OTP,
+       .read_only = true,
+       .stride = 1,
+       .word_size = 1,
diff --git a/target/linux/generic/backport-6.1/840-v6.11-0005-nvmem-rockchip-efuse-set-type-to-OTP.patch b/target/linux/generic/backport-6.1/840-v6.11-0005-nvmem-rockchip-efuse-set-type-to-OTP.patch
new file mode 100644 (file)
index 0000000..260b03e
--- /dev/null
@@ -0,0 +1,26 @@
+From ba64a04474d2989f397982c48e405cfd785e2dd5 Mon Sep 17 00:00:00 2001
+From: Heiko Stuebner <heiko.stuebner@cherry.de>
+Date: Fri, 5 Jul 2024 08:48:43 +0100
+Subject: [PATCH] nvmem: rockchip-efuse: set type to OTP
+
+This device currently reports an "Unknown" type in sysfs.
+Since it is an eFuse hardware device, set its type to OTP.
+
+Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-7-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/rockchip-efuse.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/drivers/nvmem/rockchip-efuse.c
++++ b/drivers/nvmem/rockchip-efuse.c
+@@ -206,6 +206,7 @@ static int rockchip_rk3399_efuse_read(vo
+ static struct nvmem_config econfig = {
+       .name = "rockchip-efuse",
+       .add_legacy_fixed_of_cells = true,
++      .type = NVMEM_TYPE_OTP,
+       .stride = 1,
+       .word_size = 1,
+       .read_only = true,
diff --git a/target/linux/generic/backport-6.1/840-v6.11-0006-nvmem-core-add-single-sysfs-group.patch b/target/linux/generic/backport-6.1/840-v6.11-0006-nvmem-core-add-single-sysfs-group.patch
new file mode 100644 (file)
index 0000000..4fb2afd
--- /dev/null
@@ -0,0 +1,42 @@
+From 6188f233161c6a5b2d1c396a221dfafc77dc9eec Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <linux@weissschuh.net>
+Date: Fri, 5 Jul 2024 08:48:46 +0100
+Subject: [PATCH] nvmem: core: add single sysfs group
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The sysfs core provides a function to easily register a single group.
+Use it and remove the now unnecessary nvmem_cells_groups array.
+
+Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-10-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 7 +------
+ 1 file changed, 1 insertion(+), 6 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -368,11 +368,6 @@ static const struct attribute_group *nvm
+       NULL,
+ };
+-static const struct attribute_group *nvmem_cells_groups[] = {
+-      &nvmem_cells_group,
+-      NULL,
+-};
+-
+ static struct bin_attribute bin_attr_nvmem_eeprom_compat = {
+       .attr   = {
+               .name   = "eeprom",
+@@ -477,7 +472,7 @@ static int nvmem_populate_sysfs_cells(st
+       nvmem_cells_group.bin_attrs = cells_attrs;
+-      ret = device_add_groups(&nvmem->dev, nvmem_cells_groups);
++      ret = device_add_group(&nvmem->dev, &nvmem_cells_group);
+       if (ret)
+               goto unlock_mutex;
diff --git a/target/linux/generic/backport-6.1/840-v6.11-0007-nvmem-core-remove-global-nvmem_cells_group.patch b/target/linux/generic/backport-6.1/840-v6.11-0007-nvmem-core-remove-global-nvmem_cells_group.patch
new file mode 100644 (file)
index 0000000..ef626d3
--- /dev/null
@@ -0,0 +1,83 @@
+From 6839fed062b7898665983368c88269a6fb1fc10f Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <linux@weissschuh.net>
+Date: Fri, 5 Jul 2024 08:48:47 +0100
+Subject: [PATCH] nvmem: core: remove global nvmem_cells_group
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+nvmem_cells_groups is a global variable that is also mutated.
+This is complicated and error-prone.
+
+Instead use a normal stack variable.
+
+Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-11-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 26 ++++++++++----------------
+ 1 file changed, 10 insertions(+), 16 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -358,11 +358,6 @@ static const struct attribute_group nvme
+       .is_bin_visible = nvmem_bin_attr_is_visible,
+ };
+-/* Cell attributes will be dynamically allocated */
+-static struct attribute_group nvmem_cells_group = {
+-      .name           = "cells",
+-};
+-
+ static const struct attribute_group *nvmem_dev_groups[] = {
+       &nvmem_bin_group,
+       NULL,
+@@ -424,23 +419,24 @@ static void nvmem_sysfs_remove_compat(st
+ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
+ {
+-      struct bin_attribute **cells_attrs, *attrs;
++      struct attribute_group group = {
++              .name   = "cells",
++      };
+       struct nvmem_cell_entry *entry;
++      struct bin_attribute *attrs;
+       unsigned int ncells = 0, i = 0;
+       int ret = 0;
+       mutex_lock(&nvmem_mutex);
+-      if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated) {
+-              nvmem_cells_group.bin_attrs = NULL;
++      if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated)
+               goto unlock_mutex;
+-      }
+       /* Allocate an array of attributes with a sentinel */
+       ncells = list_count_nodes(&nvmem->cells);
+-      cells_attrs = devm_kcalloc(&nvmem->dev, ncells + 1,
+-                                 sizeof(struct bin_attribute *), GFP_KERNEL);
+-      if (!cells_attrs) {
++      group.bin_attrs = devm_kcalloc(&nvmem->dev, ncells + 1,
++                                     sizeof(struct bin_attribute *), GFP_KERNEL);
++      if (!group.bin_attrs) {
+               ret = -ENOMEM;
+               goto unlock_mutex;
+       }
+@@ -466,13 +462,11 @@ static int nvmem_populate_sysfs_cells(st
+                       goto unlock_mutex;
+               }
+-              cells_attrs[i] = &attrs[i];
++              group.bin_attrs[i] = &attrs[i];
+               i++;
+       }
+-      nvmem_cells_group.bin_attrs = cells_attrs;
+-
+-      ret = device_add_group(&nvmem->dev, &nvmem_cells_group);
++      ret = device_add_group(&nvmem->dev, &group);
+       if (ret)
+               goto unlock_mutex;
diff --git a/target/linux/generic/backport-6.1/840-v6.11-0008-nvmem-core-drop-unnecessary-range-checks-in-sysfs-ca.patch b/target/linux/generic/backport-6.1/840-v6.11-0008-nvmem-core-drop-unnecessary-range-checks-in-sysfs-ca.patch
new file mode 100644 (file)
index 0000000..9b6251b
--- /dev/null
@@ -0,0 +1,61 @@
+From 588773802c386d38f9c4e91acd47369e89d95a30 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <linux@weissschuh.net>
+Date: Fri, 5 Jul 2024 08:48:48 +0100
+Subject: [PATCH] nvmem: core: drop unnecessary range checks in sysfs callbacks
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The same checks have already been done in sysfs_kf_bin_write() and
+sysfs_kf_bin_read() just before the callbacks are invoked.
+
+Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-12-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 14 --------------
+ 1 file changed, 14 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -204,19 +204,12 @@ static ssize_t bin_attr_nvmem_read(struc
+               dev = kobj_to_dev(kobj);
+       nvmem = to_nvmem_device(dev);
+-      /* Stop the user from reading */
+-      if (pos >= nvmem->size)
+-              return 0;
+-
+       if (!IS_ALIGNED(pos, nvmem->stride))
+               return -EINVAL;
+       if (count < nvmem->word_size)
+               return -EINVAL;
+-      if (pos + count > nvmem->size)
+-              count = nvmem->size - pos;
+-
+       count = round_down(count, nvmem->word_size);
+       if (!nvmem->reg_read)
+@@ -244,19 +237,12 @@ static ssize_t bin_attr_nvmem_write(stru
+               dev = kobj_to_dev(kobj);
+       nvmem = to_nvmem_device(dev);
+-      /* Stop the user from writing */
+-      if (pos >= nvmem->size)
+-              return -EFBIG;
+-
+       if (!IS_ALIGNED(pos, nvmem->stride))
+               return -EINVAL;
+       if (count < nvmem->word_size)
+               return -EINVAL;
+-      if (pos + count > nvmem->size)
+-              count = nvmem->size - pos;
+-
+       count = round_down(count, nvmem->word_size);
+       if (!nvmem->reg_write)
diff --git a/target/linux/generic/backport-6.1/840-v6.11-0009-nvmem-Use-sysfs_emit-for-type-attribute.patch b/target/linux/generic/backport-6.1/840-v6.11-0009-nvmem-Use-sysfs_emit-for-type-attribute.patch
new file mode 100644 (file)
index 0000000..3da1feb
--- /dev/null
@@ -0,0 +1,30 @@
+From 08c367e45b6d322956878774f0b88bf5e52c6d54 Mon Sep 17 00:00:00 2001
+From: Marek Vasut <marex@denx.de>
+Date: Fri, 5 Jul 2024 08:48:51 +0100
+Subject: [PATCH] nvmem: Use sysfs_emit() for type attribute
+
+Use sysfs_emit() instead of sprintf() to follow best practice per
+Documentation/filesystems/sysfs.rst
+"
+show() should only use sysfs_emit()...
+"
+
+Signed-off-by: Marek Vasut <marex@denx.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-15-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -180,7 +180,7 @@ static ssize_t type_show(struct device *
+ {
+       struct nvmem_device *nvmem = to_nvmem_device(dev);
+-      return sprintf(buf, "%s\n", nvmem_type_str[nvmem->type]);
++      return sysfs_emit(buf, "%s\n", nvmem_type_str[nvmem->type]);
+ }
+ static DEVICE_ATTR_RO(type);
diff --git a/target/linux/generic/backport-6.1/840-v6.11-0010-nvmem-core-Implement-force_ro-sysfs-attribute.patch b/target/linux/generic/backport-6.1/840-v6.11-0010-nvmem-core-Implement-force_ro-sysfs-attribute.patch
new file mode 100644 (file)
index 0000000..ac7dda1
--- /dev/null
@@ -0,0 +1,122 @@
+From 9d7eb234ac7a56b88aea8a52ed81553a730fe25c Mon Sep 17 00:00:00 2001
+From: Marek Vasut <marex@denx.de>
+Date: Fri, 5 Jul 2024 08:48:52 +0100
+Subject: [PATCH] nvmem: core: Implement force_ro sysfs attribute
+
+Implement "force_ro" sysfs attribute to allow users to set read-write
+devices as read-only and back to read-write from userspace. The choice
+of the name is based on MMC core 'force_ro' attribute.
+
+This solves a situation where an AT24 I2C EEPROM with GPIO based nWP
+signal may have to be occasionally updated. Such I2C EEPROM device is
+usually set as read-only during most of the regular system operation,
+but in case it has to be updated in a controlled manner, it could be
+unlocked using this new "force_ro" sysfs attribute and then re-locked
+again.
+
+The "read-only" DT property and config->read_only configuration is
+respected and is used to set default state of the device, read-only
+or read-write, for devices which do implement .reg_write function.
+For devices which do not implement .reg_write function, the device
+is unconditionally read-only and the "force_ro" attribute is not
+visible.
+
+Signed-off-by: Marek Vasut <marex@denx.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-16-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ Documentation/ABI/stable/sysfs-bus-nvmem | 17 ++++++++++
+ drivers/nvmem/core.c                     | 43 ++++++++++++++++++++++++
+ 2 files changed, 60 insertions(+)
+
+--- a/Documentation/ABI/stable/sysfs-bus-nvmem
++++ b/Documentation/ABI/stable/sysfs-bus-nvmem
+@@ -1,3 +1,20 @@
++What:         /sys/bus/nvmem/devices/.../force_ro
++Date:         June 2024
++KernelVersion:        6.11
++Contact:      Marek Vasut <marex@denx.de>
++Description:
++              This read/write attribute allows users to set read-write
++              devices as read-only and back to read-write from userspace.
++              This can be used to unlock and relock write-protection of
++              devices which are generally locked, except during sporadic
++              programming operation.
++              Read returns '0' or '1' for read-write or read-only modes
++              respectively.
++              Write parses one of 'YyTt1NnFf0', or [oO][NnFf] for "on"
++              and "off", i.e. what kstrbool() supports.
++              Note: This file is only present if CONFIG_NVMEM_SYSFS
++              is enabled.
++
+ What:         /sys/bus/nvmem/devices/.../nvmem
+ Date:         July 2015
+ KernelVersion:  4.2
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -185,7 +185,30 @@ static ssize_t type_show(struct device *
+ static DEVICE_ATTR_RO(type);
++static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr,
++                           char *buf)
++{
++      struct nvmem_device *nvmem = to_nvmem_device(dev);
++
++      return sysfs_emit(buf, "%d\n", nvmem->read_only);
++}
++
++static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr,
++                            const char *buf, size_t count)
++{
++      struct nvmem_device *nvmem = to_nvmem_device(dev);
++      int ret = kstrtobool(buf, &nvmem->read_only);
++
++      if (ret < 0)
++              return ret;
++
++      return count;
++}
++
++static DEVICE_ATTR_RW(force_ro);
++
+ static struct attribute *nvmem_attrs[] = {
++      &dev_attr_force_ro.attr,
+       &dev_attr_type.attr,
+       NULL,
+ };
+@@ -286,6 +309,25 @@ static umode_t nvmem_bin_attr_is_visible
+       return nvmem_bin_attr_get_umode(nvmem);
+ }
++static umode_t nvmem_attr_is_visible(struct kobject *kobj,
++                                   struct attribute *attr, int i)
++{
++      struct device *dev = kobj_to_dev(kobj);
++      struct nvmem_device *nvmem = to_nvmem_device(dev);
++
++      /*
++       * If the device has no .reg_write operation, do not allow
++       * configuration as read-write.
++       * If the device is set as read-only by configuration, it
++       * can be forced into read-write mode using the 'force_ro'
++       * attribute.
++       */
++      if (attr == &dev_attr_force_ro.attr && !nvmem->reg_write)
++              return 0;       /* Attribute not visible */
++
++      return attr->mode;
++}
++
+ static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry,
+                                           const char *id, int index);
+@@ -342,6 +384,7 @@ static const struct attribute_group nvme
+       .bin_attrs      = nvmem_bin_attributes,
+       .attrs          = nvmem_attrs,
+       .is_bin_visible = nvmem_bin_attr_is_visible,
++      .is_visible     = nvmem_attr_is_visible,
+ };
+ static const struct attribute_group *nvmem_dev_groups[] = {
diff --git a/target/linux/generic/backport-6.1/840-v6.11-0011-nvmem-u-boot-env-error-if-NVMEM-device-is-too-small.patch b/target/linux/generic/backport-6.1/840-v6.11-0011-nvmem-u-boot-env-error-if-NVMEM-device-is-too-small.patch
new file mode 100644 (file)
index 0000000..70d420f
--- /dev/null
@@ -0,0 +1,40 @@
+From 8679e8b4a1ebdb40c4429e49368d29353e07b601 Mon Sep 17 00:00:00 2001
+From: John Thomson <git@johnthomson.fastmail.com.au>
+Date: Mon, 2 Sep 2024 15:25:08 +0100
+Subject: [PATCH] nvmem: u-boot-env: error if NVMEM device is too small
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Verify data size before trying to parse it to avoid reading out of
+buffer. This could happen in case of problems at MTD level or invalid DT
+bindings.
+
+Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
+Cc: stable <stable@kernel.org>
+Fixes: d5542923f200 ("nvmem: add driver handling U-Boot environment variables")
+[rmilecki: simplify commit description & rebase]
+Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240902142510.71096-2-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/u-boot-env.c | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+--- a/drivers/nvmem/u-boot-env.c
++++ b/drivers/nvmem/u-boot-env.c
+@@ -176,6 +176,13 @@ static int u_boot_env_parse(struct u_boo
+               data_offset = offsetof(struct u_boot_env_image_broadcom, data);
+               break;
+       }
++
++      if (dev_size < data_offset) {
++              dev_err(dev, "Device too small for u-boot-env\n");
++              err = -EIO;
++              goto err_kfree;
++      }
++
+       crc32_addr = (__le32 *)(buf + crc32_offset);
+       crc32 = le32_to_cpu(*crc32_addr);
+       crc32_data_len = dev_size - crc32_data_offset;
diff --git a/target/linux/generic/backport-6.1/840-v6.11-0012-nvmem-Fix-return-type-of-devm_nvmem_device_get-in-ke.patch b/target/linux/generic/backport-6.1/840-v6.11-0012-nvmem-Fix-return-type-of-devm_nvmem_device_get-in-ke.patch
new file mode 100644 (file)
index 0000000..08f6278
--- /dev/null
@@ -0,0 +1,37 @@
+From c69f37f6559a8948d70badd2b179db7714dedd62 Mon Sep 17 00:00:00 2001
+From: Geert Uytterhoeven <geert+renesas@glider.be>
+Date: Mon, 2 Sep 2024 15:25:09 +0100
+Subject: [PATCH] nvmem: Fix return type of devm_nvmem_device_get() in
+ kerneldoc
+
+devm_nvmem_device_get() returns an nvmem device, not an nvmem cell.
+
+Fixes: e2a5402ec7c6d044 ("nvmem: Add nvmem_device based consumer apis.")
+Cc: stable <stable@kernel.org>
+Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240902142510.71096-3-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -1276,13 +1276,13 @@ void nvmem_device_put(struct nvmem_devic
+ EXPORT_SYMBOL_GPL(nvmem_device_put);
+ /**
+- * devm_nvmem_device_get() - Get nvmem cell of device form a given id
++ * devm_nvmem_device_get() - Get nvmem device of device form a given id
+  *
+  * @dev: Device that requests the nvmem device.
+  * @id: name id for the requested nvmem device.
+  *
+- * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_cell
+- * on success.  The nvmem_cell will be freed by the automatically once the
++ * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_device
++ * on success.  The nvmem_device will be freed by the automatically once the
+  * device is freed.
+  */
+ struct nvmem_device *devm_nvmem_device_get(struct device *dev, const char *id)
diff --git a/target/linux/generic/backport-6.6/822-v6.11-0001-nvmem-add-missing-MODULE_DESCRIPTION-macros.patch b/target/linux/generic/backport-6.6/822-v6.11-0001-nvmem-add-missing-MODULE_DESCRIPTION-macros.patch
new file mode 100644 (file)
index 0000000..a8ce832
--- /dev/null
@@ -0,0 +1,48 @@
+From c553bad4c5fc5ae44bd2fcaa73e1d6bedfb1c35c Mon Sep 17 00:00:00 2001
+From: Jeff Johnson <quic_jjohnson@quicinc.com>
+Date: Fri, 5 Jul 2024 08:48:38 +0100
+Subject: [PATCH] nvmem: add missing MODULE_DESCRIPTION() macros
+
+make allmodconfig && make W=1 C=1 reports:
+WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvmem/nvmem-apple-efuses.o
+WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvmem/nvmem_brcm_nvram.o
+WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/nvmem/nvmem_u-boot-env.o
+
+Add the missing invocations of the MODULE_DESCRIPTION() macro.
+
+Signed-off-by: Jeff Johnson <quic_jjohnson@quicinc.com>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-2-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/apple-efuses.c | 1 +
+ drivers/nvmem/brcm_nvram.c   | 1 +
+ drivers/nvmem/u-boot-env.c   | 1 +
+ 3 files changed, 3 insertions(+)
+
+--- a/drivers/nvmem/apple-efuses.c
++++ b/drivers/nvmem/apple-efuses.c
+@@ -78,4 +78,5 @@ static struct platform_driver apple_efus
+ module_platform_driver(apple_efuses_driver);
+ MODULE_AUTHOR("Sven Peter <sven@svenpeter.dev>");
++MODULE_DESCRIPTION("Apple SoC eFuse driver");
+ MODULE_LICENSE("GPL");
+--- a/drivers/nvmem/brcm_nvram.c
++++ b/drivers/nvmem/brcm_nvram.c
+@@ -253,5 +253,6 @@ static int __init brcm_nvram_init(void)
+ subsys_initcall_sync(brcm_nvram_init);
+ MODULE_AUTHOR("Rafał Miłecki");
++MODULE_DESCRIPTION("Broadcom I/O-mapped NVRAM support driver");
+ MODULE_LICENSE("GPL");
+ MODULE_DEVICE_TABLE(of, brcm_nvram_of_match_table);
+--- a/drivers/nvmem/u-boot-env.c
++++ b/drivers/nvmem/u-boot-env.c
+@@ -249,5 +249,6 @@ static struct platform_driver u_boot_env
+ module_platform_driver(u_boot_env_driver);
+ MODULE_AUTHOR("Rafał Miłecki");
++MODULE_DESCRIPTION("U-Boot environment variables support module");
+ MODULE_LICENSE("GPL");
+ MODULE_DEVICE_TABLE(of, u_boot_env_of_match_table);
diff --git a/target/linux/generic/backport-6.6/822-v6.11-0002-nvmem-meson-efuse-Replacing-the-use-of-of_node_put-t.patch b/target/linux/generic/backport-6.6/822-v6.11-0002-nvmem-meson-efuse-Replacing-the-use-of-of_node_put-t.patch
new file mode 100644 (file)
index 0000000..05c82db
--- /dev/null
@@ -0,0 +1,48 @@
+From 5fecb932607d83d37a703c731268e9d9051457f5 Mon Sep 17 00:00:00 2001
+From: MarileneGarcia <marilene.agarcia@gmail.com>
+Date: Fri, 5 Jul 2024 08:48:40 +0100
+Subject: [PATCH] nvmem: meson-efuse: Replacing the use of of_node_put to
+ __free
+
+Use __free for device_node values, and thus drop calls to
+of_node_put.
+
+The goal is to reduce memory management issues by using this
+scope-based of_node_put() cleanup to simplify function exit
+handling. When using __free a resource is allocated within a
+block, it is automatically freed at the end of the block.
+
+Suggested-by: Julia Lawall <julia.lawall@inria.fr>
+Signed-off-by: MarileneGarcia <marilene.agarcia@gmail.com>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-4-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/meson-efuse.c | 5 ++---
+ 1 file changed, 2 insertions(+), 3 deletions(-)
+
+--- a/drivers/nvmem/meson-efuse.c
++++ b/drivers/nvmem/meson-efuse.c
+@@ -48,20 +48,19 @@ static int meson_efuse_probe(struct plat
+ {
+       struct device *dev = &pdev->dev;
+       struct meson_sm_firmware *fw;
+-      struct device_node *sm_np;
+       struct nvmem_device *nvmem;
+       struct nvmem_config *econfig;
+       struct clk *clk;
+       unsigned int size;
++      struct device_node *sm_np __free(device_node) =
++                      of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
+-      sm_np = of_parse_phandle(pdev->dev.of_node, "secure-monitor", 0);
+       if (!sm_np) {
+               dev_err(&pdev->dev, "no secure-monitor node\n");
+               return -ENODEV;
+       }
+       fw = meson_sm_get(sm_np);
+-      of_node_put(sm_np);
+       if (!fw)
+               return -EPROBE_DEFER;
diff --git a/target/linux/generic/backport-6.6/822-v6.11-0004-nvmem-rockchip-otp-Set-type-to-OTP.patch b/target/linux/generic/backport-6.6/822-v6.11-0004-nvmem-rockchip-otp-Set-type-to-OTP.patch
new file mode 100644 (file)
index 0000000..8491eb3
--- /dev/null
@@ -0,0 +1,25 @@
+From 39f95600d8c53355b212a117e91a6ba15e0cac47 Mon Sep 17 00:00:00 2001
+From: Heiko Stuebner <heiko.stuebner@cherry.de>
+Date: Fri, 5 Jul 2024 08:48:42 +0100
+Subject: [PATCH] nvmem: rockchip-otp: Set type to OTP
+
+The Rockchip OTP is obviously an OTP memory, so document this fact.
+
+Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-6-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/rockchip-otp.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/drivers/nvmem/rockchip-otp.c
++++ b/drivers/nvmem/rockchip-otp.c
+@@ -256,6 +256,7 @@ static struct nvmem_config otp_config =
+       .name = "rockchip-otp",
+       .owner = THIS_MODULE,
+       .add_legacy_fixed_of_cells = true,
++      .type = NVMEM_TYPE_OTP,
+       .read_only = true,
+       .stride = 1,
+       .word_size = 1,
diff --git a/target/linux/generic/backport-6.6/822-v6.11-0005-nvmem-rockchip-efuse-set-type-to-OTP.patch b/target/linux/generic/backport-6.6/822-v6.11-0005-nvmem-rockchip-efuse-set-type-to-OTP.patch
new file mode 100644 (file)
index 0000000..260b03e
--- /dev/null
@@ -0,0 +1,26 @@
+From ba64a04474d2989f397982c48e405cfd785e2dd5 Mon Sep 17 00:00:00 2001
+From: Heiko Stuebner <heiko.stuebner@cherry.de>
+Date: Fri, 5 Jul 2024 08:48:43 +0100
+Subject: [PATCH] nvmem: rockchip-efuse: set type to OTP
+
+This device currently reports an "Unknown" type in sysfs.
+Since it is an eFuse hardware device, set its type to OTP.
+
+Signed-off-by: Heiko Stuebner <heiko.stuebner@cherry.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-7-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/rockchip-efuse.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/drivers/nvmem/rockchip-efuse.c
++++ b/drivers/nvmem/rockchip-efuse.c
+@@ -206,6 +206,7 @@ static int rockchip_rk3399_efuse_read(vo
+ static struct nvmem_config econfig = {
+       .name = "rockchip-efuse",
+       .add_legacy_fixed_of_cells = true,
++      .type = NVMEM_TYPE_OTP,
+       .stride = 1,
+       .word_size = 1,
+       .read_only = true,
diff --git a/target/linux/generic/backport-6.6/822-v6.11-0006-nvmem-core-add-single-sysfs-group.patch b/target/linux/generic/backport-6.6/822-v6.11-0006-nvmem-core-add-single-sysfs-group.patch
new file mode 100644 (file)
index 0000000..eae06b2
--- /dev/null
@@ -0,0 +1,42 @@
+From 6188f233161c6a5b2d1c396a221dfafc77dc9eec Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <linux@weissschuh.net>
+Date: Fri, 5 Jul 2024 08:48:46 +0100
+Subject: [PATCH] nvmem: core: add single sysfs group
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The sysfs core provides a function to easily register a single group.
+Use it and remove the now unnecessary nvmem_cells_groups array.
+
+Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-10-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 7 +------
+ 1 file changed, 1 insertion(+), 6 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -367,11 +367,6 @@ static const struct attribute_group *nvm
+       NULL,
+ };
+-static const struct attribute_group *nvmem_cells_groups[] = {
+-      &nvmem_cells_group,
+-      NULL,
+-};
+-
+ static struct bin_attribute bin_attr_nvmem_eeprom_compat = {
+       .attr   = {
+               .name   = "eeprom",
+@@ -476,7 +471,7 @@ static int nvmem_populate_sysfs_cells(st
+       nvmem_cells_group.bin_attrs = cells_attrs;
+-      ret = device_add_groups(&nvmem->dev, nvmem_cells_groups);
++      ret = device_add_group(&nvmem->dev, &nvmem_cells_group);
+       if (ret)
+               goto unlock_mutex;
diff --git a/target/linux/generic/backport-6.6/822-v6.11-0007-nvmem-core-remove-global-nvmem_cells_group.patch b/target/linux/generic/backport-6.6/822-v6.11-0007-nvmem-core-remove-global-nvmem_cells_group.patch
new file mode 100644 (file)
index 0000000..9ec523c
--- /dev/null
@@ -0,0 +1,83 @@
+From 6839fed062b7898665983368c88269a6fb1fc10f Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <linux@weissschuh.net>
+Date: Fri, 5 Jul 2024 08:48:47 +0100
+Subject: [PATCH] nvmem: core: remove global nvmem_cells_group
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+nvmem_cells_groups is a global variable that is also mutated.
+This is complicated and error-prone.
+
+Instead use a normal stack variable.
+
+Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-11-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 26 ++++++++++----------------
+ 1 file changed, 10 insertions(+), 16 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -357,11 +357,6 @@ static const struct attribute_group nvme
+       .is_bin_visible = nvmem_bin_attr_is_visible,
+ };
+-/* Cell attributes will be dynamically allocated */
+-static struct attribute_group nvmem_cells_group = {
+-      .name           = "cells",
+-};
+-
+ static const struct attribute_group *nvmem_dev_groups[] = {
+       &nvmem_bin_group,
+       NULL,
+@@ -423,23 +418,24 @@ static void nvmem_sysfs_remove_compat(st
+ static int nvmem_populate_sysfs_cells(struct nvmem_device *nvmem)
+ {
+-      struct bin_attribute **cells_attrs, *attrs;
++      struct attribute_group group = {
++              .name   = "cells",
++      };
+       struct nvmem_cell_entry *entry;
++      struct bin_attribute *attrs;
+       unsigned int ncells = 0, i = 0;
+       int ret = 0;
+       mutex_lock(&nvmem_mutex);
+-      if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated) {
+-              nvmem_cells_group.bin_attrs = NULL;
++      if (list_empty(&nvmem->cells) || nvmem->sysfs_cells_populated)
+               goto unlock_mutex;
+-      }
+       /* Allocate an array of attributes with a sentinel */
+       ncells = list_count_nodes(&nvmem->cells);
+-      cells_attrs = devm_kcalloc(&nvmem->dev, ncells + 1,
+-                                 sizeof(struct bin_attribute *), GFP_KERNEL);
+-      if (!cells_attrs) {
++      group.bin_attrs = devm_kcalloc(&nvmem->dev, ncells + 1,
++                                     sizeof(struct bin_attribute *), GFP_KERNEL);
++      if (!group.bin_attrs) {
+               ret = -ENOMEM;
+               goto unlock_mutex;
+       }
+@@ -465,13 +461,11 @@ static int nvmem_populate_sysfs_cells(st
+                       goto unlock_mutex;
+               }
+-              cells_attrs[i] = &attrs[i];
++              group.bin_attrs[i] = &attrs[i];
+               i++;
+       }
+-      nvmem_cells_group.bin_attrs = cells_attrs;
+-
+-      ret = device_add_group(&nvmem->dev, &nvmem_cells_group);
++      ret = device_add_group(&nvmem->dev, &group);
+       if (ret)
+               goto unlock_mutex;
diff --git a/target/linux/generic/backport-6.6/822-v6.11-0008-nvmem-core-drop-unnecessary-range-checks-in-sysfs-ca.patch b/target/linux/generic/backport-6.6/822-v6.11-0008-nvmem-core-drop-unnecessary-range-checks-in-sysfs-ca.patch
new file mode 100644 (file)
index 0000000..22408e5
--- /dev/null
@@ -0,0 +1,61 @@
+From 588773802c386d38f9c4e91acd47369e89d95a30 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <linux@weissschuh.net>
+Date: Fri, 5 Jul 2024 08:48:48 +0100
+Subject: [PATCH] nvmem: core: drop unnecessary range checks in sysfs callbacks
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The same checks have already been done in sysfs_kf_bin_write() and
+sysfs_kf_bin_read() just before the callbacks are invoked.
+
+Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-12-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 14 --------------
+ 1 file changed, 14 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -203,19 +203,12 @@ static ssize_t bin_attr_nvmem_read(struc
+               dev = kobj_to_dev(kobj);
+       nvmem = to_nvmem_device(dev);
+-      /* Stop the user from reading */
+-      if (pos >= nvmem->size)
+-              return 0;
+-
+       if (!IS_ALIGNED(pos, nvmem->stride))
+               return -EINVAL;
+       if (count < nvmem->word_size)
+               return -EINVAL;
+-      if (pos + count > nvmem->size)
+-              count = nvmem->size - pos;
+-
+       count = round_down(count, nvmem->word_size);
+       if (!nvmem->reg_read)
+@@ -243,19 +236,12 @@ static ssize_t bin_attr_nvmem_write(stru
+               dev = kobj_to_dev(kobj);
+       nvmem = to_nvmem_device(dev);
+-      /* Stop the user from writing */
+-      if (pos >= nvmem->size)
+-              return -EFBIG;
+-
+       if (!IS_ALIGNED(pos, nvmem->stride))
+               return -EINVAL;
+       if (count < nvmem->word_size)
+               return -EINVAL;
+-      if (pos + count > nvmem->size)
+-              count = nvmem->size - pos;
+-
+       count = round_down(count, nvmem->word_size);
+       if (!nvmem->reg_write)
diff --git a/target/linux/generic/backport-6.6/822-v6.11-0009-nvmem-Use-sysfs_emit-for-type-attribute.patch b/target/linux/generic/backport-6.6/822-v6.11-0009-nvmem-Use-sysfs_emit-for-type-attribute.patch
new file mode 100644 (file)
index 0000000..3159efb
--- /dev/null
@@ -0,0 +1,30 @@
+From 08c367e45b6d322956878774f0b88bf5e52c6d54 Mon Sep 17 00:00:00 2001
+From: Marek Vasut <marex@denx.de>
+Date: Fri, 5 Jul 2024 08:48:51 +0100
+Subject: [PATCH] nvmem: Use sysfs_emit() for type attribute
+
+Use sysfs_emit() instead of sprintf() to follow best practice per
+Documentation/filesystems/sysfs.rst
+"
+show() should only use sysfs_emit()...
+"
+
+Signed-off-by: Marek Vasut <marex@denx.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-15-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -179,7 +179,7 @@ static ssize_t type_show(struct device *
+ {
+       struct nvmem_device *nvmem = to_nvmem_device(dev);
+-      return sprintf(buf, "%s\n", nvmem_type_str[nvmem->type]);
++      return sysfs_emit(buf, "%s\n", nvmem_type_str[nvmem->type]);
+ }
+ static DEVICE_ATTR_RO(type);
diff --git a/target/linux/generic/backport-6.6/822-v6.11-0010-nvmem-core-Implement-force_ro-sysfs-attribute.patch b/target/linux/generic/backport-6.6/822-v6.11-0010-nvmem-core-Implement-force_ro-sysfs-attribute.patch
new file mode 100644 (file)
index 0000000..28fb544
--- /dev/null
@@ -0,0 +1,122 @@
+From 9d7eb234ac7a56b88aea8a52ed81553a730fe25c Mon Sep 17 00:00:00 2001
+From: Marek Vasut <marex@denx.de>
+Date: Fri, 5 Jul 2024 08:48:52 +0100
+Subject: [PATCH] nvmem: core: Implement force_ro sysfs attribute
+
+Implement "force_ro" sysfs attribute to allow users to set read-write
+devices as read-only and back to read-write from userspace. The choice
+of the name is based on MMC core 'force_ro' attribute.
+
+This solves a situation where an AT24 I2C EEPROM with GPIO based nWP
+signal may have to be occasionally updated. Such I2C EEPROM device is
+usually set as read-only during most of the regular system operation,
+but in case it has to be updated in a controlled manner, it could be
+unlocked using this new "force_ro" sysfs attribute and then re-locked
+again.
+
+The "read-only" DT property and config->read_only configuration is
+respected and is used to set default state of the device, read-only
+or read-write, for devices which do implement .reg_write function.
+For devices which do not implement .reg_write function, the device
+is unconditionally read-only and the "force_ro" attribute is not
+visible.
+
+Signed-off-by: Marek Vasut <marex@denx.de>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240705074852.423202-16-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ Documentation/ABI/stable/sysfs-bus-nvmem | 17 ++++++++++
+ drivers/nvmem/core.c                     | 43 ++++++++++++++++++++++++
+ 2 files changed, 60 insertions(+)
+
+--- a/Documentation/ABI/stable/sysfs-bus-nvmem
++++ b/Documentation/ABI/stable/sysfs-bus-nvmem
+@@ -1,3 +1,20 @@
++What:         /sys/bus/nvmem/devices/.../force_ro
++Date:         June 2024
++KernelVersion:        6.11
++Contact:      Marek Vasut <marex@denx.de>
++Description:
++              This read/write attribute allows users to set read-write
++              devices as read-only and back to read-write from userspace.
++              This can be used to unlock and relock write-protection of
++              devices which are generally locked, except during sporadic
++              programming operation.
++              Read returns '0' or '1' for read-write or read-only modes
++              respectively.
++              Write parses one of 'YyTt1NnFf0', or [oO][NnFf] for "on"
++              and "off", i.e. what kstrbool() supports.
++              Note: This file is only present if CONFIG_NVMEM_SYSFS
++              is enabled.
++
+ What:         /sys/bus/nvmem/devices/.../nvmem
+ Date:         July 2015
+ KernelVersion:  4.2
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -184,7 +184,30 @@ static ssize_t type_show(struct device *
+ static DEVICE_ATTR_RO(type);
++static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr,
++                           char *buf)
++{
++      struct nvmem_device *nvmem = to_nvmem_device(dev);
++
++      return sysfs_emit(buf, "%d\n", nvmem->read_only);
++}
++
++static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr,
++                            const char *buf, size_t count)
++{
++      struct nvmem_device *nvmem = to_nvmem_device(dev);
++      int ret = kstrtobool(buf, &nvmem->read_only);
++
++      if (ret < 0)
++              return ret;
++
++      return count;
++}
++
++static DEVICE_ATTR_RW(force_ro);
++
+ static struct attribute *nvmem_attrs[] = {
++      &dev_attr_force_ro.attr,
+       &dev_attr_type.attr,
+       NULL,
+ };
+@@ -285,6 +308,25 @@ static umode_t nvmem_bin_attr_is_visible
+       return nvmem_bin_attr_get_umode(nvmem);
+ }
++static umode_t nvmem_attr_is_visible(struct kobject *kobj,
++                                   struct attribute *attr, int i)
++{
++      struct device *dev = kobj_to_dev(kobj);
++      struct nvmem_device *nvmem = to_nvmem_device(dev);
++
++      /*
++       * If the device has no .reg_write operation, do not allow
++       * configuration as read-write.
++       * If the device is set as read-only by configuration, it
++       * can be forced into read-write mode using the 'force_ro'
++       * attribute.
++       */
++      if (attr == &dev_attr_force_ro.attr && !nvmem->reg_write)
++              return 0;       /* Attribute not visible */
++
++      return attr->mode;
++}
++
+ static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry,
+                                           const char *id, int index);
+@@ -341,6 +383,7 @@ static const struct attribute_group nvme
+       .bin_attrs      = nvmem_bin_attributes,
+       .attrs          = nvmem_attrs,
+       .is_bin_visible = nvmem_bin_attr_is_visible,
++      .is_visible     = nvmem_attr_is_visible,
+ };
+ static const struct attribute_group *nvmem_dev_groups[] = {
diff --git a/target/linux/generic/backport-6.6/822-v6.11-0011-nvmem-u-boot-env-error-if-NVMEM-device-is-too-small.patch b/target/linux/generic/backport-6.6/822-v6.11-0011-nvmem-u-boot-env-error-if-NVMEM-device-is-too-small.patch
new file mode 100644 (file)
index 0000000..70d420f
--- /dev/null
@@ -0,0 +1,40 @@
+From 8679e8b4a1ebdb40c4429e49368d29353e07b601 Mon Sep 17 00:00:00 2001
+From: John Thomson <git@johnthomson.fastmail.com.au>
+Date: Mon, 2 Sep 2024 15:25:08 +0100
+Subject: [PATCH] nvmem: u-boot-env: error if NVMEM device is too small
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Verify data size before trying to parse it to avoid reading out of
+buffer. This could happen in case of problems at MTD level or invalid DT
+bindings.
+
+Signed-off-by: John Thomson <git@johnthomson.fastmail.com.au>
+Cc: stable <stable@kernel.org>
+Fixes: d5542923f200 ("nvmem: add driver handling U-Boot environment variables")
+[rmilecki: simplify commit description & rebase]
+Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240902142510.71096-2-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/u-boot-env.c | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+--- a/drivers/nvmem/u-boot-env.c
++++ b/drivers/nvmem/u-boot-env.c
+@@ -176,6 +176,13 @@ static int u_boot_env_parse(struct u_boo
+               data_offset = offsetof(struct u_boot_env_image_broadcom, data);
+               break;
+       }
++
++      if (dev_size < data_offset) {
++              dev_err(dev, "Device too small for u-boot-env\n");
++              err = -EIO;
++              goto err_kfree;
++      }
++
+       crc32_addr = (__le32 *)(buf + crc32_offset);
+       crc32 = le32_to_cpu(*crc32_addr);
+       crc32_data_len = dev_size - crc32_data_offset;
diff --git a/target/linux/generic/backport-6.6/822-v6.11-0012-nvmem-Fix-return-type-of-devm_nvmem_device_get-in-ke.patch b/target/linux/generic/backport-6.6/822-v6.11-0012-nvmem-Fix-return-type-of-devm_nvmem_device_get-in-ke.patch
new file mode 100644 (file)
index 0000000..6d49a25
--- /dev/null
@@ -0,0 +1,37 @@
+From c69f37f6559a8948d70badd2b179db7714dedd62 Mon Sep 17 00:00:00 2001
+From: Geert Uytterhoeven <geert+renesas@glider.be>
+Date: Mon, 2 Sep 2024 15:25:09 +0100
+Subject: [PATCH] nvmem: Fix return type of devm_nvmem_device_get() in
+ kerneldoc
+
+devm_nvmem_device_get() returns an nvmem device, not an nvmem cell.
+
+Fixes: e2a5402ec7c6d044 ("nvmem: Add nvmem_device based consumer apis.")
+Cc: stable <stable@kernel.org>
+Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20240902142510.71096-3-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -1275,13 +1275,13 @@ void nvmem_device_put(struct nvmem_devic
+ EXPORT_SYMBOL_GPL(nvmem_device_put);
+ /**
+- * devm_nvmem_device_get() - Get nvmem cell of device form a given id
++ * devm_nvmem_device_get() - Get nvmem device of device form a given id
+  *
+  * @dev: Device that requests the nvmem device.
+  * @id: name id for the requested nvmem device.
+  *
+- * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_cell
+- * on success.  The nvmem_cell will be freed by the automatically once the
++ * Return: ERR_PTR() on error or a valid pointer to a struct nvmem_device
++ * on success.  The nvmem_device will be freed by the automatically once the
+  * device is freed.
+  */
+ struct nvmem_device *devm_nvmem_device_get(struct device *dev, const char *id)
index d07447bcba8eaabe4ba6d042c9f40b41a635c529..46acd47f6342feef795502dda485b8b265e2cd7d 100644 (file)
@@ -36,7 +36,7 @@ Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
 
 --- a/drivers/nvmem/u-boot-env.c
 +++ b/drivers/nvmem/u-boot-env.c
-@@ -181,7 +181,7 @@ static int u_boot_env_parse(struct u_boo
+@@ -188,7 +188,7 @@ static int u_boot_env_parse(struct u_boo
        crc32_data_len = dev_size - crc32_data_offset;
        data_len = dev_size - data_offset;
  
index d6a471d5766f138e93e89bd02f027c5879c2e57d..29cda1824e2ed0bb392db6d1119bdc078dd3abbd 100644 (file)
@@ -33,7 +33,7 @@ string.
  #include <linux/init.h>
  #include <linux/kref.h>
  #include <linux/module.h>
-@@ -779,6 +782,62 @@ static int nvmem_validate_keepouts(struc
+@@ -797,6 +800,62 @@ static int nvmem_validate_keepouts(struc
        return 0;
  }
  
@@ -96,7 +96,7 @@ string.
  static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
  {
        struct device *dev = &nvmem->dev;
-@@ -818,6 +877,25 @@ static int nvmem_add_cells_from_dt(struc
+@@ -836,6 +895,25 @@ static int nvmem_add_cells_from_dt(struc
                if (nvmem->fixup_dt_cell_info)
                        nvmem->fixup_dt_cell_info(nvmem, &info);
  
index d07447bcba8eaabe4ba6d042c9f40b41a635c529..46acd47f6342feef795502dda485b8b265e2cd7d 100644 (file)
@@ -36,7 +36,7 @@ Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
 
 --- a/drivers/nvmem/u-boot-env.c
 +++ b/drivers/nvmem/u-boot-env.c
-@@ -181,7 +181,7 @@ static int u_boot_env_parse(struct u_boo
+@@ -188,7 +188,7 @@ static int u_boot_env_parse(struct u_boo
        crc32_data_len = dev_size - crc32_data_offset;
        data_len = dev_size - data_offset;
  
index d6a471d5766f138e93e89bd02f027c5879c2e57d..29cda1824e2ed0bb392db6d1119bdc078dd3abbd 100644 (file)
@@ -33,7 +33,7 @@ string.
  #include <linux/init.h>
  #include <linux/kref.h>
  #include <linux/module.h>
-@@ -779,6 +782,62 @@ static int nvmem_validate_keepouts(struc
+@@ -797,6 +800,62 @@ static int nvmem_validate_keepouts(struc
        return 0;
  }
  
@@ -96,7 +96,7 @@ string.
  static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
  {
        struct device *dev = &nvmem->dev;
-@@ -818,6 +877,25 @@ static int nvmem_add_cells_from_dt(struc
+@@ -836,6 +895,25 @@ static int nvmem_add_cells_from_dt(struc
                if (nvmem->fixup_dt_cell_info)
                        nvmem->fixup_dt_cell_info(nvmem, &info);
  
index d07447bcba8eaabe4ba6d042c9f40b41a635c529..46acd47f6342feef795502dda485b8b265e2cd7d 100644 (file)
@@ -36,7 +36,7 @@ Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
 
 --- a/drivers/nvmem/u-boot-env.c
 +++ b/drivers/nvmem/u-boot-env.c
-@@ -181,7 +181,7 @@ static int u_boot_env_parse(struct u_boo
+@@ -188,7 +188,7 @@ static int u_boot_env_parse(struct u_boo
        crc32_data_len = dev_size - crc32_data_offset;
        data_len = dev_size - data_offset;
  
index df724521be2df2977287101ec8f022340bfc0005..241ff77a7b4264a4f1b9f361409fbbc0c7ecf7aa 100644 (file)
@@ -33,7 +33,7 @@ string.
  #include <linux/init.h>
  #include <linux/kref.h>
  #include <linux/module.h>
-@@ -778,6 +781,62 @@ static int nvmem_validate_keepouts(struc
+@@ -796,6 +799,62 @@ static int nvmem_validate_keepouts(struc
        return 0;
  }
  
@@ -96,7 +96,7 @@ string.
  static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
  {
        struct device *dev = &nvmem->dev;
-@@ -817,6 +876,25 @@ static int nvmem_add_cells_from_dt(struc
+@@ -835,6 +894,25 @@ static int nvmem_add_cells_from_dt(struc
                if (nvmem->fixup_dt_cell_info)
                        nvmem->fixup_dt_cell_info(nvmem, &info);