Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1573411 > unrolled thread

[PATCH] drm/vc4: simplify exit path of a failed allocation of dsi_connector

Started byColin King <colin.king@canonical.com>
First post2017-02-03 21:00 +0100
Last post2017-02-08 00:50 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] drm/vc4: simplify exit path of a failed allocation of dsi_connector Colin King <colin.king@canonical.com> - 2017-02-03 21:00 +0100
    Re: [PATCH] drm/vc4: simplify exit path of a failed allocation of  dsi_connector Gustavo Padovan <gustavo@padovan.org> - 2017-02-06 12:50 +0100
    Re: [PATCH] drm/vc4: simplify exit path of a failed allocation of dsi_connector Eric Anholt <eric@anholt.net> - 2017-02-08 00:50 +0100

#1573411 — [PATCH] drm/vc4: simplify exit path of a failed allocation of dsi_connector

FromColin King <colin.king@canonical.com>
Date2017-02-03 21:00 +0100
Subject[PATCH] drm/vc4: simplify exit path of a failed allocation of dsi_connector
Message-ID<t6Sbw-6dd-23@gated-at.bofh.it>
From: Colin Ian King <colin.king@canonical.com>

If dsi_connector fails to allocate, the exit path via label 'fail'
checks if connector is null, which it always is, so the cleanup
that destroys connector is never going to be called.  Hence the
failure path can be more optimally performed by removing this
and just returning ERR_PTR(-ENOMEM).  This also removes the need
to initialize connector to NULL, and we can also remove ret too.

Detected by CoverityScan, CID#1399504 ("Logicall Dead Code")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/gpu/drm/vc4/vc4_dsi.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
index 2736b03..e328cb86 100644
--- a/drivers/gpu/drm/vc4/vc4_dsi.c
+++ b/drivers/gpu/drm/vc4/vc4_dsi.c
@@ -771,16 +771,14 @@ static const struct drm_connector_helper_funcs vc4_dsi_connector_helper_funcs =
 static struct drm_connector *vc4_dsi_connector_init(struct drm_device *dev,
 						    struct vc4_dsi *dsi)
 {
-	struct drm_connector *connector = NULL;
+	struct drm_connector *connector;
 	struct vc4_dsi_connector *dsi_connector;
-	int ret = 0;
 
 	dsi_connector = devm_kzalloc(dev->dev, sizeof(*dsi_connector),
 				     GFP_KERNEL);
-	if (!dsi_connector) {
-		ret = -ENOMEM;
-		goto fail;
-	}
+	if (!dsi_connector)
+		return ERR_PTR(-ENOMEM);
+
 	connector = &dsi_connector->base;
 
 	dsi_connector->dsi = dsi;
@@ -796,12 +794,6 @@ static struct drm_connector *vc4_dsi_connector_init(struct drm_device *dev,
 	drm_mode_connector_attach_encoder(connector, dsi->encoder);
 
 	return connector;
-
-fail:
-	if (connector)
-		vc4_dsi_connector_destroy(connector);
-
-	return ERR_PTR(ret);
 }
 
 static void vc4_dsi_encoder_destroy(struct drm_encoder *encoder)
-- 
2.10.2

[toc] | [next] | [standalone]


#1574579 — Re: [PATCH] drm/vc4: simplify exit path of a failed allocation of dsi_connector

FromGustavo Padovan <gustavo@padovan.org>
Date2017-02-06 12:50 +0100
SubjectRe: [PATCH] drm/vc4: simplify exit path of a failed allocation of dsi_connector
Message-ID<t7PXX-4pP-15@gated-at.bofh.it>
In reply to#1573411
Hi Colin,

2017-02-03 Colin King <colin.king@canonical.com>:

> From: Colin Ian King <colin.king@canonical.com>
> 
> If dsi_connector fails to allocate, the exit path via label 'fail'
> checks if connector is null, which it always is, so the cleanup
> that destroys connector is never going to be called.  Hence the
> failure path can be more optimally performed by removing this
> and just returning ERR_PTR(-ENOMEM).  This also removes the need
> to initialize connector to NULL, and we can also remove ret too.
> 
> Detected by CoverityScan, CID#1399504 ("Logicall Dead Code")
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/gpu/drm/vc4/vc4_dsi.c | 16 ++++------------
>  1 file changed, 4 insertions(+), 12 deletions(-)

Reviewed-by: Gustavo Padovan <gustavo.padovan@collabora.com>

Gustavo

[toc] | [prev] | [next] | [standalone]


#1576176

FromEric Anholt <eric@anholt.net>
Date2017-02-08 00:50 +0100
Message-ID<t8nGh-ZA-7@gated-at.bofh.it>
In reply to#1573411

[Multipart message — attachments visible in raw view] — view raw

Colin King <colin.king@canonical.com> writes:

> From: Colin Ian King <colin.king@canonical.com>
>
> If dsi_connector fails to allocate, the exit path via label 'fail'
> checks if connector is null, which it always is, so the cleanup
> that destroys connector is never going to be called.  Hence the
> failure path can be more optimally performed by removing this
> and just returning ERR_PTR(-ENOMEM).  This also removes the need
> to initialize connector to NULL, and we can also remove ret too.
>
> Detected by CoverityScan, CID#1399504 ("Logicall Dead Code")
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Reviewed and pushed to drm-misc-next.  Thanks!

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web