Skip to content

Commit

Permalink
agp: correct missing cleanup on error in agp_add_bridge
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Dave Airlie <airlied@redhat.com>
  • Loading branch information
Kevin Winchester authored and Dave Airlie committed Jan 11, 2010
1 parent 22763c5 commit 3f50b02
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions drivers/char/agp/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,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);
Expand Down Expand Up @@ -326,6 +330,7 @@ int agp_add_bridge(struct agp_bridge_data *bridge)
agp_backend_cleanup(bridge);
err_out:
module_put(bridge->driver->owner);
err_put_bridge:
agp_put_bridge(bridge);
return error;
}
Expand Down

0 comments on commit 3f50b02

Please sign in to comment.