Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sebastian Reichel" <sebastian.reichel@collabora.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org,
	dri-devel@lists.freedesktop.org, robh@kernel.org
Subject: Re: [PATCH v11 14/21] drm/bridge: synopsys: dw-dp: Add Runtime PM support
Date: Thu, 06 Aug 2026 17:41:36 +0000	[thread overview]
Message-ID: <20260806174137.006971F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260806-synopsys-dw-dp-improvements-v11-14-0d508505f383@collabora.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Devm action unmasks the IRQ during driver unload due to skipped runtime suspend, creating a Use-After-Free window.
- [Medium] Asynchronous pm_runtime_put_autosuspend() in teardown paths races with pm_runtime_disable(), leaving the device powered on.
- [Medium] The return value of dw_dp_runtime_resume() is ignored in dw_dp_probe() when runtime PM is disabled.
--

--- Patch [14]: [PATCH v11 14/21] drm/bridge: synopsys: dw-dp: Add Runtime PM support ---
commit af390b7b3091a44b56036dc11fc278ff1a6d55a3
Author: Sebastian Reichel <sebastian.reichel@collabora.com>
Subject: drm/bridge: synopsys: dw-dp: Add Runtime PM support

This commit adds runtime power management stubs to the Synopsys DesignWare
DisplayPort bridge driver. It splits the probe function to allow platform
drivers to assign it early so that runtime events can be properly routed.

> diff --git a/drivers/gpu/drm/bridge/synopsys/dw-dp.c b/drivers/gpu/drm/bridge/synopsys/dw-dp.c
> index 3af5b1f643c10..31f944e143ea5 100644
> --- a/drivers/gpu/drm/bridge/synopsys/dw-dp.c
> +++ b/drivers/gpu/drm/bridge/synopsys/dw-dp.c
> @@ -1931,6 +1963,9 @@ static int dw_dp_bridge_attach(struct drm_bridge *bridge,
>  
>  	drm_dp_aux_unregister(&dp->aux);
>  
> +err_runtime_pm_put:
> +	pm_runtime_put_autosuspend(dp->dev);
> +
>  	return ret;
>  }
>  
> @@ -1941,6 +1976,9 @@ static void dw_dp_bridge_detach(struct drm_bridge *bridge)
>  	disable_irq(dp->irq);
>  	cancel_work_sync(&dp->hpd_work);
>  	drm_dp_aux_unregister(&dp->aux);
> +
> +	if (!dp->usbc_mode)
> +		pm_runtime_put_autosuspend(dp->dev);
>  }

[Severity: Medium]
Will this asynchronous pm_runtime_put_autosuspend() race with
pm_runtime_disable() during device removal or probe failure?

In dw_dp_bridge_detach() and the error path of dw_dp_bridge_attach(), the
driver drops its runtime reference using an asynchronous put. However,
during component teardown or probe failure, this is quickly followed by the
devm cleanup phase, which calls pm_runtime_disable() (registered via
devm_pm_runtime_enable() in probe).

According to power management guidelines, pm_runtime_disable() cancels any
pending asynchronous suspend timers. Because the put was asynchronous and the
timer is cancelled before it expires, the device remains in the RPM_ACTIVE
state and is never physically suspended, causing a power leak.

Could a synchronous put (like pm_runtime_put_sync()) be used here instead?

[ ... ]

