From: Andrew Morton <akpm@linux-foundation.org>
To: Kevin Winchester <kjwinchester@gmail.com>
Cc: airlied@redhat.com, linux-kernel@vger.kernel.org,
linux-next@vger.kernel.org
Subject: Re: [PATCH linux-next] agp: correct missing cleanup on error in agp_add_bridge
Date: Tue, 28 Jul 2009 15:19:18 -0700 [thread overview]
Message-ID: <20090728151918.9b1a793e.akpm@linux-foundation.org> (raw)
In-Reply-To: <4A6BB1A1.50308@gmail.com>
On Sat, 25 Jul 2009 22:30:09 -0300
Kevin Winchester <kjwinchester@gmail.com> wrote:
>
> While investigating a kmemleak detected leak, I encountered the
> agp_add_bridge function. It appears to be responsible for freeing
> the agp_bridge_data in the case of a failure, but it is only doing
> so for some errors.
>
> Fix it to always free the bridge data if a failure condition is
> encountered.
>
> Signed-off-by: Kevin Winchester <kjwinchester@gmail.com>
> ---
>
> Note that this seems like a reasonable change to me, but this patch
> did not get rid of the kmemleak report, so I don't even have that as
> evidence of its correctness. Please review.
>
> diff --git a/drivers/char/agp/backend.c b/drivers/char/agp/backend.c
> index cfa5a64..aebd82c 100644
> --- a/drivers/char/agp/backend.c
> +++ b/drivers/char/agp/backend.c
> @@ -263,18 +263,22 @@ int agp_add_bridge(struct agp_bridge_data *bridge)
> {
> int error;
>
> - if (agp_off)
> - return -ENODEV;
> + if (agp_off) {
> + error = -ENODEV;
> + goto err_put_bridge;
> + }
>
> if (!bridge->dev) {
> printk (KERN_DEBUG PFX "Erk, registering with no pci_dev!\n");
> - return -EINVAL;
> + error = -EINVAL;
> + goto err_put_bridge;
> }
>
> /* Grab reference on the chipset driver. */
> if (!try_module_get(bridge->driver->owner)) {
> dev_info(&bridge->dev->dev, "can't lock chipset driver\n");
> - return -EINVAL;
> + error = -EINVAL;
> + goto err_put_bridge;
> }
>
> error = agp_backend_initialize(bridge);
> @@ -304,6 +308,7 @@ frontend_err:
> agp_backend_cleanup(bridge);
> err_out:
> module_put(bridge->driver->owner);
> +err_put_bridge:
> agp_put_bridge(bridge);
> return error;
> }
Looks right to me.
The code is ill-designed. The callee (agp_add_bridge) should not be
freeing things which the caller allocated. Because the callee
shouldn't assume that the caller will no longer use the data and the
callee shouldn't assume that the caller allocated the memory via
kmalloc(). Callers of agp_add_bridge() should be doing the
agp_put_bridge().
Your email client replaced all the tabs with spaces. I fixed that up.
prev parent reply other threads:[~2009-07-28 22:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-26 1:30 [PATCH linux-next] agp: correct missing cleanup on error in agp_add_bridge Kevin Winchester
2009-07-28 22:19 ` Andrew Morton [this message]
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=20090728151918.9b1a793e.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=airlied@redhat.com \
--cc=kjwinchester@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).