Skip to contentSkip to conversation

drm/bridge: dw-mipi-dsi: Fix bridge leak when host attach fails

PATCH Applied Osama Abdelkader 2 participants 3 messages Apr 3 – Apr 14

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/bridge: dw-mipi-dsi: Fix bridge leak when host attach fails

dw_mipi_dsi_host_attach() and dw_mipi_dsi2_host_attach() call drm_bridge_add() before pdata->host_ops->attach(). If attach fails, the bridge stayed registered without drm_bridge_remove(), leaking the bridge reference and leaving the device on the global bridge list.

Fixes 90910a651123 ("drm/bridge/synopsys: dsi: add ability to have glue-specific attach and detach")
Fixes 0d6d86253fef ("drm/bridge/synopsys: Add MIPI DSI2 host controller bridge")

---
v2:
- Use drm_bridge_remove only in the error paths

---
 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c  | 6 +++++-
 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi2.c | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +5 -1
index ca4dea226f4b..ef7be20a59cd 100644
@@ -345,10 +345,14 @@ static int dw_mipi_dsi_host_attach(struct mipi_dsi_host *host,
 	if (pdata->host_ops && pdata->host_ops->attach) {
 		ret = pdata->host_ops->attach(pdata->priv_data, device);
 		if (ret < 0)
-			return ret;
+			goto err_remove_bridge;
 	}
 
 	return 0;
+
+err_remove_bridge:
+	drm_bridge_remove(&dsi->bridge);
+	return ret;
 }
 
 static int dw_mipi_dsi_host_detach(struct mipi_dsi_host *host,
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi2.c +5 -1
index e6eaf9fd0251..a4bfd3ad166d 100644
@@ -540,10 +540,14 @@ static int dw_mipi_dsi2_host_attach(struct mipi_dsi_host *host,
 	if (pdata->host_ops && pdata->host_ops->attach) {
 		ret = pdata->host_ops->attach(pdata->priv_data, device);
 		if (ret < 0)
-			return ret;
+			goto err_remove_bridge;
 	}
 
 	return 0;
+
+err_remove_bridge:
+	drm_bridge_remove(&dsi2->bridge);
+	return ret;
 }
 
 static int dw_mipi_dsi2_host_detach(struct mipi_dsi_host *host,
Signature · 1 line
2.43.0
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Osama Abdelkader

dw_mipi_dsi_host_attach() and dw_mipi_dsi2_host_attach() call drm_bridge_add() before pdata->host_ops->attach(). If attach fails, the bridge stayed registered without drm_bridge_remove(), leaking the bridge reference and leaving the device on the global bridge list.

Fixes 90910a651123 ("drm/bridge/synopsys: dsi: add ability to have glue-specific attach and detach")
Fixes 0d6d86253fef ("drm/bridge/synopsys: Add MIPI DSI2 host controller bridge")

--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

reviewer Applied
#2 lore raw
In reply to Osama Abdelkader
Quoted 4 lines · Osama Abdelkader

dw_mipi_dsi_host_attach() and dw_mipi_dsi2_host_attach() call drm_bridge_add() before pdata->host_ops->attach(). If attach fails, the bridge stayed registered without drm_bridge_remove(), leaking the bridge reference and leaving the device on the global bridge list.

Applied, thanks!

[1/1] drm/bridge: dw-mipi-dsi: Fix bridge leak when host attach fails

      commit: be19b43f92fae4794f271ed9e338bdbcfa725aa2

Best regards,

Signature · 1 line
Luca Ceresoli <[email protected]>