From: Thierry Reding <thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Cc: "Terje Bergström"
<tbergstrom-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
"David Airlie" <airlied-cv59FeDIM0c@public.gmane.org>,
"Stephen Warren"
<swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>,
dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [patch] drm/tegra: small leak on error in tegra_fb_alloc()
Date: Mon, 11 Nov 2013 10:03:49 +0100 [thread overview]
Message-ID: <20131111090348.GD3884@ulmo.nvidia.com> (raw)
In-Reply-To: <20131110053406.GB13643-mgFCXtclrQlZLf2FXnZxJA@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 1620 bytes --]
On Sat, Nov 09, 2013 at 09:34:06PM -0800, Dan Carpenter wrote:
> If we don't have enough memory for ->planes then we leak "fb".
>
> Signed-off-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Hi Dan,
Thanks for catching this. Perhaps tweak the commit subject to:
drm/tegra: fix small leak on error in tegra_fb_alloc()
?
One additional comment below.
> diff --git a/drivers/gpu/drm/tegra/fb.c b/drivers/gpu/drm/tegra/fb.c
> index 490f771..1362d78 100644
> --- a/drivers/gpu/drm/tegra/fb.c
> +++ b/drivers/gpu/drm/tegra/fb.c
> @@ -98,8 +98,10 @@ static struct tegra_fb *tegra_fb_alloc(struct drm_device *drm,
> return ERR_PTR(-ENOMEM);
>
> fb->planes = kzalloc(num_planes * sizeof(*planes), GFP_KERNEL);
> - if (!fb->planes)
> - return ERR_PTR(-ENOMEM);
> + if (!fb->planes) {
> + err = -ENOMEM;
> + goto free_fb;
> + }
>
> fb->num_planes = num_planes;
>
> @@ -112,12 +114,17 @@ static struct tegra_fb *tegra_fb_alloc(struct drm_device *drm,
> if (err < 0) {
> dev_err(drm->dev, "failed to initialize framebuffer: %d\n",
> err);
> - kfree(fb->planes);
> - kfree(fb);
> - return ERR_PTR(err);
> + goto free_planes;
> }
>
> return fb;
> +
> +free_planes:
> + kfree(fb->planes);
> +free_fb:
> + kfree(fb);
> +
> + return ERR_PTR(err);
> }
I think in this case I'd actually prefer for the kfree(fb) to be
duplicated and not have this error unwind. It's actually shorter
to do it that way in this case.
What I mean is:
if (!fb->planes) {
kfree(fb);
return ERR_PTR(-ENOMEM);
}
Thierry
[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2013-11-11 9:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-10 5:34 [patch] drm/tegra: small leak on error in tegra_fb_alloc() Dan Carpenter
[not found] ` <20131110053406.GB13643-mgFCXtclrQlZLf2FXnZxJA@public.gmane.org>
2013-11-11 9:03 ` Thierry Reding [this message]
[not found] ` <20131111090348.GD3884-AwZRO8vwLAwmlAP/+Wk3EA@public.gmane.org>
2013-11-11 9:42 ` Dan Carpenter
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=20131111090348.GD3884@ulmo.nvidia.com \
--to=thierry.reding-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=airlied-cv59FeDIM0c@public.gmane.org \
--cc=dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org \
--cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
--cc=kernel-janitors-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org \
--cc=tbergstrom-DDmLM1+adcrQT0dZR+AlfA@public.gmane.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