]> www.infradead.org Git - users/dwmw2/vmclock.git/commitdiff
ptp: vmclock: Clean up miscdev and ptp clock through devres
authorThomas Weißschuh <thomas.weissschuh@linutronix.de>
Fri, 7 Feb 2025 09:39:05 +0000 (10:39 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Tue, 29 Apr 2025 16:59:16 +0000 (09:59 -0700)
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>
Acked-by: Richard Cochran <richardcochran@gmail.com>
Reviewed-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
(cherry picked from commit 9a884c3800b207bac36e27be4ec7277c78a84568)

ptp_vmclock.c

index c998130c49570fd1c255f6f3fdb838adf5e12364..efe5d0650ac8ec8075b55290501c407714e6714f 100644 (file)
@@ -426,10 +426,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);
@@ -539,8 +538,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) {
@@ -566,6 +563,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
@@ -588,7 +589,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;
                }
        }
@@ -618,7 +618,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,