mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
To: David Woodhouse <dwmw2@infradead.org>,
	 Richard Cochran <richardcochran@gmail.com>,
	 Andrew Lunn <andrew+netdev@lunn.ch>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>
Cc: "David Woodhouse" <dwmw@amazon.co.uk>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>
Subject: [PATCH net-next 3/4] ptp: vmclock: Clean up miscdev and ptp clock through devres
Date: Thu, 06 Feb 2025 18:45:03 +0100	[thread overview]
Message-ID: <20250206-vmclock-probe-v1-3-17a3ea07be34@linutronix.de> (raw)
In-Reply-To: <20250206-vmclock-probe-v1-0-17a3ea07be34@linutronix.de>

Most resources owned by the vmclock device are managed through devres.
Only the miscdev and ptp clock are managed manually.
This makes the code slightly harder to understand than necessary.

Switch them over to devres and remove the now unnecessary drvdata.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
 drivers/ptp/ptp_vmclock.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c
index 82e6bef72b1b6edef7d891964c3f9c4546f6ddba..b7fa196975229cec6d27b34f7bb235c53b5b5732 100644
--- a/drivers/ptp/ptp_vmclock.c
+++ b/drivers/ptp/ptp_vmclock.c
@@ -420,10 +420,9 @@ static const struct file_operations vmclock_miscdev_fops = {
 
 /* module operations */
 
-static void vmclock_remove(struct platform_device *pdev)
+static void vmclock_remove(void *data)
 {
-	struct device *dev = &pdev->dev;
-	struct vmclock_state *st = dev_get_drvdata(dev);
+	struct vmclock_state *st = data;
 
 	if (st->ptp_clock)
 		ptp_clock_unregister(st->ptp_clock);
@@ -524,8 +523,6 @@ static int vmclock_probe(struct platform_device *pdev)
 		goto out;
 	}
 
-	dev_set_drvdata(dev, st);
-
 	if (le32_to_cpu(st->clk->magic) != VMCLOCK_MAGIC ||
 	    le32_to_cpu(st->clk->size) > resource_size(&st->res) ||
 	    le16_to_cpu(st->clk->version) != 1) {
@@ -551,6 +548,10 @@ static int vmclock_probe(struct platform_device *pdev)
 
 	st->miscdev.minor = MISC_DYNAMIC_MINOR;
 
+	ret = devm_add_action_or_reset(&pdev->dev, vmclock_remove, st);
+	if (ret)
+		goto out;
+
 	/*
 	 * If the structure is big enough, it can be mapped to userspace.
 	 * Theoretically a guest OS even using larger pages could still
@@ -573,7 +574,6 @@ static int vmclock_probe(struct platform_device *pdev)
 		if (IS_ERR(st->ptp_clock)) {
 			ret = PTR_ERR(st->ptp_clock);
 			st->ptp_clock = NULL;
-			vmclock_remove(pdev);
 			goto out;
 		}
 	}
@@ -602,7 +602,6 @@ MODULE_DEVICE_TABLE(acpi, vmclock_acpi_ids);
 
 static struct platform_driver vmclock_platform_driver = {
 	.probe		= vmclock_probe,
-	.remove		= vmclock_remove,
 	.driver	= {
 		.name	= "vmclock",
 		.acpi_match_table = vmclock_acpi_ids,

-- 
2.48.1


  parent reply	other threads:[~2025-02-06 17:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-06 17:45 [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling Thomas Weißschuh
2025-02-06 17:45 ` [PATCH net-next 1/4] ptp: vmclock: Set driver data before its usage Thomas Weißschuh
2025-02-07  7:07   ` Mateusz Polchlopek
2025-02-06 17:45 ` [PATCH net-next 2/4] ptp: vmclock: Don't unregister misc device if it was not registered Thomas Weißschuh
2025-02-06 17:45 ` Thomas Weißschuh [this message]
2025-02-06 17:45 ` [PATCH net-next 4/4] ptp: vmclock: Remove goto-based cleanup logic Thomas Weißschuh
2025-02-07  5:43 ` [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling Richard Cochran
2025-02-07  7:13 ` Mateusz Polchlopek
2025-02-07  9:10   ` David Woodhouse
2025-02-07  9:25     ` Thomas Weißschuh
2025-02-07  9:29       ` David Woodhouse
2025-02-07  9:13 ` [PATCH net-next 5/4] ptp: vmclock: Add .owner to vmclock_miscdev_fops David Woodhouse

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=20250206-vmclock-probe-v1-3-17a3ea07be34@linutronix.de \
    --to=thomas.weissschuh@linutronix.de \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=dwmw2@infradead.org \
    --cc=dwmw@amazon.co.uk \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    /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®