Commit 5a7bd259 authored by Adrien Grassein's avatar Adrien Grassein Committed by Robert Foss

drm/bridge: lt8912b: fix incorrect handling of of_* return values

A static analysis shows several issues in the driver code at
probing time.

DT parsing errors were bad handled and could lead to bugs:
  - Bad error detection;
  - Bad release of resources

Fixes: 30e2ae94 ("drm/bridge: Introduce LT8912B DSI to HDMI bridge")
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Suggested-by: default avatarDan Carpenter  <dan.carpenter@oracle.com>
Signed-off-by: default avatarAdrien Grassein <adrien.grassein@gmail.com>
Reviewed-by: default avatarAndrzej Hajda <a.hajda@samsung.com>
Reviewed-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210415183639.1487-1-rdunlap@infradead.orgSigned-off-by: default avatarRobert Foss <robert.foss@linaro.org>
parent ad085b3a
......@@ -621,7 +621,8 @@ static int lt8912_parse_dt(struct lt8912 *lt)
{
struct gpio_desc *gp_reset;
struct device *dev = lt->dev;
int ret = 0;
int ret;
int data_lanes;
struct device_node *port_node;
struct device_node *endpoint;
......@@ -635,19 +636,21 @@ static int lt8912_parse_dt(struct lt8912 *lt)
lt->gp_reset = gp_reset;
endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 0, -1);
if (IS_ERR(endpoint)) {
ret = PTR_ERR(endpoint);
goto end;
}
if (!endpoint)
return -ENODEV;
lt->data_lanes = of_property_count_u32_elems(endpoint, "data-lanes");
data_lanes = of_property_count_u32_elems(endpoint, "data-lanes");
of_node_put(endpoint);
if (data_lanes < 0) {
dev_err(lt->dev, "%s: Bad data-lanes property\n", __func__);
return data_lanes;
}
lt->data_lanes = data_lanes;
lt->host_node = of_graph_get_remote_node(dev->of_node, 0, -1);
if (!lt->host_node) {
dev_err(lt->dev, "%s: Failed to get remote port\n", __func__);
ret = -ENODEV;
goto end;
return -ENODEV;
}
port_node = of_graph_get_remote_node(dev->of_node, 1, -1);
......@@ -658,24 +661,23 @@ static int lt8912_parse_dt(struct lt8912 *lt)
}
lt->hdmi_port = of_drm_find_bridge(port_node);
if (IS_ERR(lt->hdmi_port)) {
if (!lt->hdmi_port) {
dev_err(lt->dev, "%s: Failed to get hdmi port\n", __func__);
ret = PTR_ERR(lt->hdmi_port);
of_node_put(lt->host_node);
goto end;
ret = -ENODEV;
goto err_free_host_node;
}
if (!of_device_is_compatible(port_node, "hdmi-connector")) {
dev_err(lt->dev, "%s: Failed to get hdmi port\n", __func__);
ret = -EINVAL;
goto err_free_host_node;
}
of_node_put(port_node);
end:
return ret;
return 0;
err_free_host_node:
of_node_put(port_node);
of_node_put(lt->host_node);
return ret;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment