Skip to content

Commit 29b7cd2

Browse files
maquefelvinodkoul
authored andcommitted
dmaengine: ioatdma: Fix kmemleak in ioat_pci_probe()
If probing fails we end up with leaking ioatdma_device and each allocated channel. Following kmemleak easy to reproduce by injecting an error in ioat_alloc_chan_resources() when doing ioat_dma_self_test(). unreferenced object 0xffff888014ad5800 (size 1024): [..] [<ffffffff827692ca>] kmemleak_alloc+0x4a/0x80 [<ffffffff81430600>] kmalloc_trace+0x270/0x2f0 [<ffffffffa000b7d1>] ioat_pci_probe+0xc1/0x1c0 [ioatdma] [..] repeated for each ioatdma channel: unreferenced object 0xffff8880148e5c00 (size 512): [..] [<ffffffff827692ca>] kmemleak_alloc+0x4a/0x80 [<ffffffff81430600>] kmalloc_trace+0x270/0x2f0 [<ffffffffa0009641>] ioat_enumerate_channels+0x101/0x2d0 [ioatdma] [<ffffffffa000b266>] ioat3_dma_probe+0x4d6/0x970 [ioatdma] [<ffffffffa000b891>] ioat_pci_probe+0x181/0x1c0 [ioatdma] [..] Fixes: bf453a0 ("dmaengine: ioat: Support in-use unbind") Signed-off-by: Nikita Shubin <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent f0dc9fd commit 29b7cd2

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/dma/ioat/init.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,7 @@ static int ioat_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
13471347
void __iomem * const *iomap;
13481348
struct device *dev = &pdev->dev;
13491349
struct ioatdma_device *device;
1350+
unsigned int i;
13501351
u8 version;
13511352
int err;
13521353

@@ -1384,6 +1385,9 @@ static int ioat_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
13841385

13851386
err = ioat3_dma_probe(device, ioat_dca_enabled);
13861387
if (err) {
1388+
for (i = 0; i < IOAT_MAX_CHANS; i++)
1389+
kfree(device->idx[i]);
1390+
kfree(device);
13871391
dev_err(dev, "Intel(R) I/OAT DMA Engine init failed\n");
13881392
return -ENODEV;
13891393
}

0 commit comments

Comments
 (0)