xen/pcifront: use xenbus_setup_ring() and xenbus_teardown_ring()
authorJuergen Gross <jgross@suse.com>
Thu, 28 Apr 2022 07:01:04 +0000 (09:01 +0200)
committerJuergen Gross <jgross@suse.com>
Thu, 19 May 2022 12:22:02 +0000 (14:22 +0200)
Simplify pcifront's shared page creation and removal via
xenbus_setup_ring() and xenbus_teardown_ring().

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
drivers/pci/xen-pcifront.c

index 3edc156..689271c 100644 (file)
@@ -709,9 +709,8 @@ static struct pcifront_device *alloc_pdev(struct xenbus_device *xdev)
        if (pdev == NULL)
                goto out;
 
-       pdev->sh_info =
-           (struct xen_pci_sharedinfo *)__get_free_page(GFP_KERNEL);
-       if (pdev->sh_info == NULL) {
+       if (xenbus_setup_ring(xdev, GFP_KERNEL, (void **)&pdev->sh_info, 1,
+                             &pdev->gnt_ref)) {
                kfree(pdev);
                pdev = NULL;
                goto out;
@@ -729,7 +728,6 @@ static struct pcifront_device *alloc_pdev(struct xenbus_device *xdev)
        spin_lock_init(&pdev->sh_info_lock);
 
        pdev->evtchn = INVALID_EVTCHN;
-       pdev->gnt_ref = INVALID_GRANT_REF;
        pdev->irq = -1;
 
        INIT_WORK(&pdev->op_work, pcifront_do_aer);
@@ -754,11 +752,7 @@ static void free_pdev(struct pcifront_device *pdev)
        if (pdev->evtchn != INVALID_EVTCHN)
                xenbus_free_evtchn(pdev->xdev, pdev->evtchn);
 
-       if (pdev->gnt_ref != INVALID_GRANT_REF)
-               gnttab_end_foreign_access(pdev->gnt_ref,
-                                         (unsigned long)pdev->sh_info);
-       else
-               free_page((unsigned long)pdev->sh_info);
+       xenbus_teardown_ring((void **)&pdev->sh_info, 1, &pdev->gnt_ref);
 
        dev_set_drvdata(&pdev->xdev->dev, NULL);
 
@@ -769,13 +763,6 @@ static int pcifront_publish_info(struct pcifront_device *pdev)
 {
        int err = 0;
        struct xenbus_transaction trans;
-       grant_ref_t gref;
-
-       err = xenbus_grant_ring(pdev->xdev, pdev->sh_info, 1, &gref);
-       if (err < 0)
-               goto out;
-
-       pdev->gnt_ref = gref;
 
        err = xenbus_alloc_evtchn(pdev->xdev, &pdev->evtchn);
        if (err)