Skip to content

Commit 284b75a

Browse files
Zheng Qixingdamien-lemoal
authored andcommitted
ata: libata: Fix memory leak for error path in ata_host_alloc()
In ata_host_alloc(), if devres_alloc() fails to allocate the device host resource data pointer, the already allocated ata_host structure is not freed before returning from the function. This results in a potential memory leak. Call kfree(host) before jumping to the error handling path to ensure that the ata_host structure is properly freed if devres_alloc() fails. Fixes: 2623c7a ("libata: add refcounting to ata_host") Cc: [email protected] Signed-off-by: Zheng Qixing <[email protected]> Reviewed-by: Yu Kuai <[email protected]> Signed-off-by: Damien Le Moal <[email protected]>
1 parent d4bc0a2 commit 284b75a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/ata/libata-core.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5593,8 +5593,10 @@ struct ata_host *ata_host_alloc(struct device *dev, int n_ports)
55935593
}
55945594

55955595
dr = devres_alloc(ata_devres_release, 0, GFP_KERNEL);
5596-
if (!dr)
5596+
if (!dr) {
5597+
kfree(host);
55975598
goto err_out;
5599+
}
55985600

55995601
devres_add(dev, dr);
56005602
dev_set_drvdata(dev, host);

0 commit comments

Comments
 (0)