All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Michal Wilczynski" <m.wilczynski@samsung.com>
Cc: conor+dt@kernel.org, vkoul@kernel.org, olteanv@gmail.com,
	devicetree@vger.kernel.org, robh@kernel.org,
	linux-phy@lists.infradead.org, mfd@lists.linux.dev,
	lee@kernel.org, dri-devel@lists.freedesktop.org,
	neil.armstrong@linaro.org, linux-clk@vger.kernel.org
Subject: Re: [PATCH v2 04/15] drm/bridge: inno-hdmi: Split probe out of bind
Date: Fri, 28 Aug 2026 14:01:16 +0000	[thread overview]
Message-ID: <20260828140117.64C641F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260828-jh7110-clean-send-v2-4-331680c8b9d1@samsung.com>

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

New issues:
- [High] Missing `inno_hdmi_remove` implementation leads to hardware interrupt storms and violates API contract.

Pre-existing issues:
- [Critical] HPD IRQ is requested and enabled before bridge attach, leading to NULL pointer dereference in the interrupt handler.
- [High] Resource leak of devm_-managed allocations during component bind retries.
- [High] TOCTOU race exposing the I2C adapter to userspace before internal initialization completes.
- [High] Use-after-free in the interrupt handler during device teardown due to incorrect devres registration order.
--

commit 355630a3f7bbfe2d55d6902048b35afc6cb4d58d
Author: Michal Wilczynski <m.wilczynski@samsung.com>

drm/bridge: inno-hdmi: Split probe out of bind
    
inno_hdmi_bind() both sets up the bridge and attaches it to a DRM
encoder. A platform whose HDMI controller is a child of a larger device
needs the first half without the second, since it registers as its own
platform driver and lets the DRM core bind the bridge later.
    
Move the setup into a new exported inno_hdmi_probe(), with a matching
inno_hdmi_remove(), and reduce inno_hdmi_bind() to a wrapper around it.
    
No functional change intended.

> Move the setup into a new exported inno_hdmi_probe(), with a matching
> inno_hdmi_remove(), and reduce inno_hdmi_bind() to a wrapper around it.

[Severity: High]
The commit message mentions adding a matching inno_hdmi_remove() function,
but it does not appear to be implemented in this patch.

Without an exported remove function to safely tear down the hardware and
unmask interrupts, could this lead to hardware interrupt storms if the
platform module is removed or the driver is unbound?

