Skip to content

Commit

Permalink
vxge: fix memory leak in vxge_alloc_msix() error path
Browse files Browse the repository at this point in the history
When pci_enable_msix() returned ret<0, entries and vxge_entries were leaked.
While at it, use the centralized exit idiom in the function.

Signed-off-by: Michal Schmidt <[email protected]>
Acked-by: Ram Vepa <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
michich authored and davem330 committed Jun 27, 2010
1 parent 1b4843c commit cc413d9
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions drivers/net/vxge/vxge-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2262,7 +2262,8 @@ static int vxge_alloc_msix(struct vxgedev *vdev)
vxge_debug_init(VXGE_ERR,
"%s: memory allocation failed",
VXGE_DRIVER_NAME);
return -ENOMEM;
ret = -ENOMEM;
goto alloc_entries_failed;
}

vdev->vxge_entries =
Expand All @@ -2271,8 +2272,8 @@ static int vxge_alloc_msix(struct vxgedev *vdev)
if (!vdev->vxge_entries) {
vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
VXGE_DRIVER_NAME);
kfree(vdev->entries);
return -ENOMEM;
ret = -ENOMEM;
goto alloc_vxge_entries_failed;
}

for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
Expand Down Expand Up @@ -2303,22 +2304,32 @@ static int vxge_alloc_msix(struct vxgedev *vdev)
vxge_debug_init(VXGE_ERR,
"%s: MSI-X enable failed for %d vectors, ret: %d",
VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
ret = -ENODEV;
goto enable_msix_failed;
}

kfree(vdev->entries);
kfree(vdev->vxge_entries);
vdev->entries = NULL;
vdev->vxge_entries = NULL;

if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3))
return -ENODEV;
/* Try with less no of vector by reducing no of vpaths count */
temp = (ret - 1)/2;
vxge_close_vpaths(vdev, temp);
vdev->no_of_vpath = temp;
goto start;
} else if (ret < 0)
return -ENODEV;

} else if (ret < 0) {
ret = -ENODEV;
goto enable_msix_failed;
}
return 0;

enable_msix_failed:
kfree(vdev->vxge_entries);
alloc_vxge_entries_failed:
kfree(vdev->entries);
alloc_entries_failed:
return ret;
}

static int vxge_enable_msix(struct vxgedev *vdev)
Expand Down

0 comments on commit cc413d9

Please sign in to comment.