mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zheyu Ma <zheyuma97@gmail.com>
To: maintainers@bluecherrydvr.com, anton@corp.bluecherry.net,
	andrey.utkin@corp.bluecherry.net, mchehab@kernel.org
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Zheyu Ma <zheyuma97@gmail.com>
Subject: [PATCH] media: tw5864: Convert to use managed functions pcim* and devm*
Date: Sat, 21 May 2022 13:55:17 +0800	[thread overview]
Message-ID: <20220521055517.3099142-1-zheyuma97@gmail.com> (raw)

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>
---
 drivers/media/pci/tw5864/tw5864-core.c | 30 ++++++--------------------
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/drivers/media/pci/tw5864/tw5864-core.c b/drivers/media/pci/tw5864/tw5864-core.c
index 5cae73e6fb9c..560ff1ddcc83 100644
--- a/drivers/media/pci/tw5864/tw5864-core.c
+++ b/drivers/media/pci/tw5864/tw5864-core.c
@@ -254,9 +254,9 @@ static int tw5864_initdev(struct pci_dev *pci_dev,
 
 	/* pci init */
 	dev->pci = pci_dev;
-	err = pci_enable_device(pci_dev);
+	err = pcim_enable_device(pci_dev);
 	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;
 	}
 
@@ -265,21 +265,16 @@ static int tw5864_initdev(struct pci_dev *pci_dev,
 	err = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32));
 	if (err) {
 		dev_err(&dev->pci->dev, "32 bit PCI DMA is not supported\n");
-		goto disable_pci;
+		goto unreg_v4l2;
 	}
 
 	/* get mmio */
-	err = pci_request_regions(pci_dev, dev->name);
+	err = pcim_iomap_regions(pci_dev, BIT(0), dev->name);
 	if (err) {
 		dev_err(&dev->pci->dev, "Cannot request regions for MMIO\n");
-		goto disable_pci;
-	}
-	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;
+		goto unreg_v4l2;
 	}
+	dev->mmio = pcim_iomap_table(pci_dev)[0];
 
 	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);
 	if (err)
-		goto unmap_mmio;
+		goto unreg_v4l2;
 
 	/* get irq */
 	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:
 	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:
 	v4l2_device_unregister(&dev->v4l2_dev);
 	return err;
@@ -331,11 +320,6 @@ static void tw5864_finidev(struct pci_dev *pci_dev)
 	/* unregister */
 	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);
 }
 
-- 
2.36.1


                 reply	other threads:[~2022-05-21  5:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220521055517.3099142-1-zheyuma97@gmail.com \
    --to=zheyuma97@gmail.com \
    --cc=andrey.utkin@corp.bluecherry.net \
    --cc=anton@corp.bluecherry.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=maintainers@bluecherrydvr.com \
    --cc=mchehab@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®