4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zheng Qixing <zhengqixing@xxxxxxxxxx> commit 284b75a3d83c7631586d98f6dede1d90f128f0db upstream. 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: 2623c7a5f279 ("libata: add refcounting to ata_host") Cc: stable@xxxxxxxxxxxxxxx Signed-off-by: Zheng Qixing <zhengqixing@xxxxxxxxxx> Reviewed-by: Yu Kuai <yukuai3@xxxxxxxxxx> Signed-off-by: Damien Le Moal <dlemoal@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/ata/libata-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -6221,8 +6221,10 @@ struct ata_host *ata_host_alloc(struct d } dr = devres_alloc(ata_devres_release, 0, GFP_KERNEL); - if (!dr) + if (!dr) { + kfree(host); goto err_out; + } devres_add(dev, dr); dev_set_drvdata(dev, host);