drm/panel: check failure cases in the probe func
authorNavid Emamdoost <navid.emamdoost@gmail.com>
Wed, 24 Jul 2019 19:55:34 +0000 (14:55 -0500)
committerSam Ravnborg <sam@ravnborg.org>
Fri, 26 Jul 2019 11:44:42 +0000 (13:44 +0200)
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>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190724195534.9303-1-navid.emamdoost@gmail.com
drivers/gpu/drm/panel/panel-raspberrypi-touchscreen.c

index 28c0620dfe0f9ae025ba9ae995973ef94e9e9de0..b5b14aa059ea722195aa4e55dab8c969475e4f7b 100644 (file)
@@ -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)