[PATCH] drm/mipi-dsi: Fix device node leak in of_mipi_dsi_device_add()

Wentao Liang posted 1 patch 1 week, 1 day ago
drivers/gpu/drm/drm_mipi_dsi.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH] drm/mipi-dsi: Fix device node leak in of_mipi_dsi_device_add()
Posted by Wentao Liang 1 week, 1 day ago
of_mipi_dsi_device_add() takes a reference on the DSI device node with
of_node_get() and hands it to mipi_dsi_device_register_full() via the
device info. On success the reference is transferred to the newly
created device, but if mipi_dsi_device_register_full() fails, for
instance because the channel number is invalid, the DSI device cannot
be allocated or device_add() fails, the reference is never dropped and
the device node leaks.

Drop the reference when mipi_dsi_device_register_full() returns an
error.

Fixes: c63ae8a9686b ("drm/dsi: Use mipi_dsi_device_register_full() for DSI device creation")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/gpu/drm/drm_mipi_dsi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index 0390e14d3157..16c0682f8a99 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -162,6 +162,7 @@ static struct mipi_dsi_device *
 of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
 {
 	struct mipi_dsi_device_info info = { };
+	struct mipi_dsi_device *dsi;
 	int ret;
 	u32 reg;
 
@@ -180,7 +181,11 @@ of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
 	info.channel = reg;
 	info.node = of_node_get(node);
 
-	return mipi_dsi_device_register_full(host, &info);
+	dsi = mipi_dsi_device_register_full(host, &info);
+	if (IS_ERR(dsi))
+		of_node_put(node);
+
+	return dsi;
 }
 #else
 static struct mipi_dsi_device *
-- 
2.34.1