media: tw5864: Convert to use managed functions pcim* and devm*

When removing the module, we will get the follow flaw:

[   69.323999] remove_proc_entry: removing non-empty directory 'irq/21', leaking at least 'tw5864'
[   69.324449] WARNING: CPU: 0 PID: 395 at fs/proc/generic.c:717 remove_proc_entry+0x389/0x3f0
[   69.326909] RIP: 0010:remove_proc_entry+0x389/0x3f0
[   69.331089] Call Trace:
[   69.331215]  <TASK>
[   69.331327]  unregister_irq_proc+0x14c/0x170
[   69.332579]  tw5864_finidev+0x12a/0x190 [tw5864]
[   69.332811]  pci_device_remove+0x92/0x240

Fix this by using managed functions, this makes the error handling more
simpler.

Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
This commit is contained in:
Zheyu Ma 2022-05-21 06:55:17 +01:00 committed by Mauro Carvalho Chehab
parent a1a9b71ebd
commit d3741027e5
1 changed files with 7 additions and 23 deletions

View File

@ -254,9 +254,9 @@ static int tw5864_initdev(struct pci_dev *pci_dev,
/* pci init */ /* pci init */
dev->pci = pci_dev; dev->pci = pci_dev;
err = pci_enable_device(pci_dev); err = pcim_enable_device(pci_dev);
if (err) { if (err) {
dev_err(&dev->pci->dev, "pci_enable_device() failed\n"); dev_err(&dev->pci->dev, "pcim_enable_device() failed\n");
goto unreg_v4l2; goto unreg_v4l2;
} }
@ -265,21 +265,16 @@ static int tw5864_initdev(struct pci_dev *pci_dev,
err = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32)); err = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32));
if (err) { if (err) {
dev_err(&dev->pci->dev, "32 bit PCI DMA is not supported\n"); dev_err(&dev->pci->dev, "32 bit PCI DMA is not supported\n");
goto disable_pci; goto unreg_v4l2;
} }
/* get mmio */ /* get mmio */
err = pci_request_regions(pci_dev, dev->name); err = pcim_iomap_regions(pci_dev, BIT(0), dev->name);
if (err) { if (err) {
dev_err(&dev->pci->dev, "Cannot request regions for MMIO\n"); dev_err(&dev->pci->dev, "Cannot request regions for MMIO\n");
goto disable_pci; goto unreg_v4l2;
}
dev->mmio = pci_ioremap_bar(pci_dev, 0);
if (!dev->mmio) {
err = -EIO;
dev_err(&dev->pci->dev, "can't ioremap() MMIO memory\n");
goto release_mmio;
} }
dev->mmio = pcim_iomap_table(pci_dev)[0];
spin_lock_init(&dev->slock); spin_lock_init(&dev->slock);
@ -291,7 +286,7 @@ static int tw5864_initdev(struct pci_dev *pci_dev,
err = tw5864_video_init(dev, video_nr); err = tw5864_video_init(dev, video_nr);
if (err) if (err)
goto unmap_mmio; goto unreg_v4l2;
/* get irq */ /* get irq */
err = devm_request_irq(&pci_dev->dev, pci_dev->irq, tw5864_isr, err = devm_request_irq(&pci_dev->dev, pci_dev->irq, tw5864_isr,
@ -308,12 +303,6 @@ static int tw5864_initdev(struct pci_dev *pci_dev,
fini_video: fini_video:
tw5864_video_fini(dev); tw5864_video_fini(dev);
unmap_mmio:
iounmap(dev->mmio);
release_mmio:
pci_release_regions(pci_dev);
disable_pci:
pci_disable_device(pci_dev);
unreg_v4l2: unreg_v4l2:
v4l2_device_unregister(&dev->v4l2_dev); v4l2_device_unregister(&dev->v4l2_dev);
return err; return err;
@ -331,11 +320,6 @@ static void tw5864_finidev(struct pci_dev *pci_dev)
/* unregister */ /* unregister */
tw5864_video_fini(dev); tw5864_video_fini(dev);
/* release resources */
iounmap(dev->mmio);
pci_release_regions(pci_dev);
pci_disable_device(pci_dev);
v4l2_device_unregister(&dev->v4l2_dev); v4l2_device_unregister(&dev->v4l2_dev);
} }