Skip to contentSkip to conversation

drm/bridge: samsung-dsim: Fix potential double-free in TE GPIO handling

PATCH In review Miaoqian Lin 2 participants 2 messages Aug 4, 2025

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

PATCH 1/1 drm/bridge: samsung-dsim: Fix potential double-free in TE GPIO handling

The devm_gpiod_get_optional() function uses device-managed resources that are automatically cleaned up. The
gpiod_put() calls in both the error path of samsung_dsim_register_te_irq() and in samsung_dsim_unregister_te_irq() are redundant and may lead to double-free when the device is removed.

Fixes e7447128ca4a ("drm: bridge: Generalize Exynos-DSI driver into a Samsung DSIM bridge")
---
 drivers/gpu/drm/bridge/samsung-dsim.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/bridge/samsung-dsim.c +1 -4
index bccc88d25948..6ffaee6b7738 100644
@@ -1691,7 +1691,6 @@ static int samsung_dsim_register_te_irq(struct samsung_dsim *dsi, struct device
 				   IRQF_TRIGGER_RISING | IRQF_NO_AUTOEN, "TE", dsi);
 	if (ret) {
 		dev_err(dsi->dev, "request interrupt failed with %d\n", ret);
-		gpiod_put(dsi->te_gpio);
 		return ret;
 	}
 
@@ -1790,10 +1789,8 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,
 
 static void samsung_dsim_unregister_te_irq(struct samsung_dsim *dsi)
 {
-	if (dsi->te_gpio) {
+	if (dsi->te_gpio)
 		free_irq(gpiod_to_irq(dsi->te_gpio), dsi);
-		gpiod_put(dsi->te_gpio);
-	}
 }
 
 static int samsung_dsim_host_detach(struct mipi_dsi_host *host,
Signature · 1 line
2.35.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Miaoqian Lin

The devm_gpiod_get_optional() function uses device-managed resources that are automatically cleaned up. The
gpiod_put() calls in both the error path of samsung_dsim_register_te_irq() and in samsung_dsim_unregister_te_irq() are redundant and may lead to double-free when the device is removed.

Fixes e7447128ca4a ("drm: bridge: Generalize Exynos-DSI driver into a Samsung DSIM bridge")
Quoted 18 lines
---
  drivers/gpu/drm/bridge/samsung-dsim.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/bridge/samsung-dsim.c +0 -1
index bccc88d25948..6ffaee6b7738 100644
@@ -1691,7 +1691,6 @@ static int samsung_dsim_register_te_irq(struct samsung_dsim *dsi, struct device
  				   IRQF_TRIGGER_RISING | IRQF_NO_AUTOEN, "TE", dsi);
  	if (ret) {
  		dev_err(dsi->dev, "request interrupt failed with %d\n", ret);
-		gpiod_put(dsi->te_gpio);
  		return ret;
  	}
 
@@ -1790,10 +1789,8 @@ static int samsung_dsim_host_attach(struct mipi_dsi_host *host,
 

drivers/gpu/drm/bridge/samsung-dsim.c static int samsung_dsim_host_attach(struct mipi_dsi_host *host, · line 1796

Quoted 10 lines
drivers/gpu/drm/bridge/samsung-dsim.c +1 -3
  static void samsung_dsim_unregister_te_irq(struct samsung_dsim *dsi)
  {
-	if (dsi->te_gpio) {
+	if (dsi->te_gpio)
  		free_irq(gpiod_to_irq(dsi->te_gpio), dsi);
-		gpiod_put(dsi->te_gpio);
-	}
  }
 
  static int samsung_dsim_host_detach(struct mipi_dsi_host *host,

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland