All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sebastian Reichel" <sebastian.reichel@collabora.com>
Cc: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v12 02/23] drm/bridge: synopsys: dw-dp: Fix incorrect resource lifetimes in bind callback
Date: Sat, 14 Nov 2026 05:35:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-214184@kernel.org> (raw)
In-Reply-To: <20261114-synopsys-dw-dp-improvements-v12-2-d42d3dc5bdd4@collabora.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/rockchip: dw_dp: bridge not detached on unbind in
  dw_dp_rockchip_unbind()
- [Medium] drm/bridge: dw-dp: disable_irq() in dw_dp_bridge_detach()
  starves AUX transfers
- [Low] drm/bridge: dw-dp: missing struct platform_device forward
  declaration
--

commit a9596a762ddd1d48c8d46fe4311e13805a449537
Author: Sebastian Reichel <sebastian.reichel@collabora.com>

drm/bridge: synopsys: dw-dp: Fix incorrect resource lifetimes in bind callback

This commit moves the DesignWare DP controller's devm-managed resource
allocation and bridge registration from dw_dp_bind() into a new
dw_dp_probe() helper, leaving only drm_bridge_attach() in dw_dp_bind() and
enabling the interrupt only while the bridge is attached.

> diff --git a/drivers/gpu/drm/bridge/synopsys/dw-dp.c b/drivers/gpu/drm/bridge/synopsys/dw-dp.c
> index 0a34d6a6ace46..ac16d290d49be 100644
> --- a/drivers/gpu/drm/bridge/synopsys/dw-dp.c
> +++ b/drivers/gpu/drm/bridge/synopsys/dw-dp.c
> @@ -1827,16 +1827,22 @@ static int dw_dp_bridge_attach(struct drm_bridge *bridge,
>  	dp->aux.transfer = dw_dp_aux_transfer;
>  
>  	ret = drm_dp_aux_register(&dp->aux);
> -	if (ret)
> +	if (ret) {
>  		dev_err(dev, "Aux register failed: %d\n", ret);
> +		return ret;
> +	}
>  
> -	return ret;
> +	enable_irq(dp->irq);
> +
> +	return 0;
>  }
>  
>  static void dw_dp_bridge_detach(struct drm_bridge *bridge)
>  {
>  	struct dw_dp *dp = bridge_to_dp(bridge);
>  
> +	disable_irq(dp->irq);
> +	cancel_work_sync(&dp->hpd_work);
>  	drm_dp_aux_unregister(&dp->aux);
>  }

[Severity: Medium]
Does calling disable_irq(dp->irq) before cancel_work_sync(&dp->hpd_work)
and drm_dp_aux_unregister(&dp->aux) starve in-flight AUX transfers?

Both HPD_EVENT and AUX_REPLY_EVENT share dp->irq, and dw_dp_aux_transfer()
waits on dp->complete, which is signaled from dw_dp_irq().  If
dw_dp_hpd_work() or a /dev/drm_dp_aux* transaction is running when
dw_dp_bridge_detach() disables dp->irq, AUX_REPLY_EVENT is never delivered
and every DPCD retry in drm_dp_dpcd_access() stalls until
wait_for_completion_timeout() expires.

[ ... ]

> @@ -1982,6 +1988,18 @@ static const struct regmap_config dw_dp_regmap_config = {
>  	.rd_table = &dw_dp_readable_table,
>  };
>  
> +int dw_dp_bind(struct dw_dp *dp, struct drm_encoder *encoder)
> +{
> +	return drm_bridge_attach(encoder, &dp->bridge, NULL, DRM_BRIDGE_ATTACH_NO_CONNECTOR);
> +}
> +EXPORT_SYMBOL_GPL(dw_dp_bind);
> +
> +void dw_dp_unbind(struct dw_dp *dp)
> +{
> +	/* nothing to do as bridge is detached automatically */
> +}
> +EXPORT_SYMBOL_GPL(dw_dp_unbind);

[ ... ]

> diff --git a/drivers/gpu/drm/rockchip/dw_dp-rockchip.c b/drivers/gpu/drm/rockchip/dw_dp-rockchip.c
> index b23efb153c9e6..38e8fe75718e4 100644
> --- a/drivers/gpu/drm/rockchip/dw_dp-rockchip.c
> +++ b/drivers/gpu/drm/rockchip/dw_dp-rockchip.c

[ ... ]

