xen/usbfront: use xenbus_setup_ring() and xenbus_teardown_ring()

Simplify xen-hcd's ring creation and removal via xenbus_setup_ring()
and xenbus_teardown_ring().

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Juergen Gross <jgross@suse.com>
This commit is contained in:
Juergen Gross 2022-04-28 09:01:05 +02:00
parent caa427d252
commit 2b3daf083a
1 changed files with 15 additions and 46 deletions

View File

@ -1098,19 +1098,10 @@ static void xenhcd_destroy_rings(struct xenhcd_info *info)
unbind_from_irqhandler(info->irq, info); unbind_from_irqhandler(info->irq, info);
info->irq = 0; info->irq = 0;
if (info->urb_ring_ref != INVALID_GRANT_REF) { xenbus_teardown_ring((void **)&info->urb_ring.sring, 1,
gnttab_end_foreign_access(info->urb_ring_ref, &info->urb_ring_ref);
(unsigned long)info->urb_ring.sring); xenbus_teardown_ring((void **)&info->conn_ring.sring, 1,
info->urb_ring_ref = INVALID_GRANT_REF; &info->conn_ring_ref);
}
info->urb_ring.sring = NULL;
if (info->conn_ring_ref != INVALID_GRANT_REF) {
gnttab_end_foreign_access(info->conn_ring_ref,
(unsigned long)info->conn_ring.sring);
info->conn_ring_ref = INVALID_GRANT_REF;
}
info->conn_ring.sring = NULL;
} }
static int xenhcd_setup_rings(struct xenbus_device *dev, static int xenhcd_setup_rings(struct xenbus_device *dev,
@ -1118,46 +1109,24 @@ static int xenhcd_setup_rings(struct xenbus_device *dev,
{ {
struct xenusb_urb_sring *urb_sring; struct xenusb_urb_sring *urb_sring;
struct xenusb_conn_sring *conn_sring; struct xenusb_conn_sring *conn_sring;
grant_ref_t gref;
int err; int err;
info->urb_ring_ref = INVALID_GRANT_REF;
info->conn_ring_ref = INVALID_GRANT_REF; info->conn_ring_ref = INVALID_GRANT_REF;
err = xenbus_setup_ring(dev, GFP_NOIO | __GFP_HIGH,
urb_sring = (struct xenusb_urb_sring *)get_zeroed_page( (void **)&urb_sring, 1, &info->urb_ring_ref);
GFP_NOIO | __GFP_HIGH); if (err) {
if (!urb_sring) { xenbus_dev_fatal(dev, err, "allocating urb ring");
xenbus_dev_fatal(dev, -ENOMEM, "allocating urb ring"); return err;
return -ENOMEM;
} }
SHARED_RING_INIT(urb_sring); XEN_FRONT_RING_INIT(&info->urb_ring, urb_sring, PAGE_SIZE);
FRONT_RING_INIT(&info->urb_ring, urb_sring, PAGE_SIZE);
err = xenbus_grant_ring(dev, urb_sring, 1, &gref); err = xenbus_setup_ring(dev, GFP_NOIO | __GFP_HIGH,
if (err < 0) { (void **)&conn_sring, 1, &info->conn_ring_ref);
free_page((unsigned long)urb_sring); if (err) {
info->urb_ring.sring = NULL; xenbus_dev_fatal(dev, err, "allocating conn ring");
goto fail; goto fail;
} }
info->urb_ring_ref = gref; XEN_FRONT_RING_INIT(&info->conn_ring, conn_sring, PAGE_SIZE);
conn_sring = (struct xenusb_conn_sring *)get_zeroed_page(
GFP_NOIO | __GFP_HIGH);
if (!conn_sring) {
xenbus_dev_fatal(dev, -ENOMEM, "allocating conn ring");
err = -ENOMEM;
goto fail;
}
SHARED_RING_INIT(conn_sring);
FRONT_RING_INIT(&info->conn_ring, conn_sring, PAGE_SIZE);
err = xenbus_grant_ring(dev, conn_sring, 1, &gref);
if (err < 0) {
free_page((unsigned long)conn_sring);
info->conn_ring.sring = NULL;
goto fail;
}
info->conn_ring_ref = gref;
err = xenbus_alloc_evtchn(dev, &info->evtchn); err = xenbus_alloc_evtchn(dev, &info->evtchn);
if (err) { if (err) {