Skip to content

Commit

Permalink
media: media/pci: prevent memory leak in bttv_probe
Browse files Browse the repository at this point in the history
[ Upstream commit 7b81758 ]

In bttv_probe if some functions such as pci_enable_device,
pci_set_dma_mask and request_mem_region fails the allocated
 memory for btv should be released.

Signed-off-by: Xiaolong Huang <butterflyhuangxx@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Xiaolong Huang authored and gregkh committed Oct 29, 2020
1 parent 15e43e9 commit e967ca0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions drivers/media/pci/bt8xx/bttv-driver.c
Expand Up @@ -4013,19 +4013,22 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
btv->id = dev->device;
if (pci_enable_device(dev)) {
pr_warn("%d: Can't enable device\n", btv->c.nr);
return -EIO;
result = -EIO;
goto free_mem;
}
if (pci_set_dma_mask(dev, DMA_BIT_MASK(32))) {
pr_warn("%d: No suitable DMA available\n", btv->c.nr);
return -EIO;
result = -EIO;
goto free_mem;
}
if (!request_mem_region(pci_resource_start(dev,0),
pci_resource_len(dev,0),
btv->c.v4l2_dev.name)) {
pr_warn("%d: can't request iomem (0x%llx)\n",
btv->c.nr,
(unsigned long long)pci_resource_start(dev, 0));
return -EBUSY;
result = -EBUSY;
goto free_mem;
}
pci_set_master(dev);
pci_set_command(dev);
Expand Down Expand Up @@ -4211,6 +4214,10 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
release_mem_region(pci_resource_start(btv->c.pci,0),
pci_resource_len(btv->c.pci,0));
pci_disable_device(btv->c.pci);

free_mem:
bttvs[btv->c.nr] = NULL;
kfree(btv);
return result;
}

Expand Down

0 comments on commit e967ca0

Please sign in to comment.