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 <[email protected]> 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/[email protected]?part=14
