* [PATCH v5 0/5] nvmem: add Qualcomm eFuse Ethernet MAC address layout driver
@ 2026-12-04 6:22 Hongmei Xu
2026-12-04 6:22 ` [PATCH v5 1/5] dt-bindings: nvmem: layouts: add Qualcomm eFuse Ethernet MAC layout Hongmei Xu
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Hongmei Xu @ 2026-12-04 6:22 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki
Cc: devicetree, linux-kernel, Hongmei Xu
Qualcomm QFPROM stores Ethernet MAC address bytes contiguously, but a
given MAC address may be formed by selecting a non-consecutive subset
of bytes from a larger eFuse span — for example, bytes 0–4 and 6 of a
7-byte region, skipping byte 5 which belongs to a different MAC.
This series adds an nvmem layout driver (qcom,efuse-eth-mac) to handle
this. Each cell node in the device tree specifies its physical eFuse
offset via reg, and an optional byte-mask property selects which bytes
within the span contribute to the 6-byte output MAC address. Selected
bytes are compacted in ascending bit-index order; unset positions are
zero-filled. Without byte-mask the cell is read as a plain contiguous
6-byte block.
An example: assume a MAC address is assembled from efuse registers
0xFFFF4320[31:0] (bytes 0-3), 0xFFFF4324[7:0] (byte 4), and
0xFFFF4324[23:16] (byte 6), with 0xFFFF4324[15:8] unused (byte 5).
Map the efuse region as an 8-byte nvmem device and define the cell
skipping byte 5:
efuse: efuse@ffff4320 {
compatible = "qcom,nord-qfprom", "qcom,qfprom";
reg = <0x0 0xffff4320 0x0 0x8>;
#address-cells = <1>;
#size-cells = <1>;
nvmem-layout {
compatible = "qcom,efuse-eth-mac";
#address-cells = <1>;
#size-cells = <1>;
eth0_mac: eth0-mac@0 {
reg = <0x0 0x7>;
byte-mask = <0x5f>;
};
};
};
ethernet0: ethernet@1a00000 {
nvmem-cells = <ð0_mac>;
nvmem-cell-names = "mac-address";
}
With byte-mask = 0x5f (0101_1111), bytes 0-4 and 6 are selected
(byte 5 is skipped), forming the 6-byte MAC address output.
Patches:
1/5 dt-bindings: document the qcom,efuse-eth-mac nvmem layout
2/5 nvmem: layouts: add the Qualcomm eFuse Ethernet MAC layout driver
3/5 MAINTAINERS: add entry for the new driver and binding
4/5 arm64: defconfig: enable NVMEM_LAYOUT_QCOM_ETH_MAC
5/5 arm64: dts: qcom: add eFuse nvmem cells for Ethernet MAC addresses
Signed-off-by: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
---
Changes in v5:
- Moved byte-mask handling out of the nvmem core and into a standalone
nvmem layout driver (qcom,efuse-eth-mac) instead.
- Dropped the nvmem core byte-mask patches; the layout driver is
self-contained and requires no core changes.
- Updated dt-binding to describe the layout node and its properties.
- Link to v4: https://patch.msgid.link/20261202-nvmem-byte-mask-for-split-macaddr-v4-0-039f1b0afeca@oss.qualcomm.com
Changes in v4:
- Add nvmem-layout eFuse node in Nord dtsi to expose EMAC0/EMAC1
MAC address cells using the new byte-mask property
- Update cover letter usage example to use nvmem-layout style
- Link to v3: https://patch.msgid.link/20261117-nvmem-byte-mask-for-split-macaddr-v3-0-c02177658f66@oss.qualcomm.com
Changes in v3:
- Align cell->raw_len to word_size in byte-mask branch to avoid false
unaligned error log
- Remove redundant nvmem_validate_byte_mask() call from
nvmem_add_cells_from_dt(); validation already happens inside
nvmem_cell_info_to_nvmem_cell_entry_nodup()
- Fix DT binding commit message: remove misleading "multiple reg
entries" comparison
- Update cover letter description for bits property limitation
- Link to v2: https://patch.msgid.link/20261116-nvmem-byte-mask-for-split-macaddr-v2-0-96f4a0c08264@oss.qualcomm.com
Changes in v2:
- Move nvmem_validate_byte_mask() before the nbits block so byte_mask+nbits
is rejected even when nbits is set (mutual exclusion bypass fix).
- Run nvmem_validate_byte_mask() after fixup_dt_cell_info() in the DT path
so the provider callback can adjust cell info before validation.
- Set cell->raw_len = fls(byte_mask) instead of nvmem->size - cell->offset,
limiting the physical read to only the bytes needed; avoids large
allocations and read failures on providers with protected trailing regions
(e.g. sec-qfprom).
- Tighten the device-size check to ALIGN(fls(byte_mask), word_size) so
word-alignment cannot push the read past the device end.
- Zero-fill output bytes beyond the last selected byte with memset.
- Simplify compaction loop guard from i < raw_len && i < 32 to i < raw_len
since raw_len is now bounded by fls(byte_mask) <= 32.
- Link to v1: https://patch.msgid.link/20261113-nvmem-byte-mask-for-split-macaddr-v1-0-138f715f18c1@oss.qualcomm.com
---
Hongmei Xu (5):
dt-bindings: nvmem: layouts: add Qualcomm eFuse Ethernet MAC layout
nvmem: layouts: add Qualcomm eFuse Ethernet MAC address layout driver
MAINTAINERS: add entry for Qualcomm Ethernet MAC nvmem layout driver
arm64: defconfig: enable NVMEM_LAYOUT_QCOM_ETH_MAC
arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses
.../bindings/nvmem/layouts/qcom,efuse-eth-mac.yaml | 87 +++++++++
.../devicetree/bindings/nvmem/qcom,qfprom.yaml | 1 +
MAINTAINERS | 6 +
arch/arm64/boot/dts/qcom/nord.dtsi | 20 ++
arch/arm64/configs/defconfig | 1 +
drivers/nvmem/layouts/Kconfig | 11 ++
drivers/nvmem/layouts/Makefile | 1 +
drivers/nvmem/layouts/qcom-eth-mac.c | 203 +++++++++++++++++++++
8 files changed, 330 insertions(+)
---
base-commit: d26955e57475434b59d43ba372b2a50d33d5e0ed
change-id: 20261110-nvmem-byte-mask-for-split-macaddr-a4698a128057
Best regards,
--
Hongmei Xu <hongmei.xu@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v5 1/5] dt-bindings: nvmem: layouts: add Qualcomm eFuse Ethernet MAC layout
2026-12-04 6:22 [PATCH v5 0/5] nvmem: add Qualcomm eFuse Ethernet MAC address layout driver Hongmei Xu
@ 2026-12-04 6:22 ` Hongmei Xu
2026-12-04 6:40 ` sashiko-bot
2026-12-04 6:22 ` [PATCH v5 2/5] nvmem: layouts: add Qualcomm eFuse Ethernet MAC address layout driver Hongmei Xu
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Hongmei Xu @ 2026-12-04 6:22 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki
Cc: devicetree, linux-kernel, Hongmei Xu
Add a device tree binding for the Qualcomm eFuse Ethernet MAC address
NVMEM layout driver. The layout handles cells whose bytes in the QFPROM
may not be contiguous.
Each cell node specifies the physical eFuse offset and size via reg.
An optional byte-mask property selects which physical bytes contribute
to the 6-byte output MAC address; selected bytes are compacted in
ascending bit-index order. Without byte-mask the cell is read as a
plain contiguous 6-byte block.
Also add qcom,nord-qfprom to the QFPROM compatible list; this SoC uses
the layout and its compatible is referenced in the binding example.
Signed-off-by: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
---
.../bindings/nvmem/layouts/qcom,efuse-eth-mac.yaml | 87 ++++++++++++++++++++++
.../devicetree/bindings/nvmem/qcom,qfprom.yaml | 1 +
2 files changed, 88 insertions(+)
diff --git a/Documentation/devicetree/bindings/nvmem/layouts/qcom,efuse-eth-mac.yaml b/Documentation/devicetree/bindings/nvmem/layouts/qcom,efuse-eth-mac.yaml
new file mode 100644
index 000000000000..545aeb1741ce
--- /dev/null
+++ b/Documentation/devicetree/bindings/nvmem/layouts/qcom,efuse-eth-mac.yaml
@@ -0,0 +1,87 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/layouts/qcom,efuse-eth-mac.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Ethernet MAC address NVMEM layout
+
+maintainers:
+ - Hongmei Xu <hongmei.xu@oss.qualcomm.com>
+
+description:
+ Layout for reading Ethernet MAC addresses from Qualcomm eFuse (QFPROM).
+ Each cell node declares the physical eFuse offset via reg. An optional
+ byte-mask property selects which physical bytes contribute to the 6-byte
+ output MAC; selected bytes are compacted in ascending bit-index order and
+ unset positions are zero-filled. Without byte-mask the cell is read as a
+ plain contiguous 6-byte block.
+
+select: false
+
+properties:
+ compatible:
+ const: qcom,efuse-eth-mac
+
+ "#address-cells":
+ const: 1
+
+ "#size-cells":
+ const: 1
+
+patternProperties:
+ "^eth[0-9]+-mac@[0-9a-f]+$":
+ type: object
+ description: Ethernet MAC address cell
+
+ properties:
+ reg:
+ maxItems: 1
+ description:
+ Physical span within the NVMEM device as <offset size>. The
+ driver uses byte-mask to determine the actual read length;
+ size is informational and conventionally set to the physical
+ span of the MAC bytes in the eFuse.
+
+ byte-mask:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description:
+ Bitmask where bit i means physical byte i in the eFuse span
+ contributes to the output MAC address. Valid bytes are compacted
+ in ascending bit-index order; output positions beyond
+ hweight(byte-mask) are zero-filled. The number of set bits must
+ not exceed ETH_ALEN (6). Absent when all 6 bytes are contiguous.
+
+ required:
+ - reg
+
+ additionalProperties: false
+
+required:
+ - compatible
+
+additionalProperties: false
+
+examples:
+ - |
+ efuse: efuse@360d4320 {
+ compatible = "qcom,nord-qfprom", "qcom,qfprom";
+ reg = <0x0 0x360d4320 0x0 0x8>;
+
+ nvmem-layout {
+ compatible = "qcom,efuse-eth-mac";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ eth0_mac: eth0-mac@0 {
+ reg = <0x0 0x6>;
+ };
+
+ eth1_mac: eth1-mac@0 {
+ reg = <0x0 0x7>;
+ byte-mask = <0x5f>;
+ };
+ };
+ };
+
+...
diff --git a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
index 566304ed4c78..d7f48d4ed1ba 100644
--- a/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
+++ b/Documentation/devicetree/bindings/nvmem/qcom,qfprom.yaml
@@ -42,6 +42,7 @@ properties:
- qcom,msm8976-qfprom
- qcom,msm8996-qfprom
- qcom,msm8998-qfprom
+ - qcom,nord-qfprom
- qcom,qcm2290-qfprom
- qcom,qcs404-qfprom
- qcom,qcs615-qfprom
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v5 2/5] nvmem: layouts: add Qualcomm eFuse Ethernet MAC address layout driver
2026-12-04 6:22 [PATCH v5 0/5] nvmem: add Qualcomm eFuse Ethernet MAC address layout driver Hongmei Xu
2026-12-04 6:22 ` [PATCH v5 1/5] dt-bindings: nvmem: layouts: add Qualcomm eFuse Ethernet MAC layout Hongmei Xu
@ 2026-12-04 6:22 ` Hongmei Xu
2026-12-04 6:53 ` sashiko-bot
2026-12-04 6:22 ` [PATCH v5 3/5] MAINTAINERS: add entry for Qualcomm Ethernet MAC nvmem " Hongmei Xu
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Hongmei Xu @ 2026-12-04 6:22 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki
Cc: devicetree, linux-kernel, Hongmei Xu
Add an NVMEM layout driver for reading Ethernet MAC addresses from
Qualcomm eFuse (QFPROM). The driver supports two cell layouts:
- Contiguous: six consecutive eFuse bytes form the MAC directly.
- Non-contiguous: a byte-mask device tree property selects which
physical bytes within the eFuse span contribute to the output MAC.
Bit i set means byte i is included; selected bytes are compacted
in ascending bit-index order into a 6-byte output.
QFPROM hardware requires 4-byte word-aligned reads. For non-contiguous
cells the actual read length is ALIGN(fls(byte_mask), 4); for
contiguous cells it is ALIGN(ETH_ALEN, 4). Both paths are validated
against the eFuse device size at layout probe time to prevent
out-of-bounds hardware accesses.
Signed-off-by: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
---
drivers/nvmem/layouts/Kconfig | 11 ++
drivers/nvmem/layouts/Makefile | 1 +
drivers/nvmem/layouts/qcom-eth-mac.c | 203 +++++++++++++++++++++++++++++++++++
3 files changed, 215 insertions(+)
diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig
index 5e586dfebe47..d60bce199b8e 100644
--- a/drivers/nvmem/layouts/Kconfig
+++ b/drivers/nvmem/layouts/Kconfig
@@ -37,6 +37,17 @@ config NVMEM_LAYOUT_U_BOOT_ENV
If unsure, say N.
+config NVMEM_LAYOUT_QCOM_ETH_MAC
+ tristate "Qualcomm Ethernet MAC address layout"
+ depends on OF
+ help
+ Reads Ethernet MAC addresses from Qualcomm eFuse (QFPROM).
+ Supports cells with non-contiguous byte layouts via an optional
+ byte-mask property that selects and compacts physical eFuse bytes
+ into the 6-byte output MAC address.
+
+ Say Y if your Qualcomm SoC stores Ethernet MAC addresses in eFuse.
+
endmenu
endif
diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile
index dd6c6c70b1a9..127a4aae420d 100644
--- a/drivers/nvmem/layouts/Makefile
+++ b/drivers/nvmem/layouts/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_NVMEM_LAYOUTS) += fixed-layout.o
obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o
obj-$(CONFIG_NVMEM_LAYOUT_ONIE_TLV) += onie-tlv.o
obj-$(CONFIG_NVMEM_LAYOUT_U_BOOT_ENV) += u-boot-env.o
+obj-$(CONFIG_NVMEM_LAYOUT_QCOM_ETH_MAC) += qcom-eth-mac.o
diff --git a/drivers/nvmem/layouts/qcom-eth-mac.c b/drivers/nvmem/layouts/qcom-eth-mac.c
new file mode 100644
index 000000000000..990b096a0a5f
--- /dev/null
+++ b/drivers/nvmem/layouts/qcom-eth-mac.c
@@ -0,0 +1,203 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+/*
+ * Qualcomm Ethernet MAC address nvmem layout driver
+ *
+ * Each cell node carries an optional "byte-mask" — a bitmask where bit i
+ * means physical byte i in the eFuse span contributes to the output MAC.
+ * Valid bytes are compacted in ascending bit-index order into output
+ * positions 0..hweight(byte-mask)-1; remaining output bytes are zeroed.
+ * Without "byte-mask" the cell is read as a plain contiguous ETH_ALEN block.
+ *
+ * Example (SA8797P eth1 — physical bytes 0-4,6 are the MAC, byte 5 belongs
+ * to eth0 and must be skipped):
+ * reg = <0x0 0x7>; // physical span: bytes 0-6
+ * byte-mask = <0x5f>; // bits 0,1,2,3,4,6 → output[0..5]
+ *
+ * QFPROM reads are 4-byte word-aligned; raw_len is rounded up accordingly.
+ */
+#include <linux/bitops.h>
+#include <linux/etherdevice.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/nvmem-consumer.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of.h>
+#include <linux/slab.h>
+
+/* QFPROM register reads are 4-byte word aligned */
+#define QCOM_QFPROM_WORD_SIZE 4U
+
+struct qcom_eth_mac_priv {
+ u32 byte_mask;
+ u32 raw_len;
+ struct device *dev;
+};
+
+static int qcom_eth_mac_post_process(void *priv, const char *id, int index,
+ unsigned int offset, void *buf, size_t bytes)
+{
+ struct qcom_eth_mac_priv *p = priv;
+ u8 *out = buf;
+ u32 out_idx = 0;
+ u8 *raw;
+ u32 i;
+
+ raw = kmemdup(buf, p->raw_len, GFP_KERNEL);
+ if (!raw)
+ return -ENOMEM;
+
+ memset(out, 0, bytes);
+
+ for (i = 0; i < p->raw_len && out_idx < bytes; i++) {
+ if (p->byte_mask & BIT(i))
+ out[out_idx++] = raw[i];
+ }
+
+ kfree(raw);
+ dev_dbg(p->dev, "post_process %s: mask=0x%02x out=%pM\n",
+ id, p->byte_mask, out);
+ return 0;
+}
+
+static int qcom_eth_mac_add_cells(struct nvmem_layout *layout)
+{
+ struct nvmem_device *nvmem = layout->nvmem;
+ struct device *dev = &layout->dev;
+ struct device_node *layout_node;
+ struct device_node *child;
+ int ret = 0;
+
+ layout_node = of_nvmem_layout_get_container(nvmem);
+ if (!layout_node) {
+ dev_err(dev, "add_cells: no nvmem-layout container node\n");
+ return -ENOENT;
+ }
+
+ for_each_child_of_node(layout_node, child) {
+ struct nvmem_cell_info info = {};
+ u32 reg[2];
+ u32 byte_mask = 0;
+
+ if (of_property_read_u32_array(child, "reg", reg, 2)) {
+ dev_err(dev, "missing reg in %pOF\n", child);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ info.name = child->name;
+ info.offset = reg[0];
+ info.bytes = ETH_ALEN;
+ info.np = of_node_get(child);
+
+ of_property_read_u32(child, "byte-mask", &byte_mask);
+
+ if (byte_mask) {
+ struct qcom_eth_mac_priv *priv;
+ u32 raw_len;
+
+ if (hweight32(byte_mask) > ETH_ALEN) {
+ dev_err(dev, "%pOF: byte-mask 0x%x has more than %d bits set\n",
+ child, byte_mask, ETH_ALEN);
+ of_node_put(info.np);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ raw_len = ALIGN((u32)fls(byte_mask), QCOM_QFPROM_WORD_SIZE);
+
+ dev_dbg(dev, "%pOF: byte_mask=0x%x hweight=%d raw_len=%u\n",
+ child, byte_mask, hweight32(byte_mask), raw_len);
+
+ if (info.offset + raw_len > nvmem_dev_size(nvmem)) {
+ dev_err(dev, "%pOF: offset %u + raw_len %u exceeds device size %zu\n",
+ child, info.offset, raw_len,
+ nvmem_dev_size(nvmem));
+ of_node_put(info.np);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv) {
+ of_node_put(info.np);
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ priv->byte_mask = byte_mask;
+ priv->raw_len = raw_len;
+ priv->dev = dev;
+ info.raw_len = raw_len;
+ info.read_post_process = qcom_eth_mac_post_process;
+ info.priv = priv;
+ } else {
+ /* contiguous cell: word-align the read to avoid read overlap */
+ info.raw_len = ALIGN(ETH_ALEN, QCOM_QFPROM_WORD_SIZE);
+
+ if (info.offset + info.raw_len > nvmem_dev_size(nvmem)) {
+ dev_err(dev, "%pOF: offset %u + %zu exceeds device size %zu\n",
+ child, info.offset, info.raw_len,
+ nvmem_dev_size(nvmem));
+ of_node_put(info.np);
+ ret = -EINVAL;
+ goto out;
+ }
+ }
+
+ ret = nvmem_add_one_cell(nvmem, &info);
+ if (ret) {
+ of_node_put(info.np);
+ dev_err(dev, "failed to add cell %s: %d\n", info.name, ret);
+ goto out;
+ }
+
+ dev_dbg(dev, "%pOF: added cell '%s' offset=%u bytes=%u raw_len=%zu\n",
+ child, info.name, info.offset, info.bytes, info.raw_len);
+
+ /*
+ * Mark the cell fwnode as not-a-device so fw_devlink stops
+ * blocking ethernet on this supplier link. Must be called
+ * after nvmem_add_one_cell() so the fwnode exists.
+ * fw_devlink_refresh_fwnode() cannot be used here because the
+ * efuse device is still in probe and not yet DL_DEV_DRIVER_BOUND.
+ */
+ fw_devlink_purge_absent_suppliers(of_fwnode_handle(child));
+ }
+
+out:
+ of_node_put(child);
+ of_node_put(layout_node);
+ return ret;
+}
+
+static int qcom_eth_mac_probe(struct nvmem_layout *layout)
+{
+ layout->add_cells = qcom_eth_mac_add_cells;
+
+ return nvmem_layout_register(layout);
+}
+
+static void qcom_eth_mac_remove(struct nvmem_layout *layout)
+{
+ nvmem_layout_unregister(layout);
+}
+
+static const struct of_device_id qcom_eth_mac_of_match[] = {
+ { .compatible = "qcom,efuse-eth-mac" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, qcom_eth_mac_of_match);
+
+static struct nvmem_layout_driver qcom_eth_mac_layout = {
+ .driver = {
+ .name = "qcom-eth-mac-layout",
+ .of_match_table = qcom_eth_mac_of_match,
+ },
+ .probe = qcom_eth_mac_probe,
+ .remove = qcom_eth_mac_remove,
+};
+module_nvmem_layout_driver(qcom_eth_mac_layout);
+
+MODULE_DESCRIPTION("Qualcomm Ethernet MAC nvmem layout driver");
+MODULE_LICENSE("GPL");
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v5 3/5] MAINTAINERS: add entry for Qualcomm Ethernet MAC nvmem layout driver
2026-12-04 6:22 [PATCH v5 0/5] nvmem: add Qualcomm eFuse Ethernet MAC address layout driver Hongmei Xu
2026-12-04 6:22 ` [PATCH v5 1/5] dt-bindings: nvmem: layouts: add Qualcomm eFuse Ethernet MAC layout Hongmei Xu
2026-12-04 6:22 ` [PATCH v5 2/5] nvmem: layouts: add Qualcomm eFuse Ethernet MAC address layout driver Hongmei Xu
@ 2026-12-04 6:22 ` Hongmei Xu
2026-12-04 6:22 ` [PATCH v5 4/5] arm64: defconfig: enable NVMEM_LAYOUT_QCOM_ETH_MAC Hongmei Xu
2026-12-04 6:22 ` [PATCH v5 5/5] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses Hongmei Xu
4 siblings, 0 replies; 10+ messages in thread
From: Hongmei Xu @ 2026-12-04 6:22 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki
Cc: devicetree, linux-kernel, Hongmei Xu
Add a MAINTAINERS entry for the new Qualcomm Ethernet MAC nvmem layout
driver and its DT binding.
Signed-off-by: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
---
MAINTAINERS | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index fe23913b1e43..dfc53bb0bf7e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -23032,6 +23032,12 @@ L: netdev@vger.kernel.org
S: Maintained
F: drivers/net/ethernet/qualcomm/emac/
+QUALCOMM ETHERNET MAC NVMEM LAYOUT DRIVER
+M: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
+S: Maintained
+F: Documentation/devicetree/bindings/nvmem/layouts/qcom,efuse-eth-mac.yaml
+F: drivers/nvmem/layouts/qcom-eth-mac.c
+
QUALCOMM ETHQOS ETHERNET DRIVER
M: Mohd Ayaan Anwar <mohd.anwar@oss.qualcomm.com>
L: netdev@vger.kernel.org
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v5 4/5] arm64: defconfig: enable NVMEM_LAYOUT_QCOM_ETH_MAC
2026-12-04 6:22 [PATCH v5 0/5] nvmem: add Qualcomm eFuse Ethernet MAC address layout driver Hongmei Xu
` (2 preceding siblings ...)
2026-12-04 6:22 ` [PATCH v5 3/5] MAINTAINERS: add entry for Qualcomm Ethernet MAC nvmem " Hongmei Xu
@ 2026-12-04 6:22 ` Hongmei Xu
2026-12-04 6:30 ` sashiko-bot
2026-12-04 6:22 ` [PATCH v5 5/5] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses Hongmei Xu
4 siblings, 1 reply; 10+ messages in thread
From: Hongmei Xu @ 2026-12-04 6:22 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki
Cc: devicetree, linux-kernel, Hongmei Xu
Enable the Qualcomm eFuse Ethernet MAC address NVMEM layout driver for
arm64 builds.
Signed-off-by: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
---
arch/arm64/configs/defconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index 7b4985b29b21..f7355450f22e 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -1728,6 +1728,7 @@ CONFIG_NVMEM_IMX_OCOTP=y
CONFIG_NVMEM_IMX_OCOTP_ELE=m
CONFIG_NVMEM_IMX_OCOTP_SCU=y
CONFIG_NVMEM_LAYERSCAPE_SFP=m
+CONFIG_NVMEM_LAYOUT_QCOM_ETH_MAC=y
CONFIG_NVMEM_MESON_EFUSE=m
CONFIG_NVMEM_MTK_EFUSE=y
CONFIG_NVMEM_QCOM_QFPROM=y
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v5 5/5] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses
2026-12-04 6:22 [PATCH v5 0/5] nvmem: add Qualcomm eFuse Ethernet MAC address layout driver Hongmei Xu
` (3 preceding siblings ...)
2026-12-04 6:22 ` [PATCH v5 4/5] arm64: defconfig: enable NVMEM_LAYOUT_QCOM_ETH_MAC Hongmei Xu
@ 2026-12-04 6:22 ` Hongmei Xu
2026-12-04 6:43 ` sashiko-bot
4 siblings, 1 reply; 10+ messages in thread
From: Hongmei Xu @ 2026-12-04 6:22 UTC (permalink / raw)
To: Srinivas Kandagatla, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Rafał Miłecki
Cc: devicetree, linux-kernel, Hongmei Xu
Add a QFPROM eFuse node to expose the Ethernet MAC addresses for
EMAC0 and EMAC1 as nvmem cells.
The MAC addresses are stored in OEM_CONFIG8/9 registers starting at
0x360d4320:
bytes 0-4 shared by both EMACs
byte 5 last octet of EMAC0 MAC address
byte 6 last octet of EMAC1 MAC address
EMAC0 reads six consecutive bytes (0-5), requiring no byte selection.
EMAC1 shares bytes 0-4 but takes byte 6 as its last octet, skipping
byte 5. A byte-mask of 0x5F (0b01011111) is used to select bytes
0,1,2,3,4,6 and compact them into the six-byte output buffer.
Only 8 bytes are mapped to avoid overlapping with adjacent QFPROM
devices in the register space.
Signed-off-by: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
---
arch/arm64/boot/dts/qcom/nord.dtsi | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/arch/arm64/boot/dts/qcom/nord.dtsi b/arch/arm64/boot/dts/qcom/nord.dtsi
index fdbe290350dd..185db2e19c39 100644
--- a/arch/arm64/boot/dts/qcom/nord.dtsi
+++ b/arch/arm64/boot/dts/qcom/nord.dtsi
@@ -2116,6 +2116,26 @@ llcc: system-cache-controller@21800000 {
"llcc_broadcast_base",
"llcc_broadcast_and_base";
};
+
+ efuse: efuse@360d4320 {
+ compatible = "qcom,nord-qfprom", "qcom,qfprom";
+ reg = <0x0 0x360d4320 0x0 0x8>;
+
+ nvmem-layout {
+ compatible = "qcom,efuse-eth-mac";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ eth0_mac: eth0-mac@0 {
+ reg = <0x0 0x6>;
+ };
+
+ eth1_mac: eth1-mac@0 {
+ reg = <0x0 0x7>;
+ byte-mask = <0x5f>;
+ };
+ };
+ };
};
arch_timer: timer {
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v5 4/5] arm64: defconfig: enable NVMEM_LAYOUT_QCOM_ETH_MAC
2026-12-04 6:22 ` [PATCH v5 4/5] arm64: defconfig: enable NVMEM_LAYOUT_QCOM_ETH_MAC Hongmei Xu
@ 2026-12-04 6:30 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-04 6:30 UTC (permalink / raw)
To: Hongmei Xu; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] arm64: defconfig: enable NVMEM_LAYOUT_QCOM_ETH_MAC as module
instead of y
- [Low] arm64: defconfig: NVMEM_LAYOUT_QCOM_ETH_MAC out of savedefconfig
order
--
commit 95a7c71fcd811c52dbc5f369086db485010b7e63
Author: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
arm64: defconfig: enable NVMEM_LAYOUT_QCOM_ETH_MAC
This commit enables CONFIG_NVMEM_LAYOUT_QCOM_ETH_MAC as built-in in the
arm64 defconfig.
> diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
> index 7b4985b29b21c..f7355450f22e8 100644
> --- a/arch/arm64/configs/defconfig
> +++ b/arch/arm64/configs/defconfig
> @@ -1728,6 +1728,7 @@ CONFIG_NVMEM_IMX_OCOTP=y
> CONFIG_NVMEM_IMX_OCOTP_ELE=m
> CONFIG_NVMEM_IMX_OCOTP_SCU=y
> CONFIG_NVMEM_LAYERSCAPE_SFP=m
> +CONFIG_NVMEM_LAYOUT_QCOM_ETH_MAC=y
> CONFIG_NVMEM_MESON_EFUSE=m
> CONFIG_NVMEM_MTK_EFUSE=y
> CONFIG_NVMEM_QCOM_QFPROM=y
[Severity: Low]
Should CONFIG_NVMEM_LAYOUT_QCOM_ETH_MAC be enabled as a module (=m) instead
of built-in (=y)?
The driver is tristate, its Qualcomm Ethernet consumers (CONFIG_QCOM_EMAC=m
and CONFIG_STMMAC_ETH=m) and CONFIG_NVMEM_LAYOUT_SL28_VPD=m are modules, and
the NVMEM core supports modular layouts via autoloading and probe deferral.
Building it in unnecessarily increases the arm64 kernel image size.
[Severity: Low]
Is CONFIG_NVMEM_LAYOUT_QCOM_ETH_MAC in savedefconfig order here?
drivers/nvmem/Kconfig sources drivers/nvmem/layouts/Kconfig before the NVMEM
device drivers, so make ARCH=arm64 savedefconfig will move this entry
directly after CONFIG_NVMEM_LAYOUT_SL28_VPD=m (before
CONFIG_NVMEM_APPLE_EFUSES=m), causing churn on future defconfig updates.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-nvmem-byte-mask-for-split-macaddr-v5-0-13c12a99383f@oss.qualcomm.com?part=4
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 1/5] dt-bindings: nvmem: layouts: add Qualcomm eFuse Ethernet MAC layout
2026-12-04 6:22 ` [PATCH v5 1/5] dt-bindings: nvmem: layouts: add Qualcomm eFuse Ethernet MAC layout Hongmei Xu
@ 2026-12-04 6:40 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-04 6:40 UTC (permalink / raw)
To: Hongmei Xu; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Medium] dt-bindings: nvmem: qcom,efuse-eth-mac.yaml unreferenced with
select false
- [Medium] dt-bindings: nvmem: duplicate @0 unit-address on
shared-offset MAC cells
- [Medium] dt-bindings: nvmem: example 4-cell reg lacks 2-cell parent
bus node
- [Medium] dt-bindings: nvmem: byte-mask lacks qcom vendor prefix and
minimum bound
- [Medium] dt-bindings: nvmem: reg size marked informational and leaks
driver terms
- [Medium] dt-bindings: nvmem: MAC-only layout blocks non-MAC cells and
splits QFPROM
- [Low] dt-bindings: nvmem: unused node labels in qcom,efuse-eth-mac
example
--
commit 83a0f7d91e8c47c792f2963b9b58a84133cc3b0f
Author: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
dt-bindings: nvmem: layouts: add Qualcomm eFuse Ethernet MAC layout
This commit adds a Device Tree binding schema for the Qualcomm eFuse
Ethernet MAC address NVMEM layout and adds the qcom,nord-qfprom
compatible to qcom,qfprom.yaml.
> diff --git a/Documentation/devicetree/bindings/nvmem/layouts/qcom,efuse-eth-mac.yaml b/Documentation/devicetree/bindings/nvmem/layouts/qcom,efuse-eth-mac.yaml
> new file mode 100644
> index 0000000000000..545aeb1741ce5
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/nvmem/layouts/qcom,efuse-eth-mac.yaml
> @@ -0,0 +1,87 @@
[ ... ]
> +select: false
[Severity: Medium]
Should qcom,efuse-eth-mac.yaml also be added to the oneOf list in
Documentation/devicetree/bindings/nvmem/layouts/nvmem-layout.yaml?
With select: false, this schema is never applied directly, and
nvmem-layout.yaml validates nvmem-layout nodes against a closed oneOf
list with unevaluatedProperties: false. Without referencing it there,
make dt_binding_check fails on the example below.
[ ... ]
> +patternProperties:
> + "^eth[0-9]+-mac@[0-9a-f]+$":
[Severity: Medium]
Can two Ethernet MAC cells that share a starting eFuse byte offset avoid
a duplicate unit-address warning under this pattern?
Because nvmem-layout uses #address-cells = <1> and this pattern allows
only a single hex offset after @, sibling nodes starting at the same
offset (such as eth0-mac@0 and eth1-mac@0 in the example) share the
unit-address @0.
dtc checks unit-addresses across enabled siblings regardless of the
node-name prefix under -Wunique_unit_address_if_enabled, so
make dt_binding_check rejects this. A sub-qualifier like the one in
fixed-layout.yaml (@[a-f0-9]+(,[0-7])?$) would disambiguate them.
[ ... ]
> + reg:
> + maxItems: 1
> + description:
> + Physical span within the NVMEM device as <offset size>. The
> + driver uses byte-mask to determine the actual read length;
> + size is informational and conventionally set to the physical
> + span of the MAC bytes in the eFuse.
[Severity: Medium]
Should the reg size cell bound the bits set in byte-mask rather than
being treated as informational?
Allowing byte-mask to determine the read length independently of reg
breaks standard reg semantics and lets a cell reference bytes past its
declared [offset, offset + size) span.
Also, this description and the byte-mask description below refer to
Linux driver behavior ("The driver uses byte-mask...") and kernel
symbols (hweight(byte-mask), ETH_ALEN), which writing-bindings.rst
asks bindings to avoid.
> +
> + byte-mask:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description:
> + Bitmask where bit i means physical byte i in the eFuse span
> + contributes to the output MAC address. Valid bytes are compacted
> + in ascending bit-index order; output positions beyond
> + hweight(byte-mask) are zero-filled. The number of set bits must
> + not exceed ETH_ALEN (6). Absent when all 6 bytes are contiguous.
[Severity: Medium]
Should byte-mask carry the qcom, vendor prefix and a minimum: 1 schema
constraint?
Because byte-mask is a custom property defined only in this
Qualcomm-specific binding, writing-bindings.rst requires a vendor prefix
(qcom,byte-mask). Omitting minimum: 1 also allows byte-mask = <0> to
pass validation even though zero set bits conflicts with the absent
property case (6 contiguous bytes).
[ ... ]
> +additionalProperties: false
[Severity: Medium]
Does restricting this layout exclusively to Ethernet MAC cells prevent
other QFPROM cells from coexisting on the same NVMEM device?
An NVMEM provider supports at most one nvmem-layout child node
(of_nvmem_layout_get_container()), and direct child cells under QFPROM
are deprecated by nvmem-deprecated-cells.yaml.
With patternProperties limited to ^eth[0-9]+-mac@[0-9a-f]+$ and
additionalProperties: false, no other QFPROM cells can live in the
layout, forcing a synthetic 8-byte qcom,qfprom node as in the example.
Supporting generic fixed cells alongside Ethernet MAC cells in one
Qualcomm QFPROM layout would keep the full QFPROM block in one node.
[ ... ]
> + efuse: efuse@360d4320 {
> + compatible = "qcom,nord-qfprom", "qcom,qfprom";
> + reg = <0x0 0x360d4320 0x0 0x8>;
[Severity: Medium]
Will this 4-cell reg property fail dt_binding_check without a 2-cell
parent bus node?
Top-level binding examples default to #address-cells = <1> and
#size-cells = <1>, so this reg is parsed as two entries
(<0x0 0x360d4320> and <0x0 0x8>).
That triggers a unit_address_vs_reg mismatch against @360d4320 and
violates qcom,qfprom.yaml, which only allows 1 or 4 reg entries.
Wrapping the node in a soc node with 2 address and size cells (or using
a 1-cell reg = <0x360d4320 0x8>) fixes this.
[ ... ]
> + eth0_mac: eth0-mac@0 {
> + reg = <0x0 0x6>;
> + };
> +
> + eth1_mac: eth1-mac@0 {
> + reg = <0x0 0x7>;
> + byte-mask = <0x5f>;
> + };
[Severity: Low]
This isn't a bug, but the efuse, eth0_mac, and eth1_mac labels are not
referenced anywhere in the example, which violates writing-schema.rst
and fails scripts/dtc/dt-check-style in strict mode.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-nvmem-byte-mask-for-split-macaddr-v5-0-13c12a99383f@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 5/5] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses
2026-12-04 6:22 ` [PATCH v5 5/5] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses Hongmei Xu
@ 2026-12-04 6:43 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-04 6:43 UTC (permalink / raw)
To: Hongmei Xu; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] nvmem: layouts: UAF of devm priv in qcom_eth_mac_post_process()
- [Medium] arm64: dts: qcom: dtbs_check failure for qcom,efuse-eth-mac
layout
- [Medium] arm64: dts: qcom: standalone 8-byte QFPROM slice breaks DT
modeling
- [Medium] nvmem: qcom-eth-mac: premature
fw_devlink_purge_absent_suppliers() drops links
- [Low] arm64: dts: qcom: duplicate @0 unit-address on eth0-mac and
eth1-mac
--
commit c44ef6ebd0ca67b47b5b2f8c3e7c8472378a4efd
Author: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses
This commit adds a QFPROM eFuse node in nord.dtsi with an nvmem-layout
exposing the EMAC0 and EMAC1 MAC addresses as nvmem cells.
> diff --git a/arch/arm64/boot/dts/qcom/nord.dtsi b/arch/arm64/boot/dts/qcom/nord.dtsi
> index fdbe290350ddd..185db2e19c39c 100644
> --- a/arch/arm64/boot/dts/qcom/nord.dtsi
> +++ b/arch/arm64/boot/dts/qcom/nord.dtsi
> @@ -2116,6 +2116,26 @@ llcc: system-cache-controller@21800000 {
> "llcc_broadcast_base",
> "llcc_broadcast_and_base";
> };
> +
> + efuse: efuse@360d4320 {
> + compatible = "qcom,nord-qfprom", "qcom,qfprom";
> + reg = <0x0 0x360d4320 0x0 0x8>;
[Severity: Medium]
Should efuse@360d4320 describe the QFPROM corrected region rather than an
8-byte slice dedicated to Ethernet MACs?
qfprom_probe() claims reg entry 0 exclusively via
devm_platform_get_and_ioremap_resource(), so adding a node for the full
QFPROM corrected region later will fail with -EBUSY unless efuse@360d4320
is removed and DT ABI is broken. Attaching qcom,efuse-eth-mac as the
device's nvmem-layout also prevents non-MAC fuses from sharing this efuse
node because qcom_eth_mac_add_cells() treats every child as a 6-byte MAC
address.
Describing a standard 0x1000 corrected region at 0x360d4000 (which avoids
0x360d5000) with fixed-layout and per-cell post-processing would let MAC
cells and general QFPROM fuses coexist.
> +
> + nvmem-layout {
> + compatible = "qcom,efuse-eth-mac";
> + #address-cells = <1>;
> + #size-cells = <1>;
[Severity: Medium]
Does compatible = "qcom,efuse-eth-mac" fail make dtbs_check here?
Commit "dt-bindings: nvmem: layouts: add Qualcomm eFuse Ethernet MAC
layout" sets select: false in qcom,efuse-eth-mac.yaml without adding a
$ref entry to
Documentation/devicetree/bindings/nvmem/layouts/nvmem-layout.yaml, so
the schema is never applied and dt-validate rejects this node in
nord-ride.dtb and nord-rrd.dtb.
In addition, the example in qcom,efuse-eth-mac.yaml puts a 4-cell reg
property at the example root without a 2-cell parent node, failing
make dt_binding_check against qcom,qfprom.yaml.
[Severity: Medium]
Does the qcom,efuse-eth-mac driver drop fw_devlink consumer links for
eth0_mac and eth1_mac during probe?
In commit "nvmem: layouts: add Qualcomm eFuse Ethernet MAC address layout
driver", qcom_eth_mac_add_cells() calls fw_devlink_purge_absent_suppliers()
on each child node. That deletes all consumer fwnode links before
device_links_driver_bound() runs fw_devlink_pickup_dangling_consumers() to
move them onto layout->dev as managed device links, breaking
supplier/consumer suspend, shutdown, unbind, and sync_state ordering.
It also leaves earlier cells' consumer links permanently purged if a later
cell fails validation during probe. Dropping that call lets driver core
handle the child fwnodes on bind, as fixed-layout.c does.
> +
> + eth0_mac: eth0-mac@0 {
> + reg = <0x0 0x6>;
> + };
> +
> + eth1_mac: eth1-mac@0 {
> + reg = <0x0 0x7>;
> + byte-mask = <0x5f>;
> + };
[Severity: Low]
Will eth0-mac@0 and eth1-mac@0 trigger a dtc duplicate unit-address warning
on W=1 and dtbs_check builds?
Both enabled sibling nodes share @0, which fails
-Wunique_unit_address_if_enabled, and instance-numbered names (eth0-mac,
eth1-mac) conflict with generic Devicetree node-naming guidelines.
Modeling the shared 7-byte region as one generic cell at @0 with
#nvmem-cell-cells = <1> would avoid both issues.
[Severity: High]
Can reading eth1-mac@0 trigger a use-after-free of cell->priv in
qcom_eth_mac_post_process()?
In commit "nvmem: layouts: add Qualcomm eFuse Ethernet MAC address layout
driver", qcom_eth_mac_add_cells() allocates priv with
devm_kzalloc(&layout->dev, ...) and attaches it to a cell registered on
the parent nvmem->cells list. When the layout driver is unbound or
unloaded, nvmem_layout_unregister() is an empty stub that leaves the cell
live in sysfs while device_unbind_cleanup() frees priv via
devres_release_all().
Reading the cell via sysfs afterward invokes qcom_eth_mac_post_process()
on the freed priv (passing p->raw_len to kmemdup() and reading
p->byte_mask and p->dev), and jumps into unmapped module text if the
module was unloaded. The same dangling priv occurs if
qcom_eth_mac_add_cells() fails on a later child after registering an
earlier byte-masked cell.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-nvmem-byte-mask-for-split-macaddr-v5-0-13c12a99383f@oss.qualcomm.com?part=5
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v5 2/5] nvmem: layouts: add Qualcomm eFuse Ethernet MAC address layout driver
2026-12-04 6:22 ` [PATCH v5 2/5] nvmem: layouts: add Qualcomm eFuse Ethernet MAC address layout driver Hongmei Xu
@ 2026-12-04 6:53 ` sashiko-bot
0 siblings, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-12-04 6:53 UTC (permalink / raw)
To: Hongmei Xu; +Cc: devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] nvmem: qcom-eth-mac: use-after-free of layout devm cell priv
and priv->dev
- [Medium] nvmem: qcom-eth-mac: fw_devlink_purge_absent_suppliers()
breaks device links
- [Medium] nvmem: qcom-eth-mac: 32-bit unsigned overflow in device-size
bounds checks
- [Medium] nvmem: qcom_eth_mac_add_cells() fails on unaligned QFPROM
cell offsets
- [Low] nvmem: qcom-eth-mac: unchecked of_property_read_u32() return for
byte-mask
- [Low] nvmem: qcom-eth-mac: unnecessary kmemdup() allocation in
qcom_eth_mac_post_process()
--
commit 13f6b8a719713c9b87d23ea33aed9c0b2e45236c
Author: Hongmei Xu <hongmei.xu@oss.qualcomm.com>
nvmem: layouts: add Qualcomm eFuse Ethernet MAC address layout driver
This commit adds an NVMEM layout driver for reading contiguous and
non-contiguous Ethernet MAC addresses from Qualcomm QFPROM eFuse cells.
> diff --git a/drivers/nvmem/layouts/qcom-eth-mac.c b/drivers/nvmem/layouts/qcom-eth-mac.c
> new file mode 100644
> index 0000000000000..990b096a0a5f4
> --- /dev/null
> +++ b/drivers/nvmem/layouts/qcom-eth-mac.c
[ ... ]
> +static int qcom_eth_mac_post_process(void *priv, const char *id, int index,
> + unsigned int offset, void *buf, size_t bytes)
> +{
> + struct qcom_eth_mac_priv *p = priv;
> + u8 *out = buf;
> + u32 out_idx = 0;
> + u8 *raw;
> + u32 i;
> +
> + raw = kmemdup(buf, p->raw_len, GFP_KERNEL);
> + if (!raw)
> + return -ENOMEM;
> +
> + memset(out, 0, bytes);
> +
> + for (i = 0; i < p->raw_len && out_idx < bytes; i++) {
> + if (p->byte_mask & BIT(i))
> + out[out_idx++] = raw[i];
> + }
> +
> + kfree(raw);
[Severity: Low]
Does qcom_eth_mac_post_process() need to kmemdup() buf on every cell read?
Since out_idx never exceeds i, the loop can compact in place with
out[out_idx++] = out[i] and zero the tail with
memset(out + out_idx, 0, bytes - out_idx), dropping both the allocation
and the -ENOMEM path.
[ ... ]
> + info.name = child->name;
> + info.offset = reg[0];
> + info.bytes = ETH_ALEN;
> + info.np = of_node_get(child);
[Severity: Medium]
Can qcom_eth_mac_add_cells() handle cells whose reg[0] offset is not
4-byte aligned, such as a second contiguous 6-byte MAC cell at offset 0x6?
qcom,qfprom sets stride = 4 and relies on qfprom_fixup_dt_cell_info(),
which only runs via nvmem_add_cells_from_dt(). Because this driver calls
nvmem_add_one_cell() directly, nvmem core rejects any unaligned reg[0]
with -EINVAL and aborts layout registration.
Aligning info.offset down to QCOM_QFPROM_WORD_SIZE and adjusting raw_len
and byte_mask for the leading bytes would avoid this.
> +
> + of_property_read_u32(child, "byte-mask", &byte_mask);
> +
> + if (byte_mask) {
[Severity: Low]
Should the return value of of_property_read_u32() be checked here?
Ignoring it treats a malformed byte-mask property (-ENODATA or -EOVERFLOW)
or an explicit byte-mask = <0> the same as an absent property (-EINVAL),
silently reading contiguous eFuse bytes instead of failing probe.
[ ... ]
> + if (info.offset + raw_len > nvmem_dev_size(nvmem)) {
> + dev_err(dev, "%pOF: offset %u + raw_len %u exceeds device size %zu\n",
> + child, info.offset, raw_len,
> + nvmem_dev_size(nvmem));
> + of_node_put(info.np);
> + ret = -EINVAL;
> + goto out;
> + }
[Severity: Medium]
Can info.offset + raw_len overflow 32-bit unsigned arithmetic and bypass
the device-size bounds check?
Both info.offset and raw_len are 32-bit, so the sum wraps modulo 2^32
before promotion to size_t even on 64-bit systems (e.g. reg[0] = 0xfffffffc
with raw_len = 8 wraps to 4). The contiguous info.offset + info.raw_len
check below can also wrap on 32-bit architectures.
Because neither nvmem_add_one_cell() nor qfprom_reg_read() checks against
nvmem->size, a wrapped offset leads to out-of-bounds MMIO reads in
qfprom_reg_read(). check_add_overflow() or size_add() avoids this.
> +
> + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> + if (!priv) {
> + of_node_put(info.np);
> + ret = -ENOMEM;
> + goto out;
> + }
> +
> + priv->byte_mask = byte_mask;
> + priv->raw_len = raw_len;
> + priv->dev = dev;
> + info.raw_len = raw_len;
> + info.read_post_process = qcom_eth_mac_post_process;
> + info.priv = priv;
[Severity: High]
Can qcom_eth_mac_post_process() hit a use-after-free on priv and
priv->dev?
priv is devm-allocated on &layout->dev and caches priv->dev = dev, but
nvmem_add_one_cell() attaches it to nvmem->cells, which outlives
layout->dev. On driver unbind or rmmod, nvmem_layout_unregister() is a
no-op that leaves cells in sysfs while devres_release_all() frees priv.
Any later read of the sysfs cell file then runs
qcom_eth_mac_post_process() on freed priv, passing stale p->raw_len to
kmemdup() and freed p->dev to dev_dbg(). Partial probe failure in
qcom_eth_mac_add_cells() exposes earlier cells with freed priv as well.
[ ... ]
> + /*
> + * Mark the cell fwnode as not-a-device so fw_devlink stops
> + * blocking ethernet on this supplier link. Must be called
> + * after nvmem_add_one_cell() so the fwnode exists.
> + * fw_devlink_refresh_fwnode() cannot be used here because the
> + * efuse device is still in probe and not yet DL_DEV_DRIVER_BOUND.
> + */
> + fw_devlink_purge_absent_suppliers(of_fwnode_handle(child));
[Severity: Medium]
Does calling fw_devlink_purge_absent_suppliers() here break managed
device links between layout->dev and its Ethernet consumers?
fw_devlink_purge_absent_suppliers() deletes consumer fwnode links on each
cell before device_links_driver_bound(&layout->dev) can adopt them via
fw_devlink_pickup_dangling_consumers(). Without those managed links,
unbind, suspend/resume, and shutdown ordering for consumers is lost.
Purging links mid-loop while layout->dev.driver is already set also lets
consumers of earlier cells probe before remaining cells are added, and
leaves those cell fwnodes permanently mutated if a later iteration fails.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-nvmem-byte-mask-for-split-macaddr-v5-0-13c12a99383f@oss.qualcomm.com?part=2
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-12-04 6:53 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 6:22 [PATCH v5 0/5] nvmem: add Qualcomm eFuse Ethernet MAC address layout driver Hongmei Xu
2026-12-04 6:22 ` [PATCH v5 1/5] dt-bindings: nvmem: layouts: add Qualcomm eFuse Ethernet MAC layout Hongmei Xu
2026-12-04 6:40 ` sashiko-bot
2026-12-04 6:22 ` [PATCH v5 2/5] nvmem: layouts: add Qualcomm eFuse Ethernet MAC address layout driver Hongmei Xu
2026-12-04 6:53 ` sashiko-bot
2026-12-04 6:22 ` [PATCH v5 3/5] MAINTAINERS: add entry for Qualcomm Ethernet MAC nvmem " Hongmei Xu
2026-12-04 6:22 ` [PATCH v5 4/5] arm64: defconfig: enable NVMEM_LAYOUT_QCOM_ETH_MAC Hongmei Xu
2026-12-04 6:30 ` sashiko-bot
2026-12-04 6:22 ` [PATCH v5 5/5] arm64: dts: qcom: Add eFuse nvmem cells for Ethernet MAC addresses Hongmei Xu
2026-12-04 6:43 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox