From: sashiko-bot@kernel.org
To: "AngeloGioacchino Del Regno" <angelogioacchino.delregno@collabora.com>
Cc: vkoul@kernel.org, devicetree@vger.kernel.org, robh@kernel.org,
neil.armstrong@linaro.org, linux-phy@lists.infradead.org,
conor+dt@kernel.org, olteanv@gmail.com
Subject: Re: [PATCH v4 2/2] phy: mediatek: Add support for PCI-Express Gen4 S-PHY
Date: Tue, 15 Sep 2026 10:26:29 +0000 [thread overview]
Message-ID: <20260915102629.EFF231F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260915101022.23852-3-angelogioacchino.delregno@collabora.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] phy: mediatek: endianness bug when reading split NVMEM cells in mtk_pcie_sphy_get_one_cal_para()
--
commit ab276d5dc9414b3b5618ea96c84dcc086bdf9036
Author: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
phy: mediatek: Add support for PCI-Express Gen4 S-PHY
This commit introduces the driver for the PCI-Express Gen4 S-PHY found in
recent MediaTek SoCs such as MT6991 and MT8196. It implements the PHY
initialization routines and handles reading eFuse calibration data from
the NVMEM framework.
> diff --git a/drivers/phy/mediatek/phy-mtk-pcie-sphy.c b/drivers/phy/mediatek/phy-mtk-pcie-sphy.c
> new file mode 100644
> index 0000000000000..2bf10346ea97a
> --- /dev/null
> +++ b/drivers/phy/mediatek/phy-mtk-pcie-sphy.c
[ ... ]
> +static int mtk_pcie_sphy_get_one_cal_para(struct device *dev, const char *name, u8 max_val)
> +{
> + u16 buf;
> + u8 tmp;
> + int ret;
> +
> + /*
> + * All of the calibrations are always max 8 bits long, but some may
> + * be split between two different 8-bits cells: handle this corner
> + * case by retrying reading as u16.
> + */
> + ret = nvmem_cell_read_u8(dev, name, &tmp);
> + if (ret == 0)
> + buf = tmp;
> + else
> + ret = nvmem_cell_read_u16(dev, name, &buf);
[Severity: Medium]
When an 8-bit (or smaller) NVMEM cell crosses a byte boundary in hardware,
the NVMEM core evaluates its length as 2 bytes, causing nvmem_cell_read_u8()
to fail with -EINVAL.
Does falling back to nvmem_cell_read_u16() cause an endianness issue here?
Because the NVMEM core populates the buffer with a direct memory copy, the
shifted valid data is placed in the first byte and zeroes in the second byte.
On big-endian architectures, interpreting this buffer directly as a native
u16 variable evaluates to buf[0] << 8, which effectively multiplies the
calibration value by 256. This could lead to spurious -ERANGE failures or
incorrect calibration values being written to the PHY.
Would it be safer to use nvmem_cell_read_variable_le_u32() to handle these
split cells robustly across different architectures?
> +
> + if (ret == -ENOENT) {
> + dev_info(dev, "No calibration for %s. Using defaults\n", name);
> + return -ENOENT;
> + } else if (ret)
> + return dev_err_probe(dev, ret,
> + "Cannot get calibration data for %s\n", name);
> +
> + if (buf > max_val)
> + return dev_err_probe(dev, -ERANGE,
> + "Bad value %u retrieved for %s.\n", buf, name);
> +
> + return buf;
> +}
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260915101022.23852-1-angelogioacchino.delregno@collabora.com?part=2
--
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy
next prev parent reply other threads:[~2026-09-15 10:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 10:10 [PATCH v4 0/2] PHY: Add MediaTek PCI-Express Gen4 S-PHY Driver AngeloGioacchino Del Regno
2026-09-15 10:10 ` [PATCH v4 1/2] dt-bindings: phy: Document MT8196 MediaTek PCI-Express Gen4 S-PHY AngeloGioacchino Del Regno
2026-09-15 10:18 ` sashiko-bot
2026-09-15 10:58 ` AngeloGioacchino Del Regno
2026-09-15 10:10 ` [PATCH v4 2/2] phy: mediatek: Add support for " AngeloGioacchino Del Regno
2026-09-15 10:26 ` sashiko-bot [this message]
2026-09-15 10:59 ` AngeloGioacchino Del Regno
2026-10-05 10:20 ` [PATCH v4 0/2] PHY: Add MediaTek PCI-Express Gen4 S-PHY Driver Vinod Koul
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=20260915102629.EFF231F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-phy@lists.infradead.org \
--cc=neil.armstrong@linaro.org \
--cc=olteanv@gmail.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vkoul@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox