Skip to content

Commit

Permalink
libata: ensure host is free'd on error exit paths
Browse files Browse the repository at this point in the history
The host structure is not being kfree'd on two error exit paths
leading to memory leaks. Add in new err_free label and kfree host.

Detected by CoverityScan, CID#1466103 ("Resource leak")

Fixes: 2623c7a ("libata: add refcounting to ata_host")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
  • Loading branch information
Colin Ian King authored and htejun committed Mar 27, 2018
1 parent f0f5671 commit dafd6c4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/ata/libata-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -6087,7 +6087,7 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
return NULL;

if (!devres_open_group(dev, NULL, GFP_KERNEL))
return NULL;
goto err_free;

dr = devres_alloc(ata_devres_release, 0, GFP_KERNEL);
if (!dr)
Expand Down Expand Up @@ -6119,6 +6119,8 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports)

err_out:
devres_release_group(dev, NULL);
err_free:
kfree(host);
return NULL;
}

Expand Down

0 comments on commit dafd6c4

Please sign in to comment.