Commit 7b817585 authored by Xiaolong Huang's avatar Xiaolong Huang Committed by Mauro Carvalho Chehab

media: media/pci: prevent memory leak in bttv_probe

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: default avatarXiaolong Huang <butterflyhuangxx@gmail.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent c8872483
...@@ -4013,11 +4013,13 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) ...@@ -4013,11 +4013,13 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
btv->id = dev->device; btv->id = dev->device;
if (pci_enable_device(dev)) { if (pci_enable_device(dev)) {
pr_warn("%d: Can't enable device\n", btv->c.nr); 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))) { if (pci_set_dma_mask(dev, DMA_BIT_MASK(32))) {
pr_warn("%d: No suitable DMA available\n", btv->c.nr); 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), if (!request_mem_region(pci_resource_start(dev,0),
pci_resource_len(dev,0), pci_resource_len(dev,0),
...@@ -4025,7 +4027,8 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) ...@@ -4025,7 +4027,8 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id)
pr_warn("%d: can't request iomem (0x%llx)\n", pr_warn("%d: can't request iomem (0x%llx)\n",
btv->c.nr, btv->c.nr,
(unsigned long long)pci_resource_start(dev, 0)); (unsigned long long)pci_resource_start(dev, 0));
return -EBUSY; result = -EBUSY;
goto free_mem;
} }
pci_set_master(dev); pci_set_master(dev);
pci_set_command(dev); pci_set_command(dev);
...@@ -4211,6 +4214,10 @@ static int bttv_probe(struct pci_dev *dev, const struct pci_device_id *pci_id) ...@@ -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), release_mem_region(pci_resource_start(btv->c.pci,0),
pci_resource_len(btv->c.pci,0)); pci_resource_len(btv->c.pci,0));
pci_disable_device(btv->c.pci); pci_disable_device(btv->c.pci);
free_mem:
bttvs[btv->c.nr] = NULL;
kfree(btv);
return result; return result;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment