Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sebastian Reichel" <sebastian.reichel@collabora.com>
Cc: robh@kernel.org, conor+dt@kernel.org,
	dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v10 05/21] drm/bridge: synopsys: dw-dp: Add missing mutex cleanups on module removal
Date: Thu, 06 Aug 2026 00:58:09 +0000	[thread overview]
Message-ID: <20260806005810.5498E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806-synopsys-dw-dp-improvements-v10-5-d84a26c303d6@collabora.com>

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

Pre-existing issues:
- [High] Missing cancellation of asynchronous hpd_work in devres teardown leads to Use-After-Free.
- [High] TOCTOU race in dw_dp_link_retrain() can cause DP link training while the PHY is powered off.
- [High] Missing reinit_completion() in dw_dp_aux_transfer() breaks subsequent AUX transfers after a timeout.
--

--- Patch [5]: [PATCH v10 05/21] drm/bridge: synopsys: dw-dp: Add missing mutex cleanups on module removal ---
commit 58a91370c6467a81d51233b812a70d21f2296081
Author: Sebastian Reichel <sebastian.reichel@collabora.com>

drm/bridge: synopsys: dw-dp: Add missing mutex cleanups on module removal

The driver is currently missing to fully clean up after itself. Ensure
that the mutex is cleaned up.

