From: sashiko-bot@kernel.org
To: "AngeloGioacchino Del Regno" <angelogioacchino.delregno@collabora.com>
Cc: robh@kernel.org, olteanv@gmail.com, conor+dt@kernel.org,
devicetree@vger.kernel.org, vkoul@kernel.org,
linux-phy@lists.infradead.org, neil.armstrong@linaro.org,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 04/12] phy: phy-mtk-dp: Migrate register offsets to SoC specific pdata
Date: Thu, 10 Sep 2026 09:40:35 +0000 [thread overview]
Message-ID: <20260910094036.3D43B1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260910092038.48291-5-angelogioacchino.delregno@collabora.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] Missing NULL check for `device_get_match_data()` leads to a NULL pointer dereference on manual sysfs bind.
- [High] Overlapping devicetree reg property and hardcoded offset prevents successful DT probe.
Pre-existing issues:
- [High] Potential NULL pointer dereference when accessing `dev->platform_data` prior to validation.
--
commit 6b41d18c7c7f31b8549b66b4262af72e2486491d
Author: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
phy: phy-mtk-dp: Migrate register offsets to SoC specific pdata
In preparation for adding support for newer SoCs and for adding
more capabilities to this driver in an efficient manner, migrate
all of the hardcoded register offsets to SoC specific pdata and
assign that for both DT and platform probing.
> diff --git a/drivers/phy/mediatek/phy-mtk-dp.c b/drivers/phy/mediatek/phy-mtk-dp.c
> index d241004e28286..20974650d9409 100644
> --- a/drivers/phy/mediatek/phy-mtk-dp.c
> +++ b/drivers/phy/mediatek/phy-mtk-dp.c
[ ... ]
> @@ -170,12 +241,19 @@ static void mtk_dp_phy_legacy_remove_lookup(void *data)
> phy_remove_lookup(phy, "dp", dev_name(dp_phy->dev));
> }
>
> +static const struct mtk_dp_phy_pdata mt8195_dp_phy_data;
> +
> static int mtk_dp_phy_legacy_probe(struct platform_device *pdev, struct mtk_dp_phy *dp_phy)
> {
> struct device *dev = &pdev->dev;
> struct phy *phy;
> int ret;
>
> + /*
> + * If legacy platform driver probe, assume this is MT8195 or compatible
> + * with a devicetree that was not migrated to the new, proper bindings.
> + */
> + dp_phy->pdata = &mt8195_dp_phy_data;
> dp_phy->regmap = *(struct regmap **)dev->platform_data;
> if (!dp_phy->regmap)
> return dev_err_probe(dev, -EINVAL, "No platform data available\n");
[Severity: High]
This isn't a bug introduced by this patch, but can this dereference
dev->platform_data before checking if it is NULL?
If the driver is manually bound via sysfs or a module without platform data
provided, it looks like it would crash immediately here:
drivers/phy/mediatek/phy-mtk-dp.c:mtk_dp_phy_legacy_probe() {
...
dp_phy->regmap = *(struct regmap **)dev->platform_data;
if (!dp_phy->regmap)
return dev_err_probe(dev, -EINVAL, "No platform data available\n");
...
}
[ ... ]
> @@ -235,6 +313,8 @@ static int mtk_dp_phy_probe(struct platform_device *pdev)
> if (ret)
> return ret;
>
> + dp_phy->pdata = device_get_match_data(dev);
> +
> phy = devm_phy_create(dev, NULL, &mtk_dp_phy_dev_ops);
> if (IS_ERR(phy))
> return dev_err_probe(dev, PTR_ERR(phy),
[Severity: High]
Could this result in a NULL pointer dereference?
If the driver is manually bound (e.g., via driver_override in sysfs) to a
device that possesses an of_node but does not match any entry in
mtk_dp_phy_of_match, device_get_match_data() will return NULL.
This NULL pointer would later be dereferenced when accessing dp_phy->pdata
in mtk_dp_phy_init().
[ ... ]
> @@ -249,8 +329,15 @@ static int mtk_dp_phy_probe(struct platform_device *pdev)
> return 0;
> }
>
> +static const struct mtk_dp_phy_pdata mt8195_dp_phy_data = {
> + .off_dig_glb = 0x1000,
> + .off_dig_lane = (const u16[]) { 0x1100, 0x1200, 0x1300, 0x1400 },
> + .regs_dig_glb = mt8195_phy_dig_glb_regs,
> + .regs_dig_lane = mt8195_phy_dig_lane_regs,
> +};
> +
[Severity: High]
Will these hardcoded offsets prevent a successful devicetree probe?
The driver maps its devicetree reg resource using
devm_platform_ioremap_resource() in mtk_dp_phy_probe():
drivers/phy/mediatek/phy-mtk-dp.c:mtk_dp_phy_probe() {
...
base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(base))
return PTR_ERR(base);
...
}
If the DT reg maps the specific PHY region, the driver will still add
0x1000 to the mapped base, accessing unmapped physical memory.
If the DT reg maps the entire DP controller region to make the offsets work,
devm_platform_ioremap_resource() will fail with -EBUSY because the parent DP
driver already holds the request_mem_region lock.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260910092038.48291-1-angelogioacchino.delregno@collabora.com?part=4
next prev parent reply other threads:[~2026-09-10 9:40 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 9:20 [PATCH v4 00/12] PHY: MediaTek DP PHY refactor and MT8196 eDP AngeloGioacchino Del Regno
2026-09-10 9:20 ` [PATCH v4 01/12] dt-bindings: phy: Document MT8195 and MT8196 DisplayPort PHYs AngeloGioacchino Del Regno
2026-09-10 9:37 ` sashiko-bot
2026-09-10 9:20 ` [PATCH v4 02/12] phy: phy-mtk-dp: Rename regs to regmap in struct mtk_dp_phy AngeloGioacchino Del Regno
2026-09-10 9:20 ` [PATCH v4 03/12] phy: phy-mtk-dp: Allow probing with devicetree match AngeloGioacchino Del Regno
2026-09-10 9:41 ` sashiko-bot
2026-09-10 9:20 ` [PATCH v4 04/12] phy: phy-mtk-dp: Migrate register offsets to SoC specific pdata AngeloGioacchino Del Regno
2026-09-10 9:40 ` sashiko-bot [this message]
2026-09-10 9:20 ` [PATCH v4 05/12] phy: phy-mtk-dp: Implement power_on and power_off PHY callbacks AngeloGioacchino Del Regno
2026-09-11 5:17 ` Manivannan Sadhasivam
2026-09-10 9:20 ` [PATCH v4 06/12] phy: phy-mtk-dp: Support set_lanes in configure and properly cleanup AngeloGioacchino Del Regno
2026-09-10 9:30 ` sashiko-bot
2026-09-11 5:17 ` Manivannan Sadhasivam
2026-09-10 9:20 ` [PATCH v4 07/12] phy: phy-mtk-dp: Support setting volt swing and preemphasis values AngeloGioacchino Del Regno
2026-09-10 9:20 ` [PATCH v4 08/12] phy: phy-mtk-dp: Add support for digital and analog calibration AngeloGioacchino Del Regno
2026-09-10 9:35 ` sashiko-bot
2026-09-11 5:19 ` Manivannan Sadhasivam
2026-09-10 9:20 ` [PATCH v4 09/12] phy: phy-mtk-dp: Rewrite and document default driving param macros AngeloGioacchino Del Regno
2026-09-10 9:20 ` [PATCH v4 10/12] phy: phy-mtk-dp: Add bitrate register val definitions to SoC data AngeloGioacchino Del Regno
2026-09-10 9:20 ` [PATCH v4 11/12] phy: phy-mtk-dp: Add PHYD Lane EN register mask " AngeloGioacchino Del Regno
2026-09-11 5:20 ` Manivannan Sadhasivam
2026-09-10 9:20 ` [PATCH v4 12/12] phy: phy-mtk-dp: Add support for MT8196 eDP PHY AngeloGioacchino Del Regno
2026-09-13 10:56 ` [PATCH v4 00/12] PHY: MediaTek DP PHY refactor and MT8196 eDP 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=20260910094036.3D43B1F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.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