> @@ -2205,41 +2280,67 @@ struct dw_dp *dw_dp_probe(struct platform_device *pdev, const struct dw_dp_plat_
> +	/*
> +	 * Disable IRQ a second time; this ensures the interrupt is only
> +	 * enabled when the bridge is attached AND runtime PM is enabled.
> +	 * Also register a devm action to restore the correct balance during
> +	 * device removal.
> +	 */
> +	disable_irq(dp->irq);
> +
> +	ret = devm_add_action_or_reset(dev, dw_dp_enable_irq, dp);
> +	if (ret)
> +		return ret;

[Severity: High]
Does this devm action risk a use-after-free by unmasking the interrupt during
driver unload?

The driver uses the interrupt disable depth as a refcount: IRQF_NO_AUTOEN
(depth=1) plus the explicit disable_irq() in probe (depth=2). It expects two
enable_irq() calls (attach and runtime_resume) to reach depth 0.

If the device fails to runtime suspend during teardown (e.g., due to the
pm_runtime_put_autosuspend() cancellation race described above),
dw_dp_runtime_suspend() is skipped, and its corresponding disable_irq() is
missed. When dw_dp_bridge_detach() calls disable_irq(), the depth only
returns to 1. 

Later, the devm cleanup action dw_dp_enable_irq() decrements the depth.
Since the depth was 1, it reaches 0 and physically unmasks the interrupt.

If an interrupt fires in the small window between dw_dp_enable_irq() and
free_irq(), dw_dp_irq() queues dp->hpd_work. Since cancel_work_sync() was
already called in dw_dp_bridge_detach(), this requeues the work on a dp
structure that is about to be freed by devres, resulting in a use-after-free
when the workqueue runs.

> +	if (dp->plat_data.autosuspend_delay > 0) {
> +		pm_runtime_use_autosuspend(dev);
> +		pm_runtime_set_autosuspend_delay(dev, dp->plat_data.autosuspend_delay);
> +		ret = devm_pm_runtime_enable(dev);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	if (!pm_runtime_enabled(dev)) {
> +		dw_dp_runtime_resume(dp);
> +
> +		ret = devm_add_action_or_reset(dev, dw_dp_manual_suspend, dp);
> +		if (ret)
> +			return ret;
> +	}

[Severity: Medium]
Should the return value of dw_dp_runtime_resume() be checked here?

When pm_runtime_enabled(dev) is false, dw_dp_runtime_resume() is called
manually to power up the hardware, but its return value is ignored. If it
fails (for example, if clk_prepare_enable() fails), it aborts early and
leaves resources like aux_clk and the interrupt disabled. 

However, the probe continues and registers the dw_dp_manual_suspend devres
action. During driver teardown, dw_dp_manual_suspend() unconditionally calls
clk_disable_unprepare(dp->aux_clk) and disable_irq(dp->irq). Calling these
on resources that were never enabled triggers subsystem warnings.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260806-synopsys-dw-dp-improvements-v11-0-0d508505f383@collabora.com?part=14

  reply	other threads:[~2026-08-06 17:41 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 17:02 [PATCH v11 00/21] Synopsys DisplayPort Controller improvements for Rockchip platforms Sebastian Reichel
2026-08-06 17:02 ` [PATCH v11 01/21] drm/bridge: synopsys: dw-dp: Register DP AUX on bridge attach Sebastian Reichel
2026-08-06 17:37   ` sashiko-bot
2026-08-06 17:02 ` [PATCH v11 02/21] drm/bridge: synopsys: dw-dp: Fix incorrect resource lifetimes in bind callback Sebastian Reichel
2026-08-06 17:36   ` sashiko-bot
2026-08-06 17:02 ` [PATCH v11 03/21] drm/bridge: synopsys: dw-dp: Fix error handling for DP link enablement Sebastian Reichel
2026-08-06 17:29   ` sashiko-bot
2026-08-06 17:02 ` [PATCH v11 04/21] drm/bridge: synopsys: dw-dp: Document missing reset line deassert Sebastian Reichel
2026-08-06 17:33   ` sashiko-bot
2026-08-06 17:02 ` [PATCH v11 05/21] drm/bridge: synopsys: dw-dp: Add missing mutex cleanups on module removal Sebastian Reichel
2026-08-06 17:30   ` sashiko-bot
2026-08-06 17:02 ` [PATCH v11 06/21] drm/bridge: synopsys: dw-dp: Fix AUX transfer timeout race condition Sebastian Reichel
2026-08-06 17:32   ` sashiko-bot
2026-08-06 17:02 ` [PATCH v11 07/21] drm/bridge: synopsys: dw-dp: Fix support for short I2C reads Sebastian Reichel
2026-08-06 17:02 ` [PATCH v11 08/21] drm/bridge: synopsys: dw-dp: Free output_fmts when none are valid Sebastian Reichel
2026-08-06 17:02 ` [PATCH v11 09/21] drm/bridge: synopsys: dw-dp: Support MEDIA_BUS_FMT_FIXED Sebastian Reichel
2026-08-06 17:33   ` sashiko-bot
2026-08-06 17:02 ` [PATCH v11 10/21] drm/bridge: synopsys: dw-dp: Add follow-up bridge support Sebastian Reichel
2026-08-07  2:50   ` Chaoyi Chen
2026-08-06 17:02 ` [PATCH v11 11/21] drm/bridge: Add out-of-band HPD notify handler Sebastian Reichel
2026-08-06 17:02 ` [PATCH v11 12/21] drm/bridge: synopsys: dw-dp: Support software triggered OOB HPD Sebastian Reichel
2026-08-06 17:02 ` [PATCH v11 13/21] drm/rockchip: dw_dp: Implement out-of-band HPD handling Sebastian Reichel
2026-08-06 17:27   ` sashiko-bot
2026-08-06 17:02 ` [PATCH v11 14/21] drm/bridge: synopsys: dw-dp: Add Runtime PM support Sebastian Reichel
2026-08-06 17:41   ` sashiko-bot [this message]
2026-08-06 17:02 ` [PATCH v11 15/21] drm/rockchip: dw_dp: Add runtime " Sebastian Reichel
2026-08-06 17:45   ` sashiko-bot
2026-08-06 17:02 ` [PATCH v11 16/21] drm/bridge: synopsys: dw-dp: Protect sdp_reg_bank from concurrent access Sebastian Reichel
2026-08-06 17:02 ` [PATCH v11 17/21] drm/bridge: synopsys: dw-dp: Drop useless reservation of first slot Sebastian Reichel
2026-08-06 17:45   ` sashiko-bot
2026-08-06 17:02 ` [PATCH v11 18/21] drm/bridge: synopsys: dw-dp: Clear only enabled SDPs on atomic disable Sebastian Reichel
2026-08-06 17:02 ` [PATCH v11 19/21] drm/bridge: synopsys: dw-dp: Use regmap_set_bits in dw_dp_send_sdp Sebastian Reichel
2026-08-06 17:02 ` [PATCH v11 20/21] dt-bindings: display: rockchip: dw-dp: Fix sound DAI cells Sebastian Reichel
2026-08-06 17:39   ` sashiko-bot
2026-08-07 15:51     ` Rob Herring
2026-08-07 17:58       ` Sebastian Reichel
2026-08-06 17:02 ` [PATCH v11 21/21] drm/bridge: synopsys: dw-dp: Add audio support Sebastian Reichel
2026-08-06 17:44   ` 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=20260806174137.006971F00A3A@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=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sebastian.reichel@collabora.com \
    /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