> diff --git a/drivers/gpu/drm/bridge/synopsys/dw-dp.c b/drivers/gpu/drm/bridge/synopsys/dw-dp.c
> index fd7663013faaa..535af11e617c4 100644
> --- a/drivers/gpu/drm/bridge/synopsys/dw-dp.c
> +++ b/drivers/gpu/drm/bridge/synopsys/dw-dp.c
> @@ -2045,10 +2045,13 @@ struct dw_dp *dw_dp_probe(struct platform_device *pdev, const struct dw_dp_plat_
>  	dp->pixel_mode = plat_data->pixel_mode;
>  	dp->plat_data.max_link_rate = plat_data->max_link_rate;
>  
> -	mutex_init(&dp->irq_lock);
>  	INIT_WORK(&dp->hpd_work, dw_dp_hpd_work);

[Severity: High]
This isn't a bug introduced by this patch, but since we are fixing cleanups
on module removal here, does the asynchronous hpd_work also need to be
canceled during devres teardown?

If the driver is unbound, devm_request_threaded_irq will free the IRQ. If a
hotplug event occurred right before this, hpd_work could be scheduled. Since
there is no devm action to cancel the work, the work handler dw_dp_hpd_work()
could execute after devres has freed the struct dw_dp memory and destroyed
the irq_lock mutex, leading to a use-after-free when it calls
mutex_lock(&dp->irq_lock).

>  	init_completion(&dp->complete);

[Severity: High]
This is also a pre-existing issue, but I noticed dw_dp_aux_transfer() uses
this completion without reinitializing it.

If an AUX transfer times out:

dw_dp_aux_transfer() {
    ...
    regmap_write(dp->regmap, DW_DP_AUX_CMD, value);
    status = wait_for_completion_timeout(&dp->complete, timeout);
    ...
}

wait_for_completion_timeout() returns 0 without consuming the completion's
internal done count. If the hardware interrupt fires shortly after, the
handler calls complete(&dp->complete), leaving the completion in a signaled
state.

Since dw_dp_aux_transfer() does not call reinit_completion() before starting
a new transfer, will the next transfer immediately fall through
wait_for_completion_timeout(), reading stale hardware status?

>  
> +	ret = devm_mutex_init(dev, &dp->irq_lock);
> +	if (ret)
> +		return ERR_PTR(ret);
> +
>  	res = devm_platform_ioremap_resource(pdev, 0);
>  	if (IS_ERR(res))
>  		return ERR_CAST(res);

[Severity: High]
This is another pre-existing issue not introduced by this patch, but looking
at the hpd_work handler, is there a TOCTOU race in dw_dp_link_retrain() that
can cause DP link training while the PHY is powered off?

dw_dp_link_retrain() checks the link state before acquiring the mutex:

dw_dp_link_retrain() {
    if (!dw_dp_needs_link_retrain(dp))
        return 0;
    ...
    drm_modeset_acquire_init(&ctx, 0);
    for (;;) {
        ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
        ...
    }
    if (!ret)
        ret = dw_dp_link_train(dp);
    ...
}

dw_dp_link_retrain() is called asynchronously from hpd_work. Concurrently,
userspace could issue an atomic commit to disable the display, which acquires
connection_mutex and disables the link (powering off the PHY via
dw_dp_link_disable). 

When the atomic commit releases the mutex, dw_dp_link_retrain() acquires it
and unconditionally calls dw_dp_link_train(). Could this result in hardware
lockups from attempting to read or write registers of a powered-off PHY?

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

  reply	other threads:[~2026-08-06  0:58 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06  0:39 [PATCH v10 00/21] Synopsys DisplayPort Controller improvements for Rockchip platforms Sebastian Reichel
2026-08-06  0:39 ` [PATCH v10 01/21] drm/bridge: synopsys: dw-dp: Register DP AUX on bridge attach Sebastian Reichel
2026-08-06  1:02   ` sashiko-bot
2026-08-06  0:39 ` [PATCH v10 02/21] drm/bridge: synopsys: dw-dp: Fix incorrect resource lifetimes in bind callback Sebastian Reichel
2026-08-06  1:05   ` sashiko-bot
2026-08-06  0:39 ` [PATCH v10 03/21] drm/bridge: synopsys: dw-dp: Fix error handling for DP link enablement Sebastian Reichel
2026-08-06  0:59   ` sashiko-bot
2026-08-06  0:39 ` [PATCH v10 04/21] drm/bridge: synopsys: dw-dp: Document missing reset line deassert Sebastian Reichel
2026-08-06  0:58   ` sashiko-bot
2026-08-06  0:39 ` [PATCH v10 05/21] drm/bridge: synopsys: dw-dp: Add missing mutex cleanups on module removal Sebastian Reichel
2026-08-06  0:58   ` sashiko-bot [this message]
2026-08-06  0:39 ` [PATCH v10 06/21] drm/bridge: synopsys: dw-dp: Fix AUX transfer timeout race condition Sebastian Reichel
2026-08-06  1:05   ` sashiko-bot
2026-08-06  0:39 ` [PATCH v10 07/21] drm/bridge: synopsys: dw-dp: Fix support for short I2C reads Sebastian Reichel
2026-08-06  0:39 ` [PATCH v10 08/21] drm/bridge: synopsys: dw-dp: Free output_fmts when none are valid Sebastian Reichel
2026-08-06  0:39 ` [PATCH v10 09/21] drm/bridge: synopsys: dw-dp: Support MEDIA_BUS_FMT_FIXED Sebastian Reichel
2026-08-06  0:39 ` [PATCH v10 10/21] drm/bridge: synopsys: dw-dp: Add follow-up bridge support Sebastian Reichel
2026-08-06  1:01   ` sashiko-bot
2026-08-06  0:39 ` [PATCH v10 11/21] drm/bridge: Add out-of-band HPD notify handler Sebastian Reichel
2026-08-06  0:39 ` [PATCH v10 12/21] drm/bridge: synopsys: dw-dp: Support software triggered OOB HPD Sebastian Reichel
2026-08-06  0:39 ` [PATCH v10 13/21] drm/rockchip: dw_dp: Implement out-of-band HPD handling Sebastian Reichel
2026-08-06  0:58   ` sashiko-bot
2026-08-06  0:39 ` [PATCH v10 14/21] drm/bridge: synopsys: dw-dp: Add Runtime PM support Sebastian Reichel
2026-08-06  1:07   ` sashiko-bot
2026-08-06  0:39 ` [PATCH v10 15/21] drm/rockchip: dw_dp: Add runtime " Sebastian Reichel
2026-08-06  1:06   ` sashiko-bot
2026-08-06  0:39 ` [PATCH v10 16/21] drm/bridge: synopsys: dw-dp: Protect sdp_reg_bank from concurrent access Sebastian Reichel
2026-08-06  0:39 ` [PATCH v10 17/21] drm/bridge: synopsys: dw-dp: Drop useless reservation of first slot Sebastian Reichel
2026-08-06  0:39 ` [PATCH v10 18/21] drm/bridge: synopsys: dw-dp: Clear only enabled SDPs on atomic disable Sebastian Reichel
2026-08-06  0:39 ` [PATCH v10 19/21] drm/bridge: synopsys: dw-dp: Use regmap_set_bits in dw_dp_send_sdp Sebastian Reichel
2026-08-06  0:39 ` [PATCH v10 20/21] dt-bindings: display: rockchip: dw-dp: Fix sound DAI cells Sebastian Reichel
2026-08-06  1:06   ` sashiko-bot
2026-08-06  0:39 ` [PATCH v10 21/21] drm/bridge: synopsys: dw-dp: Add audio support Sebastian Reichel
2026-08-06  1:10   ` 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=20260806005810.5498E1F000E9@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