> @@ -73,37 +73,28 @@ static const struct drm_encoder_helper_funcs dw_dp_encoder_helper_funcs = {
>  
>  static int dw_dp_rockchip_bind(struct device *dev, struct device *master, void *data)
>  {
> -	struct platform_device *pdev = to_platform_device(dev);
> -	const struct dw_dp_plat_data *plat_data;
> +	struct rockchip_dw_dp *dp = dev_get_drvdata(dev);
>  	struct drm_device *drm_dev = data;
> -	struct rockchip_dw_dp *dp;
>  	struct drm_encoder *encoder;
>  	struct drm_connector *connector;
>  	int ret;
>  
> -	dp = drmm_kzalloc(drm_dev, sizeof(*dp), GFP_KERNEL);
> -	if (!dp)
> +	dp->encoder = drmm_kzalloc(drm_dev, sizeof(*dp->encoder), GFP_KERNEL);
> +	if (!dp->encoder)
>  		return -ENOMEM;
>  
> -	dp->dev = dev;
> -	platform_set_drvdata(pdev, dp);
> -
> -	plat_data = of_device_get_match_data(dev);
> -	if (!plat_data)
> -		return -ENODEV;
> -
> -	encoder = &dp->encoder.encoder;
> +	encoder = &dp->encoder->encoder;
>  	encoder->possible_crtcs = drm_of_find_possible_crtcs(drm_dev, dev->of_node);
> -	rockchip_drm_encoder_set_crtc_endpoint_id(&dp->encoder, dev->of_node, 0, 0);
> +	rockchip_drm_encoder_set_crtc_endpoint_id(dp->encoder, dev->of_node, 0, 0);
>  
>  	ret = drmm_encoder_init(drm_dev, encoder, NULL, DRM_MODE_ENCODER_TMDS, NULL);
>  	if (ret)
>  		return ret;
>  	drm_encoder_helper_add(encoder, &dw_dp_encoder_helper_funcs);
>  
> -	dp->base = dw_dp_bind(dev, encoder, plat_data);
> -	if (IS_ERR(dp->base))
> -		return PTR_ERR(dp->base);
> +	ret = dw_dp_bind(dp->base, encoder);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "failed to bind DW-DP bridge\n");
>  
>  	connector = drm_bridge_connector_init(drm_dev, encoder);
>  	if (IS_ERR(connector)) {

[Severity: High]
Does keeping drmm_encoder_init() while making dw_dp_unbind() a no-op leave
dp->bridge attached across component unbind?

drmm_encoder_init() defers drm_encoder_cleanup() -> drm_bridge_detach() ->
dw_dp_bridge_detach() until the final drm_device reference drops in
drm_managed_release().  If the component is unbound while userspace holds
an open file descriptor to /dev/dri/card*, drm_dev_put() in
rockchip_drm_unbind() does not release drm_dev:

- If the dw-dp platform device is then removed, devres_release_all() frees
  dp->irq, dp->regmap, MMIO, clocks and dp->phy while dw_dp_bridge_detach()
  has not run, leaving dp->hpd_work and dp->aux active against freed
  resources (use-after-free) and later calling disable_irq() on a freed IRQ
  when the DRM fd closes.
- If the component is rebound while the old DRM fd is still open,
  dp->bridge.dev is still non-NULL and drm_bridge_attach() in dw_dp_bind()
  fails with -EBUSY.
- If drm_bridge_connector_init() or a later component's bind fails, the
  error path calls the no-op dw_dp_unbind(), leaving dp->irq enabled and
  dp->aux registered while earlier components are unbound.

Initializing the encoder with drm_encoder_init() and calling
drm_encoder_cleanup() in dw_dp_rockchip_unbind() and on the
drm_bridge_connector_init() error path (as analogix_dp-rockchip.c and
cdn-dp-core.c do) would detach the bridge synchronously at unbind time.

[ ... ]

> diff --git a/include/drm/bridge/dw_dp.h b/include/drm/bridge/dw_dp.h
> index 22105c3e8e4d6..a82412a9e7695 100644
> --- a/include/drm/bridge/dw_dp.h
> +++ b/include/drm/bridge/dw_dp.h
> @@ -22,7 +22,8 @@ struct dw_dp_plat_data {
>  	u8 pixel_mode;
>  };
>  
> -struct dw_dp *dw_dp_bind(struct device *dev, struct drm_encoder *encoder,
> -			 const struct dw_dp_plat_data *plat_data);
> +int dw_dp_bind(struct dw_dp *dp, struct drm_encoder *encoder);
>  void dw_dp_unbind(struct dw_dp *dp);
> +
> +struct dw_dp *dw_dp_probe(struct platform_device *pdev, const struct dw_dp_plat_data *plat_data);
>  #endif /* __DW_DP__ */

[Severity: Low]
Does include/drm/bridge/dw_dp.h need a forward declaration for struct
platform_device?

This header only includes <linux/device.h> and forward-declares struct
drm_encoder and struct dw_dp, so compiling it standalone (e.g. with
CONFIG_DRM_HEADER_TEST=y) or before <linux/platform_device.h> triggers a
-Wvisibility warning on dw_dp_probe().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261114-synopsys-dw-dp-improvements-v12-0-d42d3dc5bdd4@collabora.com?part=2

  reply	other threads:[~2026-11-14  5:35 UTC|newest]

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