> diff --git a/drivers/gpu/drm/bridge/inno-hdmi.c b/drivers/gpu/drm/bridge/inno-hdmi.c
> index 9a62bf59a4033..12fd208d5e852 100644
> --- a/drivers/gpu/drm/bridge/inno-hdmi.c
> +++ b/drivers/gpu/drm/bridge/inno-hdmi.c
[ ... ]
> +struct inno_hdmi *inno_hdmi_probe(struct platform_device *pdev,
> +				  const struct inno_hdmi_plat_data *plat_data)
>  {
> -	struct platform_device *pdev = to_platform_device(dev);
> +	struct device *dev = &pdev->dev;

[Severity: High]
This isn't a bug introduced by this patch, but there appears to be a
time-of-check to time-of-use (TOCTOU) race condition during I2C adapter
registration within this setup path.

In inno_hdmi_i2c_adapter(), devm_i2c_add_adapter() publishes the adapter
to userspace before assigning hdmi->i2c = i2c. If a userspace tool
initiates an I2C transaction concurrently during this small window,
inno_hdmi_i2c_xfer() will attempt to lock i2c->lock using the still-NULL
hdmi->i2c pointer.

Can this lead to a NULL pointer dereference?

[Severity: Critical]
This is a pre-existing issue, but requesting the IRQ before the bridge
is attached seems to cause a crash on decoupled platforms.

During the hardware setup in this path, devm_request_threaded_irq()
requests the hotplug interrupt. If a monitor is already connected, the
interrupt can fire immediately. The handler, inno_hdmi_irq(), unconditionally
calls drm_helper_hpd_irq_event(hdmi->bridge.dev). However, hdmi->bridge.dev
remains NULL until drm_bridge_attach() is called later.

Since this patch explicitly supports decoupled drivers that register
the bridge without immediately attaching it, does this guarantee a boot-time
NULL pointer dereference if a display is connected?

[Severity: High]
This is a pre-existing issue, but there appears to be a devres registration
order issue that leads to a use-after-free.

The IRQ is requested via devm_request_threaded_irq() before the I2C
adapter memory is allocated with devm_kzalloc(). During device teardown,
devres cleans up resources in reverse order, meaning the I2C memory is freed
while the IRQ remains active.

If a hardware interrupt fires during this teardown window,
inno_hdmi_hardirq() will check the dangling pointer and call
inno_hdmi_i2c_irq(), which accesses the already freed memory.

Should the IRQ be requested after all resources it depends on are allocated?

[ ... ]
> +struct inno_hdmi *inno_hdmi_bind(struct device *dev,
> +				 struct drm_encoder *encoder,
> +				 const struct inno_hdmi_plat_data *plat_data)
> +{
> +	struct platform_device *pdev = to_platform_device(dev);
> +	struct inno_hdmi *hdmi;
> +	int ret;
> +
> +	hdmi = inno_hdmi_probe(pdev, plat_data);
> +	if (IS_ERR(hdmi))
> +		return hdmi;
> +
> +	ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL,
> +				DRM_BRIDGE_ATTACH_NO_CONNECTOR);
> +	if (ret)
> +		return ERR_PTR(ret);

[Severity: High]
This isn't a bug introduced by this patch, but if drm_bridge_attach() fails
(for example, due to probe deferral of another bridge), this returns an
error directly without explicitly destroying the devm_ resources allocated
during inno_hdmi_probe().

Since devm_ allocations are tied to the component device's lifetime rather
than the component bind cycle, won't this leak memory and accumulate
duplicate IRQ registrations on each component bind retry?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260828-jh7110-clean-send-v2-0-331680c8b9d1@samsung.com?part=4

WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Michal Wilczynski" <m.wilczynski@samsung.com>
Cc: conor+dt@kernel.org, vkoul@kernel.org, olteanv@gmail.com,
	devicetree@vger.kernel.org, robh@kernel.org,
	linux-phy@lists.infradead.org, mfd@lists.linux.dev,
	lee@kernel.org, dri-devel@lists.freedesktop.org,
	neil.armstrong@linaro.org, linux-clk@vger.kernel.org
Subject: Re: [PATCH v2 04/15] drm/bridge: inno-hdmi: Split probe out of bind
Date: Fri, 28 Aug 2026 14:01:16 +0000	[thread overview]
Message-ID: <20260828140117.64C641F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260828-jh7110-clean-send-v2-4-331680c8b9d1@samsung.com>

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

New issues:
- [High] Missing `inno_hdmi_remove` implementation leads to hardware interrupt storms and violates API contract.

Pre-existing issues:
- [Critical] HPD IRQ is requested and enabled before bridge attach, leading to NULL pointer dereference in the interrupt handler.
- [High] Resource leak of devm_-managed allocations during component bind retries.
- [High] TOCTOU race exposing the I2C adapter to userspace before internal initialization completes.
- [High] Use-after-free in the interrupt handler during device teardown due to incorrect devres registration order.
--

commit 355630a3f7bbfe2d55d6902048b35afc6cb4d58d
Author: Michal Wilczynski <m.wilczynski@samsung.com>

drm/bridge: inno-hdmi: Split probe out of bind
    
inno_hdmi_bind() both sets up the bridge and attaches it to a DRM
encoder. A platform whose HDMI controller is a child of a larger device
needs the first half without the second, since it registers as its own
platform driver and lets the DRM core bind the bridge later.
    
Move the setup into a new exported inno_hdmi_probe(), with a matching
inno_hdmi_remove(), and reduce inno_hdmi_bind() to a wrapper around it.
    
No functional change intended.

> Move the setup into a new exported inno_hdmi_probe(), with a matching
> inno_hdmi_remove(), and reduce inno_hdmi_bind() to a wrapper around it.

[Severity: High]
The commit message mentions adding a matching inno_hdmi_remove() function,
but it does not appear to be implemented in this patch.

Without an exported remove function to safely tear down the hardware and
unmask interrupts, could this lead to hardware interrupt storms if the
platform module is removed or the driver is unbound?

> diff --git a/drivers/gpu/drm/bridge/inno-hdmi.c b/drivers/gpu/drm/bridge/inno-hdmi.c
> index 9a62bf59a4033..12fd208d5e852 100644
> --- a/drivers/gpu/drm/bridge/inno-hdmi.c
> +++ b/drivers/gpu/drm/bridge/inno-hdmi.c
[ ... ]
> +struct inno_hdmi *inno_hdmi_probe(struct platform_device *pdev,
> +				  const struct inno_hdmi_plat_data *plat_data)
>  {
> -	struct platform_device *pdev = to_platform_device(dev);
> +	struct device *dev = &pdev->dev;

[Severity: High]
This isn't a bug introduced by this patch, but there appears to be a
time-of-check to time-of-use (TOCTOU) race condition during I2C adapter
registration within this setup path.

In inno_hdmi_i2c_adapter(), devm_i2c_add_adapter() publishes the adapter
to userspace before assigning hdmi->i2c = i2c. If a userspace tool
initiates an I2C transaction concurrently during this small window,
inno_hdmi_i2c_xfer() will attempt to lock i2c->lock using the still-NULL
hdmi->i2c pointer.

Can this lead to a NULL pointer dereference?

[Severity: Critical]
This is a pre-existing issue, but requesting the IRQ before the bridge
is attached seems to cause a crash on decoupled platforms.

During the hardware setup in this path, devm_request_threaded_irq()
requests the hotplug interrupt. If a monitor is already connected, the
interrupt can fire immediately. The handler, inno_hdmi_irq(), unconditionally
calls drm_helper_hpd_irq_event(hdmi->bridge.dev). However, hdmi->bridge.dev
remains NULL until drm_bridge_attach() is called later.

Since this patch explicitly supports decoupled drivers that register
the bridge without immediately attaching it, does this guarantee a boot-time
NULL pointer dereference if a display is connected?

[Severity: High]
This is a pre-existing issue, but there appears to be a devres registration
order issue that leads to a use-after-free.

The IRQ is requested via devm_request_threaded_irq() before the I2C
adapter memory is allocated with devm_kzalloc(). During device teardown,
devres cleans up resources in reverse order, meaning the I2C memory is freed
while the IRQ remains active.

If a hardware interrupt fires during this teardown window,
inno_hdmi_hardirq() will check the dangling pointer and call
inno_hdmi_i2c_irq(), which accesses the already freed memory.

Should the IRQ be requested after all resources it depends on are allocated?

[ ... ]
> +struct inno_hdmi *inno_hdmi_bind(struct device *dev,
> +				 struct drm_encoder *encoder,
> +				 const struct inno_hdmi_plat_data *plat_data)
> +{
> +	struct platform_device *pdev = to_platform_device(dev);
> +	struct inno_hdmi *hdmi;
> +	int ret;
> +
> +	hdmi = inno_hdmi_probe(pdev, plat_data);
> +	if (IS_ERR(hdmi))
> +		return hdmi;
> +
> +	ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL,
> +				DRM_BRIDGE_ATTACH_NO_CONNECTOR);
> +	if (ret)
> +		return ERR_PTR(ret);

[Severity: High]
This isn't a bug introduced by this patch, but if drm_bridge_attach() fails
(for example, due to probe deferral of another bridge), this returns an
error directly without explicitly destroying the devm_ resources allocated
during inno_hdmi_probe().

Since devm_ allocations are tied to the component device's lifetime rather
than the component bind cycle, won't this leak memory and accumulate
duplicate IRQ registrations on each component bind retry?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260828-jh7110-clean-send-v2-0-331680c8b9d1@samsung.com?part=4

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

  reply	other threads:[~2026-08-28 14:01 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20260828134813eucas1p1bd003a66706ed251017185fc14f13cc9@eucas1p1.samsung.com>
2026-08-28 13:47 ` [PATCH v2 00/15] drm: starfive: jh7110: Enable display subsystem Michal Wilczynski
2026-08-28 13:47   ` Michal Wilczynski
2026-08-28 13:47   ` Michal Wilczynski
2026-08-28 13:47   ` Michal Wilczynski
2026-08-28 13:47   ` [PATCH v2 01/15] dt-bindings: phy: Add starfive,jh7110-inno-hdmi-phy Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:54     ` sashiko-bot
2026-08-28 13:54       ` sashiko-bot
2026-08-28 16:43     ` Conor Dooley
2026-08-28 16:43       ` Conor Dooley
2026-08-28 16:43       ` Conor Dooley
2026-08-28 16:43       ` Conor Dooley
2026-08-28 13:47   ` [PATCH v2 02/15] dt-bindings: display: bridge: Add starfive,jh7110-inno-hdmi-controller Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:54     ` sashiko-bot
2026-08-28 13:54       ` sashiko-bot
2026-08-28 14:04     ` Icenowy Zheng
2026-08-28 14:04       ` Icenowy Zheng
2026-08-28 14:04       ` Icenowy Zheng
2026-08-28 14:04       ` Icenowy Zheng
2026-08-28 16:47     ` Conor Dooley
2026-08-28 16:47       ` Conor Dooley
2026-08-28 16:47       ` Conor Dooley
2026-08-28 16:47       ` Conor Dooley
2026-08-28 13:47   ` [PATCH v2 03/15] dt-bindings: mfd: Add starfive,jh7110-hdmi-subsystem Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:54     ` sashiko-bot
2026-08-28 13:54       ` sashiko-bot
2026-08-28 16:50     ` Conor Dooley
2026-08-28 16:50       ` Conor Dooley
2026-08-28 16:50       ` Conor Dooley
2026-08-28 16:50       ` Conor Dooley
2026-08-28 13:47   ` [PATCH v2 04/15] drm/bridge: inno-hdmi: Split probe out of bind Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 14:01     ` sashiko-bot [this message]
2026-08-28 14:01       ` sashiko-bot
2026-08-28 13:47   ` [PATCH v2 05/15] drm/bridge: inno-hdmi: Allow the register map to come from a parent Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:54     ` sashiko-bot
2026-08-28 13:54       ` sashiko-bot
2026-08-28 13:47   ` [PATCH v2 06/15] drm/bridge: inno-hdmi: Add .disable platform operation Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:57     ` sashiko-bot
2026-08-28 13:57       ` sashiko-bot
2026-08-28 13:47   ` [PATCH v2 07/15] drm/bridge: inno-hdmi: Add .mode_valid " Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:52     ` sashiko-bot
2026-08-28 13:52       ` sashiko-bot
2026-08-28 13:47   ` [PATCH v2 08/15] soc: starfive: Add jh7110-hdmi-subsystem driver Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:59     ` sashiko-bot
2026-08-28 13:59       ` sashiko-bot
2026-08-28 13:47   ` [PATCH v2 09/15] clk: starfive: jh7110-vout: Allow pixel clock rate propagation Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 14:01     ` sashiko-bot
2026-08-28 14:01       ` sashiko-bot
2026-08-28 13:47   ` [PATCH v2 10/15] drm/bridge: starfive: Add JH7110 HDMI controller driver Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:59     ` sashiko-bot
2026-08-28 13:59       ` sashiko-bot
2026-08-28 13:47   ` [PATCH v2 11/15] phy: Add common Innosilicon HDMI PHY helpers Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 14:00     ` sashiko-bot
2026-08-28 14:00       ` sashiko-bot
2026-08-28 13:47   ` [PATCH v2 12/15] phy: rockchip: inno-hdmi: Use the common Innosilicon " Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 14:12     ` sashiko-bot
2026-08-28 14:12       ` sashiko-bot
2026-08-28 13:47   ` [PATCH v2 13/15] phy: starfive: Add jh7110-inno-hdmi-phy driver Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 14:04     ` sashiko-bot
2026-08-28 14:04       ` sashiko-bot
2026-08-28 13:47   ` [PATCH v2 14/15] riscv: dts: starfive: jh7110: Update DT for display subsystem Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 14:06     ` sashiko-bot
2026-08-28 14:06       ` sashiko-bot
2026-08-28 14:06     ` Icenowy Zheng
2026-08-28 14:06       ` Icenowy Zheng
2026-08-28 14:06       ` Icenowy Zheng
2026-08-28 14:06       ` Icenowy Zheng
2026-08-28 13:47   ` [PATCH v2 15/15] MAINTAINERS: Add StarFive JH7110 display subsystem entry Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 13:47     ` Michal Wilczynski
2026-08-28 14:01     ` Icenowy Zheng
2026-08-28 14:01       ` Icenowy Zheng
2026-08-28 14:01       ` Icenowy Zheng
2026-08-28 14:01       ` Icenowy Zheng

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=20260828140117.64C641F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lee@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=m.wilczynski@samsung.com \
    --cc=mfd@lists.linux.dev \
    --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 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.