Skip to contentSkip to conversation

rpi_touchscreen_probe: check for failure case

PATCH In review Navid Emamdoost 2 participants 6 messages Jul 24, 2019 – Jul 26, 2019

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

PATCH 1/1 rpi_touchscreen_probe: check for failure case

of_graph_get_next_endpoint may return NULL, so null check is needed.

---
 drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c +2 -0
index 28c0620dfe0f..2e0977e26fab 100644
@@ -399,6 +399,8 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,
 
 	/* Look up the DSI host.  It needs to probe before we do. */
 	endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
+	if (!endpoint)
+		return -ENODEV;
 	dsi_host_node = of_graph_get_remote_port_parent(endpoint);
 	host = of_find_mipi_dsi_host_by_node(dsi_host_node);
 	of_node_put(dsi_host_node);
Signature · 1 line
2.17.1
#1 lore raw

Hi Navid.

Thanks for your patch.

Quoted 3 lines · Navid Emamdoost

of_graph_get_next_endpoint may return NULL, so null check is needed.

The patch looks fine, but could you please audit the other calls in the probe function. For example of_graph_get_remote_port_parent() may also return NULL.
If you do this then we can have the error handling reviewed in one go, and fixed in one patch.

Sam

Quoted 19 lines
---
 drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c +2 -0
index 28c0620dfe0f..2e0977e26fab 100644
@@ -399,6 +399,8 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,
 
 	/* Look up the DSI host.  It needs to probe before we do. */
 	endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
+	if (!endpoint)
+		return -ENODEV;
 	dsi_host_node = of_graph_get_remote_port_parent(endpoint);
 	host = of_find_mipi_dsi_host_by_node(dsi_host_node);
 	of_node_put(dsi_host_node);
Signature · 1 line
2.17.1
#2 lore raw

PATCH 1/1 drm/panel: check failure cases in the probe func

The following function calls may fail and return NULL, so the null check is added.
of_graph_get_next_endpoint
of_graph_get_remote_port_parent
of_graph_get_remote_port

---
 drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c +9 -0
index 28c0620dfe0f..9484fdb60f68 100644
@@ -399,7 +399,13 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,
 
 	/* Look up the DSI host.  It needs to probe before we do. */
 	endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
+	if (!endpoint)
+		return -ENODEV;
+
 	dsi_host_node = of_graph_get_remote_port_parent(endpoint);
+	if (!dsi_host_node)
+		return -ENODEV;
+
 	host = of_find_mipi_dsi_host_by_node(dsi_host_node);
 	of_node_put(dsi_host_node);
 	if (!host) {
@@ -408,6 +414,9 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,
 	}
 
 	info.node = of_graph_get_remote_port(endpoint);
+	if (!info.node)
+		return -ENODEV;
+
 	of_node_put(endpoint);
 
 	ts->dsi = mipi_dsi_device_register_full(host, &info);
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH] drm/panel: check failure cases in the probe func

Hi Navid.

Thanks for your patch.

Quoted 16 lines · Navid Emamdoost

The following function calls may fail and return NULL, so the null check is added.
of_graph_get_next_endpoint
of_graph_get_remote_port_parent
of_graph_get_remote_port

---
 drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c +0 -0
index 28c0620dfe0f..9484fdb60f68 100644

drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c static int rpi_touchscreen_probe(struct i2c_client *i2c, · line 408

Quoted 10 lines
drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c +6 -0
@@ -399,7 +399,13 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,
 
 	/* Look up the DSI host.  It needs to probe before we do. */
 	endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
+	if (!endpoint)
+		return -ENODEV;
+
 	dsi_host_node = of_graph_get_remote_port_parent(endpoint);
+	if (!dsi_host_node)
+		return -ENODEV;
+

If we return here we will leak endpoint - a of_node_put() is missing. Use goto to rewind the allocations in the bottom of this function.

drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c static int rpi_touchscreen_probe(struct i2c_client *i2c, · line 418

Quoted 9 lines
drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c +2 -0
 	host = of_find_mipi_dsi_host_by_node(dsi_host_node);
 	of_node_put(dsi_host_node);
 	if (!host) {
@@ -408,6 +414,9 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,
 	}
 
 	info.node = of_graph_get_remote_port(endpoint);
+	if (!info.node)
+		return -ENODEV;

Here we also leak endpoint, but not dsi_host_node as we already did a put above.

drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c static int rpi_touchscreen_probe(struct i2c_client *i2c, · line 422

Quoted 4 lines
drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c +1 -0
+
 	of_node_put(endpoint);
 
 	ts->dsi = mipi_dsi_device_register_full(host, &info);

Sam
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

PATCH v2 1/1 drm/panel: check failure cases in the probe func

The following function calls may fail and return NULL, so the null check is added.
of_graph_get_next_endpoint
of_graph_get_remote_port_parent
of_graph_get_remote_port

Update: Thanks to Sam Ravnborg, for suggession on the use of goto to avoid leaking endpoint.

---
 .../gpu/drm/panel/panel-raspberrypi-touchscreen.c   | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c +13 -0
index 28c0620dfe0f..b5b14aa059ea 100644
@@ -399,7 +399,13 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,
 
 	/* Look up the DSI host.  It needs to probe before we do. */
 	endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
+	if (!endpoint)
+		return -ENODEV;
+
 	dsi_host_node = of_graph_get_remote_port_parent(endpoint);
+	if (!dsi_host_node)
+		goto error;
+
 	host = of_find_mipi_dsi_host_by_node(dsi_host_node);
 	of_node_put(dsi_host_node);
 	if (!host) {
@@ -408,6 +414,9 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,
 	}
 
 	info.node = of_graph_get_remote_port(endpoint);
+	if (!info.node)
+		goto error;
+
 	of_node_put(endpoint);
 
 	ts->dsi = mipi_dsi_device_register_full(host, &info);
@@ -428,6 +437,10 @@ static int rpi_touchscreen_probe(struct i2c_client *i2c,
 		return ret;
 
 	return 0;
+
+error:
+	of_node_put(endpoint);
+	return -ENODEV;
 }
 
 static int rpi_touchscreen_remove(struct i2c_client *i2c)
Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH v2] drm/panel: check failure cases in the probe func

Hi Navid.

Quoted 10 lines · Navid Emamdoost

The following function calls may fail and return NULL, so the null check is added.
of_graph_get_next_endpoint
of_graph_get_remote_port_parent
of_graph_get_remote_port

Update: Thanks to Sam Ravnborg, for suggession on the use of goto to avoid leaking endpoint.

Applied and pushed to drm-misc-next.

Sam