bcm53xx: backport brcm_nvram changes needed for fix patch
authorRafał Miłecki <rafal@milecki.pl>
Thu, 18 Jan 2024 09:26:36 +0000 (10:26 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Thu, 18 Jan 2024 15:49:13 +0000 (16:49 +0100)
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
target/linux/bcm53xx/patches-5.10/083-v6.1-nvmem-brcm_nvram-Use-kzalloc-for-allocating-only-one.patch [new file with mode: 0644]
target/linux/bcm53xx/patches-5.10/084-v6.2-0002-nvmem-brcm_nvram-Add-check-for-kzalloc.patch [new file with mode: 0644]
target/linux/bcm53xx/patches-5.10/086-v6.6-nvmem-brcm_nvram-Use-devm_platform_get_and_ioremap_r.patch [new file with mode: 0644]

diff --git a/target/linux/bcm53xx/patches-5.10/083-v6.1-nvmem-brcm_nvram-Use-kzalloc-for-allocating-only-one.patch b/target/linux/bcm53xx/patches-5.10/083-v6.1-nvmem-brcm_nvram-Use-kzalloc-for-allocating-only-one.patch
new file mode 100644 (file)
index 0000000..48ad63f
--- /dev/null
@@ -0,0 +1,29 @@
+From d3524bb5b9a0c567b853a0024526afe87dde01ed Mon Sep 17 00:00:00 2001
+From: Kenneth Lee <klee33@uw.edu>
+Date: Fri, 16 Sep 2022 13:20:52 +0100
+Subject: [PATCH] nvmem: brcm_nvram: Use kzalloc for allocating only one
+ element
+
+Use kzalloc(...) rather than kcalloc(1, ...) because the number of
+elements we are specifying in this case is 1, so kzalloc would
+accomplish the same thing and we can simplify.
+
+Signed-off-by: Kenneth Lee <klee33@uw.edu>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20220916122100.170016-6-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/brcm_nvram.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+--- a/drivers/nvmem/brcm_nvram.c
++++ b/drivers/nvmem/brcm_nvram.c
+@@ -96,7 +96,7 @@ static int brcm_nvram_parse(struct brcm_
+       len = le32_to_cpu(header.len);
+-      data = kcalloc(1, len, GFP_KERNEL);
++      data = kzalloc(len, GFP_KERNEL);
+       memcpy_fromio(data, priv->base, len);
+       data[len - 1] = '\0';
diff --git a/target/linux/bcm53xx/patches-5.10/084-v6.2-0002-nvmem-brcm_nvram-Add-check-for-kzalloc.patch b/target/linux/bcm53xx/patches-5.10/084-v6.2-0002-nvmem-brcm_nvram-Add-check-for-kzalloc.patch
new file mode 100644 (file)
index 0000000..c37f8ff
--- /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
+@@ -98,6 +98,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/bcm53xx/patches-5.10/086-v6.6-nvmem-brcm_nvram-Use-devm_platform_get_and_ioremap_r.patch b/target/linux/bcm53xx/patches-5.10/086-v6.6-nvmem-brcm_nvram-Use-devm_platform_get_and_ioremap_r.patch
new file mode 100644 (file)
index 0000000..6945038
--- /dev/null
@@ -0,0 +1,30 @@
+From cfadd0e7d9225566f320bc4dc716682be910be6c Mon Sep 17 00:00:00 2001
+From: Yangtao Li <frank.li@vivo.com>
+Date: Wed, 23 Aug 2023 14:27:25 +0100
+Subject: [PATCH] nvmem: brcm_nvram: Use
+ devm_platform_get_and_ioremap_resource()
+
+Convert platform_get_resource(), devm_ioremap_resource() to a single
+call to devm_platform_get_and_ioremap_resource(), as this is exactly
+what this function does.
+
+Signed-off-by: Yangtao Li <frank.li@vivo.com>
+Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
+Link: https://lore.kernel.org/r/20230823132744.350618-4-srinivas.kandagatla@linaro.org
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/nvmem/brcm_nvram.c | 3 +--
+ 1 file changed, 1 insertion(+), 2 deletions(-)
+
+--- a/drivers/nvmem/brcm_nvram.c
++++ b/drivers/nvmem/brcm_nvram.c
+@@ -131,8 +131,7 @@ static int brcm_nvram_probe(struct platf
+               return -ENOMEM;
+       priv->dev = dev;
+-      res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+-      priv->base = devm_ioremap_resource(dev, res);
++      priv->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+       if (IS_ERR(priv->base))
+               return PTR_ERR(priv->base);