On 10/9/2023 12:01 PM, Dmitry Baryshkov wrote:
On 09/10/2023 21:51, Abhinav Kumar wrote:On 10/9/2023 11:46 AM, Dmitry Baryshkov wrote:On 09/10/2023 21:39, Abhinav Kumar wrote:On 10/9/2023 11:10 AM, Dmitry Baryshkov wrote:Make MSM DSI driver use devm_drm_bridge_add() instead of plaindrm_bridge_add(). As the driver doesn't require any additional cleanup,stop adding created bridge to the priv->bridges array. Reviewed-by: Rob Clark <robdclark@xxxxxxxxx> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxx> --- drivers/gpu/drm/msm/dsi/dsi.c | 28 +++++-------------------- drivers/gpu/drm/msm/dsi/dsi.h | 3 +--drivers/gpu/drm/msm/dsi/dsi_manager.c | 30 +++++++++------------------3 files changed, 16 insertions(+), 45 deletions(-)diff --git a/drivers/gpu/drm/msm/dsi/dsi.c b/drivers/gpu/drm/msm/dsi/dsi.cindex d45e43024802..47f327e68471 100644 --- a/drivers/gpu/drm/msm/dsi/dsi.c +++ b/drivers/gpu/drm/msm/dsi/dsi.c @@ -215,20 +215,14 @@ void __exit msm_dsi_unregister(void)int msm_dsi_modeset_init(struct msm_dsi *msm_dsi, struct drm_device *dev,struct drm_encoder *encoder) { - struct msm_drm_private *priv = dev->dev_private; int ret; - if (priv->num_bridges == ARRAY_SIZE(priv->bridges)) { - DRM_DEV_ERROR(dev->dev, "too many bridges\n"); - return -ENOSPC; - } - msm_dsi->dev = dev; ret = msm_dsi_host_modeset_init(msm_dsi->host, dev); if (ret) {DRM_DEV_ERROR(dev->dev, "failed to modeset init host: %d\n", ret);- goto fail; + return ret; } if (msm_dsi_is_bonded_dsi(msm_dsi) &&@@ -242,32 +236,20 @@ int msm_dsi_modeset_init(struct msm_dsi *msm_dsi, struct drm_device *dev,msm_dsi->encoder = encoder; - msm_dsi->bridge = msm_dsi_manager_bridge_init(msm_dsi->id); - if (IS_ERR(msm_dsi->bridge)) { - ret = PTR_ERR(msm_dsi->bridge); + ret = msm_dsi_manager_bridge_init(msm_dsi); + if (ret) {DRM_DEV_ERROR(dev->dev, "failed to create dsi bridge: %d\n", ret);- msm_dsi->bridge = NULL; - goto fail; + return ret; } ret = msm_dsi_manager_ext_bridge_init(msm_dsi->id); if (ret) { DRM_DEV_ERROR(dev->dev, "failed to create dsi connector: %d\n", ret); - goto fail; + return ret; } - priv->bridges[priv->num_bridges++] = msm_dsi->bridge; - return 0; -fail: - /* bridge/connector are normally destroyed by drm: */ - if (msm_dsi->bridge) { - msm_dsi_manager_bridge_destroy(msm_dsi->bridge); - msm_dsi->bridge = NULL; - }We can drop msm_dsi_manager_bridge_destroy() now but dont we need to keep the part to reset msm_dsi->bridge to NULL in the fail tag if msm_dsi_manager_ext_bridge_init() fails?What for? This field is not read in the error /unbinding path. I'll send a followup that drops msm_dsi->bridge completely.Not used in the error path. The behavior before this patch was, if msm_dsi_manager_ext_bridge_init failed, it was marking msm_dsi->bridge as NULL. Thats what I thought you would want to retain till you drop the msm_dsi->bridge.Why would you like to keep the useless behaviour?
Not sure whether to call it useless. So msm_dsi_manager_ext_bridge_init() is referencing msm_dsi->bridge. msm_dsi_manager_ext_bridge_init() is an exported API. If someone tries to call it outside of where its called now, this was the only protection against the access?
I guess, you could counter argue that noone calls it that way today.In that sense, I am fine with this, just wanted to report the gap after this patch before I ack.
OR you can even add that line in the if (ret) of msm_dsi_manager_ext_bridge_init(msm_dsi->id); failure.- - return ret; }void msm_dsi_snapshot(struct msm_disp_state *disp_state, struct msm_dsi *msm_dsi) diff --git a/drivers/gpu/drm/msm/dsi/dsi.h b/drivers/gpu/drm/msm/dsi/dsi.hindex d21867da78b8..a01c326774a6 100644 --- a/drivers/gpu/drm/msm/dsi/dsi.h +++ b/drivers/gpu/drm/msm/dsi/dsi.h @@ -56,8 +56,7 @@ struct msm_dsi { }; /* dsi manager */ -struct drm_bridge *msm_dsi_manager_bridge_init(u8 id); -void msm_dsi_manager_bridge_destroy(struct drm_bridge *bridge); +int msm_dsi_manager_bridge_init(struct msm_dsi *msm_dsi); int msm_dsi_manager_ext_bridge_init(u8 id);int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg); bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len); diff --git a/drivers/gpu/drm/msm/dsi/dsi_manager.c b/drivers/gpu/drm/msm/dsi/dsi_manager.cindex 28b8012a21f2..17aa19bb6510 100644 --- a/drivers/gpu/drm/msm/dsi/dsi_manager.c +++ b/drivers/gpu/drm/msm/dsi/dsi_manager.c@@ -466,9 +466,8 @@ static const struct drm_bridge_funcs dsi_mgr_bridge_funcs = {}; /* initialize bridge */ -struct drm_bridge *msm_dsi_manager_bridge_init(u8 id) +int msm_dsi_manager_bridge_init(struct msm_dsi *msm_dsi) { - struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id); struct drm_bridge *bridge = NULL; struct dsi_bridge *dsi_bridge; struct drm_encoder *encoder;@@ -476,31 +475,27 @@ struct drm_bridge *msm_dsi_manager_bridge_init(u8 id)dsi_bridge = devm_kzalloc(msm_dsi->dev->dev, sizeof(*dsi_bridge), GFP_KERNEL); - if (!dsi_bridge) { - ret = -ENOMEM; - goto fail; - } + if (!dsi_bridge) + return -ENOMEM; - dsi_bridge->id = id; + dsi_bridge->id = msm_dsi->id; encoder = msm_dsi->encoder; bridge = &dsi_bridge->base; bridge->funcs = &dsi_mgr_bridge_funcs; - drm_bridge_add(bridge); + ret = devm_drm_bridge_add(&msm_dsi->pdev->dev, bridge); + if (ret) + return ret; ret = drm_bridge_attach(encoder, bridge, NULL, 0); if (ret) - goto fail; + return ret; - return bridge; + msm_dsi->bridge = bridge; -fail: - if (bridge) - msm_dsi_manager_bridge_destroy(bridge); - - return ERR_PTR(ret); + return 0; } int msm_dsi_manager_ext_bridge_init(u8 id) @@ -557,11 +552,6 @@ int msm_dsi_manager_ext_bridge_init(u8 id) return 0; } -void msm_dsi_manager_bridge_destroy(struct drm_bridge *bridge) -{ - drm_bridge_remove(bridge); -} - int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg) { struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);