* [PATCH] rpi_touchscreen_probe: check for failure case
@ 2019-07-24 2:56 Navid Emamdoost
2019-07-24 5:17 ` Sam Ravnborg
0 siblings, 1 reply; 6+ messages in thread
From: Navid Emamdoost @ 2019-07-24 2:56 UTC (permalink / raw)
To: emamd001
Cc: kjlu, smccaman, Navid Emamdoost, Thierry Reding, Sam Ravnborg,
David Airlie, Daniel Vetter, dri-devel, linux-kernel
of_graph_get_next_endpoint may return NULL, so null check is needed.
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
index 28c0620dfe0f..2e0977e26fab 100644
--- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
+++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
@@ -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);
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] rpi_touchscreen_probe: check for failure case
2019-07-24 2:56 [PATCH] rpi_touchscreen_probe: check for failure case Navid Emamdoost
@ 2019-07-24 5:17 ` Sam Ravnborg
2019-07-24 14:48 ` [PATCH] drm/panel: check failure cases in the probe func Navid Emamdoost
0 siblings, 1 reply; 6+ messages in thread
From: Sam Ravnborg @ 2019-07-24 5:17 UTC (permalink / raw)
To: Navid Emamdoost
Cc: emamd001, kjlu, smccaman, Thierry Reding, David Airlie,
Daniel Vetter, dri-devel, linux-kernel
Hi Navid.
Thanks for your patch.
On Tue, Jul 23, 2019 at 09:56:43PM -0500, Navid Emamdoost wrote:
> of_graph_get_next_endpoint may return NULL, so null check is needed.
>
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
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
> ---
> drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
> index 28c0620dfe0f..2e0977e26fab 100644
> --- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
> +++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
> @@ -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);
> --
> 2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] drm/panel: check failure cases in the probe func
2019-07-24 5:17 ` Sam Ravnborg
@ 2019-07-24 14:48 ` Navid Emamdoost
2019-07-24 18:59 ` Sam Ravnborg
0 siblings, 1 reply; 6+ messages in thread
From: Navid Emamdoost @ 2019-07-24 14:48 UTC (permalink / raw)
To: sam
Cc: emamd001, kjlu, smccaman, secalert, Navid Emamdoost,
Thierry Reding, David Airlie, Daniel Vetter, dri-devel,
linux-kernel
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
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
index 28c0620dfe0f..9484fdb60f68 100644
--- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
+++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
@@ -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);
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/panel: check failure cases in the probe func
2019-07-24 14:48 ` [PATCH] drm/panel: check failure cases in the probe func Navid Emamdoost
@ 2019-07-24 18:59 ` Sam Ravnborg
2019-07-24 19:55 ` [PATCH v2] " Navid Emamdoost
0 siblings, 1 reply; 6+ messages in thread
From: Sam Ravnborg @ 2019-07-24 18:59 UTC (permalink / raw)
To: Navid Emamdoost
Cc: emamd001, kjlu, smccaman, secalert, Thierry Reding, David Airlie,
Daniel Vetter, dri-devel, linux-kernel
Hi Navid.
Thanks for your patch.
On Wed, Jul 24, 2019 at 09:48:44AM -0500, Navid Emamdoost wrote:
> 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
>
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
> drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
> index 28c0620dfe0f..9484fdb60f68 100644
> --- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
> +++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
> @@ -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.
> 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.
> +
> of_node_put(endpoint);
>
> ts->dsi = mipi_dsi_device_register_full(host, &info);
Sam
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] drm/panel: check failure cases in the probe func
2019-07-24 18:59 ` Sam Ravnborg
@ 2019-07-24 19:55 ` Navid Emamdoost
2019-07-26 12:33 ` Sam Ravnborg
0 siblings, 1 reply; 6+ messages in thread
From: Navid Emamdoost @ 2019-07-24 19:55 UTC (permalink / raw)
To: sam
Cc: emamd001, kjlu, smccaman, secalert, Navid Emamdoost,
Thierry Reding, David Airlie, Daniel Vetter, dri-devel,
linux-kernel
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.
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
.../gpu/drm/panel/panel-raspberrypi-touchscreen.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
index 28c0620dfe0f..b5b14aa059ea 100644
--- a/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
+++ b/drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c
@@ -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)
--
2.17.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] drm/panel: check failure cases in the probe func
2019-07-24 19:55 ` [PATCH v2] " Navid Emamdoost
@ 2019-07-26 12:33 ` Sam Ravnborg
0 siblings, 0 replies; 6+ messages in thread
From: Sam Ravnborg @ 2019-07-26 12:33 UTC (permalink / raw)
To: Navid Emamdoost
Cc: secalert, David Airlie, kjlu, linux-kernel, dri-devel,
Thierry Reding, smccaman, emamd001
Hi Navid.
On Wed, Jul 24, 2019 at 02:55:34PM -0500, Navid Emamdoost wrote:
> 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.
>
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
Applied and pushed to drm-misc-next.
Sam
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-07-26 12:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-24 2:56 [PATCH] rpi_touchscreen_probe: check for failure case Navid Emamdoost
2019-07-24 5:17 ` Sam Ravnborg
2019-07-24 14:48 ` [PATCH] drm/panel: check failure cases in the probe func Navid Emamdoost
2019-07-24 18:59 ` Sam Ravnborg
2019-07-24 19:55 ` [PATCH v2] " Navid Emamdoost
2019-07-26 12:33 ` Sam Ravnborg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).