kernel: backport NVMEM late fixes from v6.2
authorRafał Miłecki <rafal@milecki.pl>
Thu, 23 Feb 2023 08:47:39 +0000 (09:47 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Thu, 23 Feb 2023 08:50:01 +0000 (09:50 +0100)
They were backported to stable kernels but we backport more stuff on our
own so we have to pick up few remaining.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
target/linux/bcm53xx/patches-5.10/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch
target/linux/bcm53xx/patches-5.15/800-0002-nvmem-brcm_nvram-provide-NVMEM-content-to-the-NVRAM-.patch
target/linux/generic/backport-5.10/812-v6.2-0007-nvmem-brcm_nvram-Add-check-for-kzalloc.patch [new file with mode: 0644]
target/linux/generic/backport-5.10/812-v6.2-0008-nvmem-sunxi_sid-Always-use-32-bit-MMIO-reads.patch [new file with mode: 0644]
target/linux/generic/backport-5.10/812-v6.2-0013-nvmem-core-fix-device-node-refcounting.patch [new file with mode: 0644]
target/linux/generic/backport-5.10/813-v6.3-0002-nvmem-core-add-an-index-parameter-to-the-cell.patch
target/linux/generic/backport-5.15/808-v6.2-0007-nvmem-brcm_nvram-Add-check-for-kzalloc.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/808-v6.2-0008-nvmem-sunxi_sid-Always-use-32-bit-MMIO-reads.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/808-v6.2-0013-nvmem-core-fix-device-node-refcounting.patch [new file with mode: 0644]
target/linux/generic/backport-5.15/809-v6.3-0002-nvmem-core-add-an-index-parameter-to-the-cell.patch

index ecc5f3974ea51232ae3853239f5ea7e559a14224..6648874bcff0040ceffa8ea1b10de22b5a98df0b 100644 (file)
@@ -20,7 +20,7 @@ Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  #include <linux/io.h>
  #include <linux/mod_devicetable.h>
  #include <linux/module.h>
-@@ -136,6 +137,8 @@ static int brcm_nvram_probe(struct platf
+@@ -139,6 +140,8 @@ static int brcm_nvram_probe(struct platf
        if (err)
                return err;
  
index ecc5f3974ea51232ae3853239f5ea7e559a14224..6648874bcff0040ceffa8ea1b10de22b5a98df0b 100644 (file)
@@ -20,7 +20,7 @@ Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  #include <linux/io.h>
  #include <linux/mod_devicetable.h>
  #include <linux/module.h>
-@@ -136,6 +137,8 @@ static int brcm_nvram_probe(struct platf
+@@ -139,6 +140,8 @@ static int brcm_nvram_probe(struct platf
        if (err)
                return err;
  
diff --git a/target/linux/generic/backport-5.10/812-v6.2-0007-nvmem-brcm_nvram-Add-check-for-kzalloc.patch b/target/linux/generic/backport-5.10/812-v6.2-0007-nvmem-brcm_nvram-Add-check-for-kzalloc.patch
new file mode 100644 (file)
index 0000000..14108b5
--- /dev/null
@@ -0,0 +1,30 @@
+From b0576ade3aaf24b376ea1a4406ae138e2a22b0c0 Mon Sep 17 00:00:00 2001
+From: Jiasheng Jiang <jiasheng@iscas.ac.cn>
+Date: Fri, 27 Jan 2023 10:40:06 +0000
+Subject: [PATCH] nvmem: brcm_nvram: Add check for kzalloc
+
+Add the check for the return value of kzalloc in order to avoid
+NULL pointer dereference.
+
+Fixes: 6e977eaa8280 ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells")
+Cc: stable@vger.kernel.org
+Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20230127104015.23839-2-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/brcm_nvram.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+--- a/drivers/nvmem/brcm_nvram.c
++++ b/drivers/nvmem/brcm_nvram.c
+@@ -97,6 +97,9 @@ static int brcm_nvram_parse(struct brcm_
+       len = le32_to_cpu(header.len);
+       data = kzalloc(len, GFP_KERNEL);
++      if (!data)
++              return -ENOMEM;
++
+       memcpy_fromio(data, priv->base, len);
+       data[len - 1] = '\0';
diff --git a/target/linux/generic/backport-5.10/812-v6.2-0008-nvmem-sunxi_sid-Always-use-32-bit-MMIO-reads.patch b/target/linux/generic/backport-5.10/812-v6.2-0008-nvmem-sunxi_sid-Always-use-32-bit-MMIO-reads.patch
new file mode 100644 (file)
index 0000000..632b01c
--- /dev/null
@@ -0,0 +1,55 @@
+From c151d5ed8e8fe0474bd61dce7f2076ca5916c683 Mon Sep 17 00:00:00 2001
+From: Samuel Holland <samuel@sholland.org>
+Date: Fri, 27 Jan 2023 10:40:07 +0000
+Subject: [PATCH] nvmem: sunxi_sid: Always use 32-bit MMIO reads
+
+The SID SRAM on at least some SoCs (A64 and D1) returns different values
+when read with bus cycles narrower than 32 bits. This is not immediately
+obvious, because memcpy_fromio() uses word-size accesses as long as
+enough data is being copied.
+
+The vendor driver always uses 32-bit MMIO reads, so do the same here.
+This is faster than the register-based method, which is currently used
+as a workaround on A64. And it fixes the values returned on D1, where
+the SRAM method was being used.
+
+The special case for the last word is needed to maintain .word_size == 1
+for sysfs ABI compatibility, as noted previously in commit de2a3eaea552
+("nvmem: sunxi_sid: Optimize register read-out method").
+
+Fixes: 07ae4fde9efa ("nvmem: sunxi_sid: Add support for D1 variant")
+Cc: stable@vger.kernel.org
+Tested-by: Heiko Stuebner <heiko@sntech.de>
+Signed-off-by: Samuel Holland <samuel@sholland.org>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20230127104015.23839-3-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/sunxi_sid.c | 15 ++++++++++++++-
+ 1 file changed, 14 insertions(+), 1 deletion(-)
+
+--- a/drivers/nvmem/sunxi_sid.c
++++ b/drivers/nvmem/sunxi_sid.c
+@@ -41,8 +41,21 @@ static int sunxi_sid_read(void *context,
+                         void *val, size_t bytes)
+ {
+       struct sunxi_sid *sid = context;
++      u32 word;
+-      memcpy_fromio(val, sid->base + sid->value_offset + offset, bytes);
++      /* .stride = 4 so offset is guaranteed to be aligned */
++      __ioread32_copy(val, sid->base + sid->value_offset + offset, bytes / 4);
++
++      val += round_down(bytes, 4);
++      offset += round_down(bytes, 4);
++      bytes = bytes % 4;
++
++      if (!bytes)
++              return 0;
++
++      /* Handle any trailing bytes */
++      word = readl_relaxed(sid->base + sid->value_offset + offset);
++      memcpy(val, &word, bytes);
+       return 0;
+ }
diff --git a/target/linux/generic/backport-5.10/812-v6.2-0013-nvmem-core-fix-device-node-refcounting.patch b/target/linux/generic/backport-5.10/812-v6.2-0013-nvmem-core-fix-device-node-refcounting.patch
new file mode 100644 (file)
index 0000000..53a8fed
--- /dev/null
@@ -0,0 +1,48 @@
+From edcf2fb660526b5ed29f93bd17328a2b4835c8b2 Mon Sep 17 00:00:00 2001
+From: Michael Walle <michael@walle.cc>
+Date: Fri, 27 Jan 2023 10:40:12 +0000
+Subject: [PATCH] nvmem: core: fix device node refcounting
+
+In of_nvmem_cell_get(), of_get_next_parent() is used on cell_np. This
+will decrement the refcount on cell_np, but cell_np is still used later
+in the code. Use of_get_parent() instead and of_node_put() in the
+appropriate places.
+
+Fixes: 69aba7948cbe ("nvmem: Add a simple NVMEM framework for consumers")
+Fixes: 7ae6478b304b ("nvmem: core: rework nvmem cell instance creation")
+Cc: stable@vger.kernel.org
+Signed-off-by: Michael Walle <michael@walle.cc>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20230127104015.23839-8-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 11 ++++++++---
+ 1 file changed, 8 insertions(+), 3 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -1242,16 +1242,21 @@ struct nvmem_cell *of_nvmem_cell_get(str
+       if (!cell_np)
+               return ERR_PTR(-ENOENT);
+-      nvmem_np = of_get_next_parent(cell_np);
+-      if (!nvmem_np)
++      nvmem_np = of_get_parent(cell_np);
++      if (!nvmem_np) {
++              of_node_put(cell_np);
+               return ERR_PTR(-EINVAL);
++      }
+       nvmem = __nvmem_device_get(nvmem_np, device_match_of_node);
+       of_node_put(nvmem_np);
+-      if (IS_ERR(nvmem))
++      if (IS_ERR(nvmem)) {
++              of_node_put(cell_np);
+               return ERR_CAST(nvmem);
++      }
+       cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np);
++      of_node_put(cell_np);
+       if (!cell_entry) {
+               __nvmem_device_put(nvmem);
+               return ERR_PTR(-ENOENT);
index 4f1bfac806c9088eb72da589a96bf44a81d8569d..b51208559845442a35b9e0ee3aa6acf2ee1c754b 100644 (file)
@@ -103,9 +103,9 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
 +      if (cell_spec.args_count)
 +              cell_index = cell_spec.args[0];
  
-       nvmem_np = of_get_next_parent(cell_np);
-       if (!nvmem_np)
-@@ -1257,7 +1272,7 @@ struct nvmem_cell *of_nvmem_cell_get(str
+       nvmem_np = of_get_parent(cell_np);
+       if (!nvmem_np) {
+@@ -1262,7 +1277,7 @@ struct nvmem_cell *of_nvmem_cell_get(str
                return ERR_PTR(-ENOENT);
        }
  
@@ -114,7 +114,7 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
        if (IS_ERR(cell))
                __nvmem_device_put(nvmem);
  
-@@ -1410,8 +1425,8 @@ static void nvmem_shift_read_buffer_in_p
+@@ -1415,8 +1430,8 @@ static void nvmem_shift_read_buffer_in_p
  }
  
  static int __nvmem_cell_read(struct nvmem_device *nvmem,
@@ -125,7 +125,7 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  {
        int rc;
  
-@@ -1425,7 +1440,7 @@ static int __nvmem_cell_read(struct nvme
+@@ -1430,7 +1445,7 @@ static int __nvmem_cell_read(struct nvme
                nvmem_shift_read_buffer_in_place(cell, buf);
  
        if (nvmem->cell_post_process) {
@@ -134,7 +134,7 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
                                              cell->offset, buf, cell->bytes);
                if (rc)
                        return rc;
-@@ -1460,7 +1475,7 @@ void *nvmem_cell_read(struct nvmem_cell
+@@ -1465,7 +1480,7 @@ void *nvmem_cell_read(struct nvmem_cell
        if (!buf)
                return ERR_PTR(-ENOMEM);
  
@@ -143,7 +143,7 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
        if (rc) {
                kfree(buf);
                return ERR_PTR(rc);
-@@ -1773,7 +1788,7 @@ ssize_t nvmem_device_cell_read(struct nv
+@@ -1778,7 +1793,7 @@ ssize_t nvmem_device_cell_read(struct nv
        if (rc)
                return rc;
  
diff --git a/target/linux/generic/backport-5.15/808-v6.2-0007-nvmem-brcm_nvram-Add-check-for-kzalloc.patch b/target/linux/generic/backport-5.15/808-v6.2-0007-nvmem-brcm_nvram-Add-check-for-kzalloc.patch
new file mode 100644 (file)
index 0000000..14108b5
--- /dev/null
@@ -0,0 +1,30 @@
+From b0576ade3aaf24b376ea1a4406ae138e2a22b0c0 Mon Sep 17 00:00:00 2001
+From: Jiasheng Jiang <jiasheng@iscas.ac.cn>
+Date: Fri, 27 Jan 2023 10:40:06 +0000
+Subject: [PATCH] nvmem: brcm_nvram: Add check for kzalloc
+
+Add the check for the return value of kzalloc in order to avoid
+NULL pointer dereference.
+
+Fixes: 6e977eaa8280 ("nvmem: brcm_nvram: parse NVRAM content into NVMEM cells")
+Cc: stable@vger.kernel.org
+Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20230127104015.23839-2-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/brcm_nvram.c | 3 +++
+ 1 file changed, 3 insertions(+)
+
+--- a/drivers/nvmem/brcm_nvram.c
++++ b/drivers/nvmem/brcm_nvram.c
+@@ -97,6 +97,9 @@ static int brcm_nvram_parse(struct brcm_
+       len = le32_to_cpu(header.len);
+       data = kzalloc(len, GFP_KERNEL);
++      if (!data)
++              return -ENOMEM;
++
+       memcpy_fromio(data, priv->base, len);
+       data[len - 1] = '\0';
diff --git a/target/linux/generic/backport-5.15/808-v6.2-0008-nvmem-sunxi_sid-Always-use-32-bit-MMIO-reads.patch b/target/linux/generic/backport-5.15/808-v6.2-0008-nvmem-sunxi_sid-Always-use-32-bit-MMIO-reads.patch
new file mode 100644 (file)
index 0000000..632b01c
--- /dev/null
@@ -0,0 +1,55 @@
+From c151d5ed8e8fe0474bd61dce7f2076ca5916c683 Mon Sep 17 00:00:00 2001
+From: Samuel Holland <samuel@sholland.org>
+Date: Fri, 27 Jan 2023 10:40:07 +0000
+Subject: [PATCH] nvmem: sunxi_sid: Always use 32-bit MMIO reads
+
+The SID SRAM on at least some SoCs (A64 and D1) returns different values
+when read with bus cycles narrower than 32 bits. This is not immediately
+obvious, because memcpy_fromio() uses word-size accesses as long as
+enough data is being copied.
+
+The vendor driver always uses 32-bit MMIO reads, so do the same here.
+This is faster than the register-based method, which is currently used
+as a workaround on A64. And it fixes the values returned on D1, where
+the SRAM method was being used.
+
+The special case for the last word is needed to maintain .word_size == 1
+for sysfs ABI compatibility, as noted previously in commit de2a3eaea552
+("nvmem: sunxi_sid: Optimize register read-out method").
+
+Fixes: 07ae4fde9efa ("nvmem: sunxi_sid: Add support for D1 variant")
+Cc: stable@vger.kernel.org
+Tested-by: Heiko Stuebner <heiko@sntech.de>
+Signed-off-by: Samuel Holland <samuel@sholland.org>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20230127104015.23839-3-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/sunxi_sid.c | 15 ++++++++++++++-
+ 1 file changed, 14 insertions(+), 1 deletion(-)
+
+--- a/drivers/nvmem/sunxi_sid.c
++++ b/drivers/nvmem/sunxi_sid.c
+@@ -41,8 +41,21 @@ static int sunxi_sid_read(void *context,
+                         void *val, size_t bytes)
+ {
+       struct sunxi_sid *sid = context;
++      u32 word;
+-      memcpy_fromio(val, sid->base + sid->value_offset + offset, bytes);
++      /* .stride = 4 so offset is guaranteed to be aligned */
++      __ioread32_copy(val, sid->base + sid->value_offset + offset, bytes / 4);
++
++      val += round_down(bytes, 4);
++      offset += round_down(bytes, 4);
++      bytes = bytes % 4;
++
++      if (!bytes)
++              return 0;
++
++      /* Handle any trailing bytes */
++      word = readl_relaxed(sid->base + sid->value_offset + offset);
++      memcpy(val, &word, bytes);
+       return 0;
+ }
diff --git a/target/linux/generic/backport-5.15/808-v6.2-0013-nvmem-core-fix-device-node-refcounting.patch b/target/linux/generic/backport-5.15/808-v6.2-0013-nvmem-core-fix-device-node-refcounting.patch
new file mode 100644 (file)
index 0000000..99a9907
--- /dev/null
@@ -0,0 +1,48 @@
+From edcf2fb660526b5ed29f93bd17328a2b4835c8b2 Mon Sep 17 00:00:00 2001
+From: Michael Walle <michael@walle.cc>
+Date: Fri, 27 Jan 2023 10:40:12 +0000
+Subject: [PATCH] nvmem: core: fix device node refcounting
+
+In of_nvmem_cell_get(), of_get_next_parent() is used on cell_np. This
+will decrement the refcount on cell_np, but cell_np is still used later
+in the code. Use of_get_parent() instead and of_node_put() in the
+appropriate places.
+
+Fixes: 69aba7948cbe ("nvmem: Add a simple NVMEM framework for consumers")
+Fixes: 7ae6478b304b ("nvmem: core: rework nvmem cell instance creation")
+Cc: stable@vger.kernel.org
+Signed-off-by: Michael Walle <michael@walle.cc>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20230127104015.23839-8-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/core.c | 11 ++++++++---
+ 1 file changed, 8 insertions(+), 3 deletions(-)
+
+--- a/drivers/nvmem/core.c
++++ b/drivers/nvmem/core.c
+@@ -1240,16 +1240,21 @@ struct nvmem_cell *of_nvmem_cell_get(str
+       if (!cell_np)
+               return ERR_PTR(-ENOENT);
+-      nvmem_np = of_get_next_parent(cell_np);
+-      if (!nvmem_np)
++      nvmem_np = of_get_parent(cell_np);
++      if (!nvmem_np) {
++              of_node_put(cell_np);
+               return ERR_PTR(-EINVAL);
++      }
+       nvmem = __nvmem_device_get(nvmem_np, device_match_of_node);
+       of_node_put(nvmem_np);
+-      if (IS_ERR(nvmem))
++      if (IS_ERR(nvmem)) {
++              of_node_put(cell_np);
+               return ERR_CAST(nvmem);
++      }
+       cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np);
++      of_node_put(cell_np);
+       if (!cell_entry) {
+               __nvmem_device_put(nvmem);
+               return ERR_PTR(-ENOENT);
index d6b3057e48d07a265e4b6967a15b51d8e069b597..cefc4c89c7cd547b419e3666cdb0aa83d1b2fe85 100644 (file)
@@ -103,9 +103,9 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
 +      if (cell_spec.args_count)
 +              cell_index = cell_spec.args[0];
  
-       nvmem_np = of_get_next_parent(cell_np);
-       if (!nvmem_np)
-@@ -1255,7 +1270,7 @@ struct nvmem_cell *of_nvmem_cell_get(str
+       nvmem_np = of_get_parent(cell_np);
+       if (!nvmem_np) {
+@@ -1260,7 +1275,7 @@ struct nvmem_cell *of_nvmem_cell_get(str
                return ERR_PTR(-ENOENT);
        }
  
@@ -114,7 +114,7 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
        if (IS_ERR(cell))
                __nvmem_device_put(nvmem);
  
-@@ -1408,8 +1423,8 @@ static void nvmem_shift_read_buffer_in_p
+@@ -1413,8 +1428,8 @@ static void nvmem_shift_read_buffer_in_p
  }
  
  static int __nvmem_cell_read(struct nvmem_device *nvmem,
@@ -125,7 +125,7 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  {
        int rc;
  
-@@ -1423,7 +1438,7 @@ static int __nvmem_cell_read(struct nvme
+@@ -1428,7 +1443,7 @@ static int __nvmem_cell_read(struct nvme
                nvmem_shift_read_buffer_in_place(cell, buf);
  
        if (nvmem->cell_post_process) {
@@ -134,7 +134,7 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
                                              cell->offset, buf, cell->bytes);
                if (rc)
                        return rc;
-@@ -1458,7 +1473,7 @@ void *nvmem_cell_read(struct nvmem_cell
+@@ -1463,7 +1478,7 @@ void *nvmem_cell_read(struct nvmem_cell
        if (!buf)
                return ERR_PTR(-ENOMEM);
  
@@ -143,7 +143,7 @@ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
        if (rc) {
                kfree(buf);
                return ERR_PTR(rc);
-@@ -1771,7 +1786,7 @@ ssize_t nvmem_device_cell_read(struct nv
+@@ -1776,7 +1791,7 @@ ssize_t nvmem_device_cell_read(struct nv
        if (rc)
                return rc;