Skip to contentSkip to conversation

ARM: dts: BCM5301X: AC56U: add nvram node

PATCH Superseded Rosen Penev 3 participants 5 messages Sep 10 – Sep 11

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ARM: dts: BCM5301X: AC56U: add nvram node

Add it and set for gmac0, which is the only GMAC used on this board.

nvram size found from a random bootlog online.

---
v2: fix typo.

 .../boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts    | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/arm/boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts +14 -0
index c80ac16ad949..9ab618a097b1 100644
@@ -25,6 +25,15 @@ memory@0 {
 		      <0x88000000 0x08000000>;
 	};
 
+	nvram@1c080000 {
+		compatible = "brcm,nvram";
+		reg = <0x1c080000 0x180000>;
+
+		et0macaddr: et0macaddr {
+			#nvmem-cell-cells = <1>;
+		};
+	};
+
 	leds {
 		compatible = "gpio-leds";
 
@@ -92,3 +101,8 @@ button-wps {
 &usb3_phy {
 	status = "okay";
 };
+
+&gmac0 {
+	nvmem-cells = <&et0macaddr 0>;
+	nvmem-cell-names = "mac-address";
+};
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Zero-size allocation leads to a kernel panic if NVRAM is completely empty or uninitialized. --

commit 3e511df55083f5f3829311b665dd624ff8599e95
Author: Rosen Penev <[email protected]>

ARM: dts: BCM5301X: AC56U: add nvram node

This commit adds the brcm,nvram node to the bcm4708-asus-rt-ac56u device tree. It configures it for gmac0, which is the only GMAC used on this board, and sets the size based on a bootlog.

Quoted 7 lines
arch/arm/boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts +0 -0
index c80ac16ad9496..9ab618a097b1f 100644
@@ -25,6 +25,15 @@ memory@0 {
 		      <0x88000000 0x08000000>;
 	};

arch/arm/boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts memory@0 { · line 36

Quoted 10 lines
arch/arm/boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts +9 -0
 
+	nvram@1c080000 {
+		compatible = "brcm,nvram";
+		reg = <0x1c080000 0x180000>;
+
+		et0macaddr: et0macaddr {
+			#nvmem-cell-cells = <1>;
+		};
+	};
+

[Severity: High]
This isn't a bug introduced by this patch, but enabling the brcm,nvram node exposes a potential kernel panic in the nvmem driver if the NVRAM is completely empty or uninitialized.

In drivers/nvmem/brcm_nvram.c:brcm_nvram_copy_data(), if the flash partition consists only of padding bytes (e.g., after an erase), the scanning loop decrements priv->data_len to 0:

	for (priv->data_len = priv->nvmem_size;
	     priv->data_len;
	     priv->data_len--) {
		if (readb(base + priv->data_len - 1) != priv->padding_byte)
			break;
	}

This results in a zero-byte allocation:

	priv->data = devm_kzalloc(priv->dev, priv->data_len, GFP_KERNEL);

If priv->data_len is 0, devm_kzalloc() returns ZERO_SIZE_PTR (0x10) rather than NULL, so execution continues successfully to brcm_nvram_parse().

The driver then attempts to read the header:

	struct brcm_nvram_header *header = (struct brcm_nvram_header *)priv->data;
	...
	if (memcmp(header->magic, NVRAM_MAGIC, 4)) {

This dereferences ZERO_SIZE_PTR (0x10), which causes a page fault and kernel panic on devices with erased NVRAM.

Could a check be added for priv->data_len == 0 in the nvmem driver to prevent this unrecoverable boot failure before enabling the node in the device tree?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Rosen Penev
Quoted 15 lines · Rosen Penev

Add it and set for gmac0, which is the only GMAC used on this board.

nvram size found from a random bootlog online.

---
v2: fix typo.

  .../boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts    | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
arch/arm/boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts +0 -0
index c80ac16ad949..9ab618a097b1 100644

arch/arm/boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts memory@0 { · line 30

Quoted 6 lines
arch/arm/boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts +3 -0
@@ -25,6 +25,15 @@ memory@0 {
  		      <0x88000000 0x08000000>;
  	};
 
+	nvram@1c080000 {
+		compatible = "brcm,nvram";
+		reg = <0x1c080000 0x180000>;

Why is not the nvram node moved to bcm5301x.dtsi given it is common to all of the chips? --
Florian

#3 lore raw
Quoted 20 lines · Florian Fainelli
Quoted 18 lines · Rosen Penev

Add it and set for gmac0, which is the only GMAC used on this board.

nvram size found from a random bootlog online.

---
v2: fix typo.

  .../boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts    | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
arch/arm/boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts +0 -0
index c80ac16ad949..9ab618a097b1 100644
@@ -25,6 +25,15 @@ memory@0 {
                    <0x88000000 0x08000000>;
      };
 
Quoted 6 lines

arch/arm/boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts memory@0 { · line 30

Quoted 3 lines
arch/arm/boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts +3 -0
+     nvram@1c080000 {
+             compatible = "brcm,nvram";
+             reg = <0x1c080000 0x180000>;

Why is not the nvram node moved to bcm5301x.dtsi given it is common to all of the chips?

To avoid probe errors on hardware where sizes are unknown.

Quoted 2 lines

--
Florian

#4 lore raw
Quoted 23 lines · Rosen Penev
Quoted 20 lines · Florian Fainelli
Quoted 18 lines · Rosen Penev

Add it and set for gmac0, which is the only GMAC used on this board.

nvram size found from a random bootlog online.

---
v2: fix typo.

  .../boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts    | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
arch/arm/boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts +0 -0
index c80ac16ad949..9ab618a097b1 100644
@@ -25,6 +25,15 @@ memory@0 {
                    <0x88000000 0x08000000>;
      };
 
Quoted 7 lines
Quoted 6 lines

arch/arm/boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts memory@0 { · line 30

Quoted 3 lines
arch/arm/boot/dts/broadcom/bcm4708-asus-rt-ac56u.dts +3 -0
+     nvram@1c080000 {
+             compatible = "brcm,nvram";
+             reg = <0x1c080000 0x180000>;

Why is not the nvram node moved to bcm5301x.dtsi given it is common to all of the chips?

To avoid probe errors on hardware where sizes are unknown.

I looked at this again. It makes no sense to centralize:

+ nvram@1c080000 {
+ compatible = "brcm,nvram";
+ reg = <0x1c080000 0x180000>;

The reg and @ values are correct here but not for all devices. There's also nvram@1e3f0000 and nvram@1e1f0000 as examples.

Quoted 2 lines
Quoted 2 lines

--
Florian