Skip to content

Commit

Permalink
drivers/iommu/msm_iommu_dev.c: fix leak and clean up error paths
Browse files Browse the repository at this point in the history
Fix two obvious problems:

1. We have registered msm_iommu_driver first, and need unregister it
   when registered msm_iommu_ctx_driver fail

2. We don't need to kfree drvdata before kzalloc was successful.

[[email protected]: remove now-unneeded initialization of ctx_drvdata, remove unneeded braces]
Signed-off-by: Libo Chen <[email protected]>
Acked-by: David Brown <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: James Hogan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Libo Chen authored and torvalds committed Jul 9, 2013
1 parent 9756b91 commit 34e3a58
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions drivers/iommu/msm_iommu_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,25 +291,20 @@ static int msm_iommu_ctx_probe(struct platform_device *pdev)
{
struct msm_iommu_ctx_dev *c = pdev->dev.platform_data;
struct msm_iommu_drvdata *drvdata;
struct msm_iommu_ctx_drvdata *ctx_drvdata = NULL;
struct msm_iommu_ctx_drvdata *ctx_drvdata;
int i, ret;
if (!c || !pdev->dev.parent) {
ret = -EINVAL;
goto fail;
}

drvdata = dev_get_drvdata(pdev->dev.parent);
if (!c || !pdev->dev.parent)
return -EINVAL;

if (!drvdata) {
ret = -ENODEV;
goto fail;
}
drvdata = dev_get_drvdata(pdev->dev.parent);
if (!drvdata)
return -ENODEV;

ctx_drvdata = kzalloc(sizeof(*ctx_drvdata), GFP_KERNEL);
if (!ctx_drvdata) {
ret = -ENOMEM;
goto fail;
}
if (!ctx_drvdata)
return -ENOMEM;

ctx_drvdata->num = c->num;
ctx_drvdata->pdev = pdev;

Expand Down Expand Up @@ -403,6 +398,7 @@ static int __init msm_iommu_driver_init(void)

ret = platform_driver_register(&msm_iommu_ctx_driver);
if (ret != 0) {
platform_driver_unregister(&msm_iommu_driver);
pr_err("Failed to register IOMMU context driver\n");
goto error;
}
Expand Down

0 comments on commit 34e3a58

Please sign in to comment.