Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Luca Ceresoli" <luca.ceresoli@bootlin.com>
Cc: dri-devel@lists.freedesktop.org, imx@lists.linux.dev,
	Frank.Li@kernel.org
Subject: Re: [PATCH v4 14/32] drm/bridge: ti-sn65dsi86: protect device resources on unplug
Date: Wed, 25 Nov 2026 18:16:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-233947@kernel.org> (raw)
In-Reply-To: <20261125-drm-bridge-hotplug-v4-14-822722850492@bootlin.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/bridge: ti-sn65dsi86: release action registered on wrong
  device
- [High] drm/bridge: ti-sn65dsi86: unprotected HPD and debugfs callbacks
  on unplug
- [Medium] drm/bridge: unchecked devm_add_action() in
  ti_sn_bridge_atomic_pre_enable()
--

commit c57970c3929d58f60b46d5db47153169c16eb129
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>

drm/bridge: ti-sn65dsi86: protect device resources on unplug

This commit wraps hardware accesses in bridge callbacks with
drm_bridge_enter() and drm_bridge_exit(), uses a devres action to release
resources acquired in ti_sn_bridge_atomic_pre_enable(), and switches
ti_sn_bridge_remove() to drm_bridge_unplug().

> diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi86.c b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> index 48b83df9aed61..38318113a534f 100644
> --- a/drivers/gpu/drm/bridge/ti-sn65dsi86.c
> +++ b/drivers/gpu/drm/bridge/ti-sn65dsi86.c
[ ... ]
> @@ -1176,26 +1188,57 @@ static void ti_sn_bridge_atomic_enable(struct drm_bridge *bridge,
[ ... ]
> +static void ti_sn_bridge_release_resources(void *data)
> +{
> +	struct ti_sn65dsi86 *pdata = (struct ti_sn65dsi86 *)data;
> +
> +	if (!pdata->refclk)
> +		ti_sn65dsi86_disable_comms(pdata);
> +
> +	pm_runtime_put_sync(pdata->dev);
> +}
>  
>  static void ti_sn_bridge_atomic_pre_enable(struct drm_bridge *bridge,
>  					   struct drm_atomic_commit *state)
>  {
>  	struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge);
> +	int idx;
> +
> +	if (!drm_bridge_enter(bridge, &idx))
> +		return;
>  
>  	pm_runtime_get_sync(pdata->dev);
>  
>  	if (!pdata->refclk)
>  		ti_sn65dsi86_enable_comms(pdata, state);
>  
> +	devm_add_action(pdata->dev, ti_sn_bridge_release_resources, pdata);

[Severity: Medium]
Does an allocation failure in devm_add_action() leak the runtime PM
reference and comms state?

If devm_add_action() fails with -ENOMEM, ti_sn_bridge_release_resources()
is never queued, so a later ti_sn_bridge_atomic_post_disable() hits
WARN_ON(IS_ERR(dr)) in devm_release_action() and skips releasing the
resources.  Using devm_add_action_or_reset() would run
ti_sn_bridge_release_resources() immediately on failure.

> +
>  	/* td7: min 100 us after enable before DSI data */
>  	usleep_range(100, 110);
> +
> +	drm_bridge_exit(idx);
>  }
>  
>  static void ti_sn_bridge_atomic_post_disable(struct drm_bridge *bridge,
>  					     struct drm_atomic_commit *state)
>  {
>  	struct ti_sn65dsi86 *pdata = bridge_to_ti_sn65dsi86(bridge);
> +	int idx;
> +
> +	if (!drm_bridge_enter(bridge, &idx))
> +		return;
>  
>  	/* semi auto link training mode OFF */
>  	regmap_write(pdata->regmap, SN_ML_TX_MODE_REG, 0);
> @@ -1204,17 +1247,21 @@ static void ti_sn_bridge_atomic_post_disable(struct drm_bridge *bridge,
>  	/* disable DP PLL */
>  	regmap_write(pdata->regmap, SN_PLL_ENABLE_REG, 0);
>  
> -	if (!pdata->refclk)
> -		ti_sn65dsi86_disable_comms(pdata);
> +	devm_release_action(pdata->dev, ti_sn_bridge_release_resources, pdata);

[Severity: High]
Should ti_sn_bridge_release_resources() be registered on
&pdata->bridge_aux->dev instead of pdata->dev?

During probe, ti_sn_aux_probe() creates pdata->bridge_aux via
ti_sn65dsi86_add_aux_device() -> __devm_auxiliary_device_create(), which
queues auxiliary_device_destroy() on pdata->dev.  When
ti_sn_bridge_atomic_pre_enable() later registers
ti_sn_bridge_release_resources() on pdata->dev at modeset time, that action
is queued after auxiliary_device_destroy().

Because devres_release_all(pdata->dev) runs actions in reverse order on
parent I2C device unbind, ti_sn_bridge_release_resources() drops the
runtime PM reference and powers down the bridge before
auxiliary_device_destroy() invokes ti_sn_bridge_remove() ->
drm_bridge_unplug(&pdata->bridge).  Bridge callbacks can then still enter
drm_bridge_enter() while the chip is powered off, and a concurrent
ti_sn_bridge_atomic_post_disable() hits WARN_ON(IS_ERR(dr)) in
devm_release_action() once devres_release_all(pdata->dev) has detached the
action list.

Conversely, if the bridge auxiliary device is unbound directly (for example
during ti_sn65dsi86_exit(), which unregisters ti_sn_bridge_driver before
the I2C driver), ti_sn_bridge_remove() calls drm_bridge_unplug() while
ti_sn_bridge_release_resources() stays attached to pdata->dev, preventing
a subsequent ti_sn_bridge_atomic_post_disable() from releasing the runtime
PM reference.

[ ... ]

> @@ -1475,7 +1535,7 @@ static void ti_sn_bridge_remove(struct auxiliary_device *adev)
>  	if (!pdata)
>  		return;
>  
> -	drm_bridge_remove(&pdata->bridge);
> +	drm_bridge_unplug(&pdata->bridge);

[Severity: High]
Are ti_sn_bridge_hpd_enable(), ti_sn_bridge_hpd_disable() and status_show()
still exposed to device resource accesses or runtime PM leaks on unplug?

In DisplayPort mode with an IRQ, ti_sn_bridge_hpd_enable() takes a runtime
PM reference with pm_runtime_get_sync(pdata->dev) and accesses
pdata->regmap until ti_sn_bridge_hpd_disable() runs:

drivers/gpu/drm/bridge/ti-sn65dsi86.c:ti_sn_bridge_hpd_enable() {
	...
	pm_runtime_get_sync(pdata->dev);
	...
	if (client->irq) {
		ret = regmap_set_bits(pdata->regmap, SN_IRQ_EVENTS_EN_REG,
				      HPD_REMOVAL_EN | HPD_INSERTION_EN);
	...
}

Neither HPD callback checks drm_bridge_enter(), and
ti_sn_bridge_hpd_enable() does not register a devres cleanup action for its
runtime PM reference.  If the bridge is unplugged while HPD is enabled, the
runtime PM reference is leaked across device unbind (keeping regulators and
refclk enabled), or a subsequent HPD disable accesses pdata->regmap after
drm_bridge_unplug() completes.

Similarly, status_show() in connector debugfs calls
pm_runtime_get_sync(pdata->dev) and regmap_read(pdata->regmap, ...) without
drm_bridge_enter() and drm_bridge_exit() protection.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=14

  reply	other threads:[~2026-11-25 18:16 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 01/32] drm/display: hdmi-cec-helper: use drmm_ prefix for drmm action Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 02/32] drm/display: hdmi-cec-helper: add non-drmm API variant Luca Ceresoli
2026-11-25 18:08   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 03/32] drm/display: hdmi-cec-notifier-helper: use drmm_ prefix for drmm action Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 04/32] drm/display: hdmi-cec-notifier-helper: add non-drmm API variant Luca Ceresoli
2026-11-25 18:07   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 05/32] drm/connector: split drmm_connector_hdmi_init() in 3 parts Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 06/32] drm/connector: add drm_connector_hdmi_dynamic_init() Luca Ceresoli
2026-11-25 18:10   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 07/32] drm/display: bridge-connector: split allocation code from initialization code Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 08/32] drm/display: bridge-connector: hoist error management to common code Luca Ceresoli
2026-11-25 18:03   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 09/32] drm/display: bridge-connector: use a dynamic connector Luca Ceresoli
2026-11-25 18:21   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 10/32] drm/display: bridge-connector: add APIs to add/remove the connector dynamically Luca Ceresoli
2026-11-25 18:14   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 11/32] drm/bridge: constify of_drm_find_and_get_bridge() device_node parameter Luca Ceresoli
2026-11-25 17:59   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 12/32] drm/bridge: initialize chain_node list head on allocation Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 13/32] drm/bridge: initialize chain_node list head on detach and attach errors Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 14/32] drm/bridge: ti-sn65dsi86: protect device resources on unplug Luca Ceresoli
2026-11-25 18:16   ` sashiko-bot [this message]
2026-11-25 17:50 ` [PATCH v4 15/32] drm/atomic: drm_atomic_private_obj_fini: protect private_obj removal from list Luca Ceresoli
2026-11-25 18:12   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 16/32] drm/probe-helper: add per-connector polling enable/disable Luca Ceresoli
2026-11-25 18:10   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 17/32] drm: event-notifier: add mechanism to notify about hotplug events Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 18/32] drm/bridge: notify about added and detached bridges Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 19/32] drm/mipi-dsi: notify about DSI attach Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 20/32] drm/bridge: add drm_bridge_get_next() and supporting func Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 21/32] drm/panel: implement .get_next_bridge Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 22/32] drm/bridge: display-connector: " Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 23/32] drm/bridge: ti-sn65dsi83: " Luca Ceresoli
2026-11-25 18:14   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 24/32] drm/bridge: ti-sn65dsi86: " Luca Ceresoli
2026-11-25 18:18   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 25/32] drm/bridge: samsung-dsim: " Luca Ceresoli
2026-11-25 18:15   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 26/32] drm/bridge: add drm_bridge_detach_from() Luca Ceresoli
2026-11-25 18:15   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 27/32] drm/atomic: add drm_atomic_shutdown_encoder() Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 28/32] drm/tests: atomic: add tests for drm_atomic_shutdown_encoder() Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 29/32] drm/bridge: clear bridge->encoder on detach Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 30/32] drm/bridge: shutdown encoder and detach downstream bridges on bridge unplug Luca Ceresoli
2026-11-25 18:28   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 31/32] drm: drm_hotplug_helper: new helper to implement bridge hotplug Luca Ceresoli
2026-11-25 18:30   ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 32/32] drm/mxsfb/lcdif: enable " Luca Ceresoli
2026-11-25 18:31   ` 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-233947@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=imx@lists.linux.dev \
    --cc=luca.ceresoli@bootlin.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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