diff mbox series

[v5,1/1] drm/bridge: lt8912b: fix incorrect handling of of_* return values

Message ID 20210331133313.411307-2-adrien.grassein@gmail.com (mailing list archive)
State New, archived
Headers show
Series Fixes 30e2ae943c26 "drm/bridge: Introduce LT8912B DSI to HDMI" | expand

Commit Message

Adrien Grassein March 31, 2021, 1:33 p.m. UTC
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 ressources

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Suggested-by: Dan Carpenter  <dan.carpenter@oracle.com>
Signed-off-by: Adrien Grassein <adrien.grassein@gmail.com>
Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>
---
 drivers/gpu/drm/bridge/lontium-lt8912b.c | 32 +++++++++++++-----------
 1 file changed, 17 insertions(+), 15 deletions(-)

Comments

Dan Carpenter March 31, 2021, 2:42 p.m. UTC | #1
On Wed, Mar 31, 2021 at 03:33:13PM +0200, Adrien Grassein wrote:
> 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 ressources
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Suggested-by: Dan Carpenter  <dan.carpenter@oracle.com>
> Signed-off-by: Adrien Grassein <adrien.grassein@gmail.com>
> Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>

Great!  Thanks!

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

regards,
dan carpenter
Adrien Grassein April 16, 2021, 12:01 p.m. UTC | #2
Hi Robert,

Could you please have a look at this patch?
It has been reviewed by the bug reporter and another person.

I don't receive any "merged" message.

Thanks a lot,
Adrien

Le mer. 31 mars 2021 à 16:42, Dan Carpenter <dan.carpenter@oracle.com> a écrit :
>
> On Wed, Mar 31, 2021 at 03:33:13PM +0200, Adrien Grassein wrote:
> > 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 ressources
> >
> > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Suggested-by: Dan Carpenter  <dan.carpenter@oracle.com>
> > Signed-off-by: Adrien Grassein <adrien.grassein@gmail.com>
> > Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>
>
> Great!  Thanks!
>
> Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> regards,
> dan carpenter
>
Robert Foss April 16, 2021, 3:16 p.m. UTC | #3
Hey Adrien,

On Fri, 16 Apr 2021 at 14:02, Adrien Grassein <adrien.grassein@gmail.com> wrote:
>
> Hi Robert,
>
> Could you please have a look at this patch?
> It has been reviewed by the bug reporter and another person.
>
> I don't receive any "merged" message.
>
> Thanks a lot,
> Adrien
>
> Le mer. 31 mars 2021 à 16:42, Dan Carpenter <dan.carpenter@oracle.com> a écrit :
> >
> > On Wed, Mar 31, 2021 at 03:33:13PM +0200, Adrien Grassein wrote:
> > > 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 ressources
> > >
> > > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > > Suggested-by: Dan Carpenter  <dan.carpenter@oracle.com>
> > > Signed-off-by: Adrien Grassein <adrien.grassein@gmail.com>
> > > Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>
> >
> > Great!  Thanks!
> >
> > Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

Fixed a checkpatch --strict nit, added `Link` tag and added 'Fixes` tag.

Merged for v5.13 in drm-misc-next-fixes.


Rob.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/bridge/lontium-lt8912b.c b/drivers/gpu/drm/bridge/lontium-lt8912b.c
index 61491615bad0..55d8aa22c882 100644
--- a/drivers/gpu/drm/bridge/lontium-lt8912b.c
+++ b/drivers/gpu/drm/bridge/lontium-lt8912b.c
@@ -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;
 }