From: sashiko-bot@kernel.org
To: "Hongmei Xu" <hongmei.xu@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v5 2/5] nvmem: layouts: add Qualcomm eFuse Ethernet MAC address layout driver
Date: Fri, 04 Dec 2026 06:53:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-249260@kernel.org> (raw)
In-Reply-To: <20261204-nvmem-byte-mask-for-split-macaddr-v5-2-13c12a99383f@oss.qualcomm.com>
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
next prev parent reply other threads:[~2026-12-04 6:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 13:07 ` Rob Herring (Arm)
2026-12-05 3:21 ` Krzysztof Kozlowski
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 [this message]
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-05 3:19 ` Krzysztof Kozlowski
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-249260@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=hongmei.xu@oss.qualcomm.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.