From: Russell King - ARM Linux <linux@armlinux.org.uk>
To: Sean Paul <seanpaul@chromium.org>
Cc: David Airlie <airlied@linux.ie>, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/5] drm/armada: fix leak of crtc structure
Date: Wed, 29 Nov 2017 19:16:43 +0000 [thread overview]
Message-ID: <20171129191643.GF8356@n2100.armlinux.org.uk> (raw)
In-Reply-To: <20171129145342.ripjickq7o75cvfj@art_vandelay>
On Wed, Nov 29, 2017 at 09:53:42AM -0500, Sean Paul wrote:
> On Wed, Nov 29, 2017 at 11:45:43AM +0000, Russell King wrote:
> > Fix the leak of the CRTC structure in the failure paths of
> > armada_drm_crtc_create().
> >
> > Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
> > ---
> > drivers/gpu/drm/armada/armada_crtc.c | 10 ++++++++--
> > 1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/armada/armada_crtc.c b/drivers/gpu/drm/armada/armada_crtc.c
> > index 2e065facdce7..844d488b6654 100644
> > --- a/drivers/gpu/drm/armada/armada_crtc.c
> > +++ b/drivers/gpu/drm/armada/armada_crtc.c
> > @@ -1246,11 +1246,14 @@ static int armada_drm_crtc_create(struct drm_device *drm, struct device *dev,
> > dcrtc->crtc.port = port;
> >
> > primary = kzalloc(sizeof(*primary), GFP_KERNEL);
> > - if (!primary)
> > + if (!primary) {
> > + kfree(dcrtc);
> > return -ENOMEM;
> > + }
> >
> > ret = armada_drm_plane_init(primary);
> > if (ret) {
> > + kfree(dcrtc);
> > kfree(primary);
> > return ret;
> > }
> > @@ -1262,14 +1265,17 @@ static int armada_drm_crtc_create(struct drm_device *drm, struct device *dev,
> > NULL,
> > DRM_PLANE_TYPE_PRIMARY, NULL);
> > if (ret) {
> > + kfree(dcrtc);
> > kfree(primary);
> > return ret;
> > }
> >
> > ret = drm_crtc_init_with_planes(drm, &dcrtc->crtc, &primary->base, NULL,
> > &armada_crtc_funcs, NULL);
> > - if (ret)
> > + if (ret) {
> > + kfree(dcrtc);
> > goto err_crtc_init;
>
> The mixed use of cleaning up at every exit and the lone label is a bit messy and
> prone to bugs such as the one you're fixing. How about you label everything
> and then just clean up once?
It's not that simple - see alternative patch below. How we clean
stuff up depends on how far through the initialisation we are, and
that doesn't lend itself to a sequential cleanup methodology.
> It also seems like you're missing cleanup if armada_overlay_plane_create()
> fails?
It's not missing. At that point, the CRTC has been registered, and any
failure will be cleaned up by the drm_mode_config_cleanup() in the
error paths in armada_drm_bind() in armada_drv.c
It's rather non-obvious because it uses the ->destroy callbacks.
diff --git a/drivers/gpu/drm/armada/armada_crtc.c b/drivers/gpu/drm/armada/armada_crtc.c
index d987198a2ac6..79ce877bf45f 100644
--- a/drivers/gpu/drm/armada/armada_crtc.c
+++ b/drivers/gpu/drm/armada/armada_crtc.c
@@ -1225,17 +1225,13 @@ static int armada_drm_crtc_create(struct drm_device *drm, struct device *dev,
ret = devm_request_irq(dev, irq, armada_drm_irq, 0, "armada_drm_crtc",
dcrtc);
- if (ret < 0) {
- kfree(dcrtc);
- return ret;
- }
+ if (ret < 0)
+ goto err_crtc;
if (dcrtc->variant->init) {
ret = dcrtc->variant->init(dcrtc, dev);
- if (ret) {
- kfree(dcrtc);
- return ret;
- }
+ if (ret)
+ goto err_crtc;
}
/* Ensure AXI pipeline is enabled */
@@ -1247,15 +1243,14 @@ static int armada_drm_crtc_create(struct drm_device *drm, struct device *dev,
primary = kzalloc(sizeof(*primary), GFP_KERNEL);
if (!primary) {
- kfree(dcrtc);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto err_crtc;
}
ret = armada_drm_plane_init(primary);
if (ret) {
- kfree(dcrtc);
kfree(primary);
- return ret;
+ goto err_crtc;
}
ret = drm_universal_plane_init(drm, &primary->base, 0,
@@ -1265,17 +1260,14 @@ static int armada_drm_crtc_create(struct drm_device *drm, struct device *dev,
NULL,
DRM_PLANE_TYPE_PRIMARY, NULL);
if (ret) {
- kfree(dcrtc);
kfree(primary);
- return ret;
+ goto err_crtc;
}
ret = drm_crtc_init_with_planes(drm, &dcrtc->crtc, &primary->base, NULL,
&armada_crtc_funcs, NULL);
- if (ret) {
- kfree(dcrtc);
+ if (ret)
goto err_crtc_init;
- }
drm_crtc_helper_add(&dcrtc->crtc, &armada_crtc_helper_funcs);
@@ -1288,6 +1280,9 @@ static int armada_drm_crtc_create(struct drm_device *drm, struct device *dev,
err_crtc_init:
primary->base.funcs->destroy(&primary->base);
+err_crtc:
+ kfree(dcrtc);
+
return ret;
}
--
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up
According to speedtest.net: 8.21Mbps down 510kbps up
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2017-11-29 19:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-29 11:45 [PATCH 0/5] Armada DRM fixes Russell King - ARM Linux
2017-11-29 11:45 ` [PATCH 1/5] drm/armada: fix leak of crtc structure Russell King
2017-11-29 14:53 ` Sean Paul
2017-11-29 19:16 ` Russell King - ARM Linux [this message]
2017-11-29 20:03 ` Sean Paul
2017-11-29 20:11 ` Russell King - ARM Linux
2017-11-29 20:29 ` Sean Paul
2017-11-29 11:45 ` [PATCH 2/5] drm/armada: fix SRAM powerdown Russell King
2017-11-29 11:45 ` [PATCH 3/5] drm/armada: fix UV swap code Russell King
2017-11-29 11:45 ` [PATCH 4/5] drm/armada: improve efficiency of armada_drm_plane_calc_addrs() Russell King
2017-11-29 11:46 ` [PATCH 5/5] drm/armada: fix YUV planar format framebuffer offsets Russell King
-- strict thread matches above, loose matches on Subject: below --
2017-12-08 12:13 [PATCH v2 0/5] Armada DRM fixes Russell King - ARM Linux
2017-12-08 12:14 ` [PATCH 1/5] drm/armada: fix leak of crtc structure Russell King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171129191643.GF8356@n2100.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=airlied@linux.ie \
--cc=dri-devel@lists.freedesktop.org \
--cc=seanpaul@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox