LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Jonathan Lemon <jonathan.lemon@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Richard Cochran <richardcochran@gmail.com>
Subject: [PATCH v1 net-next 2/3] ptp_ocp: Convert to use managed functions pcim_* and devm_*
Date: Fri, 13 Aug 2021 15:27:36 +0300	[thread overview]
Message-ID: <20210813122737.45860-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20210813122737.45860-1-andriy.shevchenko@linux.intel.com>

This makes the error handling much more simpler than open-coding everything
and in addition makes the probe function smaller an tidier.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/ptp/ptp_ocp.c | 40 +++++++++-------------------------------
 1 file changed, 9 insertions(+), 31 deletions(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 874ea7930079..5d0c0c0734f2 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -301,30 +301,25 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	struct ptp_ocp *bp;
 	int err;
 
-	bp = kzalloc(sizeof(*bp), GFP_KERNEL);
+	bp = devm_kzalloc(&pdev->dev, sizeof(*bp), GFP_KERNEL);
 	if (!bp)
 		return -ENOMEM;
 	bp->pdev = pdev;
 	pci_set_drvdata(pdev, bp);
 
-	err = pci_enable_device(pdev);
+	err = pcim_enable_device(pdev);
 	if (err) {
 		dev_err(&pdev->dev, "pci_enable_device\n");
-		goto out_free;
+		return err;
 	}
 
-	err = pci_request_regions(pdev, KBUILD_MODNAME);
+	err = pcim_iomap_regions(pdev, BIT(0), KBUILD_MODNAME);
 	if (err) {
-		dev_err(&pdev->dev, "pci_request_region\n");
-		goto out_disable;
-	}
-
-	bp->base = pci_ioremap_bar(pdev, 0);
-	if (!bp->base) {
 		dev_err(&pdev->dev, "io_remap bar0\n");
-		err = -ENOMEM;
-		goto out_release_regions;
+		return err;
 	}
+
+	bp->base = pcim_iomap_table(pdev)[0];
 	bp->reg = bp->base + OCP_REGISTER_OFFSET;
 	bp->tod = bp->base + TOD_REGISTER_OFFSET;
 	bp->ptp_info = ptp_ocp_clock_info;
@@ -332,29 +327,17 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	err = ptp_ocp_check_clock(bp);
 	if (err)
-		goto out;
+		return err;
 
 	bp->ptp = ptp_clock_register(&bp->ptp_info, &pdev->dev);
 	if (IS_ERR(bp->ptp)) {
 		dev_err(&pdev->dev, "ptp_clock_register\n");
-		err = PTR_ERR(bp->ptp);
-		goto out;
+		return PTR_ERR(bp->ptp);
 	}
 
 	ptp_ocp_info(bp);
 
 	return 0;
-
-out:
-	pci_iounmap(pdev, bp->base);
-out_release_regions:
-	pci_release_regions(pdev);
-out_disable:
-	pci_disable_device(pdev);
-out_free:
-	kfree(bp);
-
-	return err;
 }
 
 static void
@@ -363,11 +346,6 @@ ptp_ocp_remove(struct pci_dev *pdev)
 	struct ptp_ocp *bp = pci_get_drvdata(pdev);
 
 	ptp_clock_unregister(bp->ptp);
-	pci_iounmap(pdev, bp->base);
-	pci_release_regions(pdev);
-	pci_disable_device(pdev);
-	pci_set_drvdata(pdev, NULL);
-	kfree(bp);
 }
 
 static struct pci_driver ptp_ocp_driver = {
-- 
2.30.2


  reply	other threads:[~2021-08-13 12:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-13 12:27 [PATCH v1 net-next 1/3] ptp_ocp: Switch to use module_pci_driver() macro Andy Shevchenko
2021-08-13 12:27 ` Andy Shevchenko [this message]
2021-08-13 12:27 ` [PATCH v1 net-next 3/3] ptp_ocp: use bits.h macros for all masks Andy Shevchenko
2021-08-13 17:35   ` kernel test robot
2021-08-13 17:48     ` Andy Shevchenko
2021-08-13 18:14 ` [PATCH v1 net-next 1/3] ptp_ocp: Switch to use module_pci_driver() macro Jakub Kicinski
2021-08-13 19:30   ` Andy Shevchenko
2021-08-16 21:01     ` Jonathan Lemon
2021-08-17  9:48       ` Andy Shevchenko
2021-08-17 12:43         ` Andy Shevchenko

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=20210813122737.45860-2-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=jonathan.lemon@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --subject='Re: [PATCH v1 net-next 2/3] ptp_ocp: Convert to use managed functions pcim_* and devm_*' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).