diff options
| author | Zheng Qixing <zhengqixing@huawei.com> | 2024-08-22 11:30:50 +0800 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-09-12 11:06:43 +0200 |
| commit | e0b122a8f6dddbec9c6b153f882f8f5a5cc47caa (patch) | |
| tree | da534073741293ab49c2e38ce20f8bf1f29145b0 /drivers/ata | |
| parent | 0f27b8c07e9a5994fd7e6ccb90e0cf4d91a7423f (diff) | |
| download | linux-e0b122a8f6dddbec9c6b153f882f8f5a5cc47caa.tar.gz linux-e0b122a8f6dddbec9c6b153f882f8f5a5cc47caa.tar.bz2 linux-e0b122a8f6dddbec9c6b153f882f8f5a5cc47caa.zip | |
ata: libata: Fix memory leak for error path in ata_host_alloc()
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@vger.kernel.org
Signed-off-by: Zheng Qixing <zhengqixing@huawei.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/ata')
| -rw-r--r-- | drivers/ata/libata-core.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 467fc8002c44..107c28ec23b8 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5429,8 +5429,10 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports) } 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); |
