Commit 46e20d43 authored by Juergen Gross's avatar Juergen Gross

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

Simplify netfront's ring creation and removal via xenbus_setup_ring()
and xenbus_teardown_ring().
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Reviewed-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
parent 47cbd598
......@@ -1921,8 +1921,7 @@ static int setup_netfront(struct xenbus_device *dev,
struct netfront_queue *queue, unsigned int feature_split_evtchn)
{
struct xen_netif_tx_sring *txs;
struct xen_netif_rx_sring *rxs = NULL;
grant_ref_t gref;
struct xen_netif_rx_sring *rxs;
int err;
queue->tx_ring_ref = INVALID_GRANT_REF;
......@@ -1930,33 +1929,19 @@ static int setup_netfront(struct xenbus_device *dev,
queue->rx.sring = NULL;
queue->tx.sring = NULL;
txs = (struct xen_netif_tx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH);
if (!txs) {
err = -ENOMEM;
xenbus_dev_fatal(dev, err, "allocating tx ring page");
err = xenbus_setup_ring(dev, GFP_NOIO | __GFP_HIGH, (void **)&txs,
1, &queue->tx_ring_ref);
if (err)
goto fail;
}
SHARED_RING_INIT(txs);
FRONT_RING_INIT(&queue->tx, txs, XEN_PAGE_SIZE);
err = xenbus_grant_ring(dev, txs, 1, &gref);
if (err < 0)
goto fail;
queue->tx_ring_ref = gref;
XEN_FRONT_RING_INIT(&queue->tx, txs, XEN_PAGE_SIZE);
rxs = (struct xen_netif_rx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH);
if (!rxs) {
err = -ENOMEM;
xenbus_dev_fatal(dev, err, "allocating rx ring page");
err = xenbus_setup_ring(dev, GFP_NOIO | __GFP_HIGH, (void **)&rxs,
1, &queue->rx_ring_ref);
if (err)
goto fail;
}
SHARED_RING_INIT(rxs);
FRONT_RING_INIT(&queue->rx, rxs, XEN_PAGE_SIZE);
err = xenbus_grant_ring(dev, rxs, 1, &gref);
if (err < 0)
goto fail;
queue->rx_ring_ref = gref;
XEN_FRONT_RING_INIT(&queue->rx, rxs, XEN_PAGE_SIZE);
if (feature_split_evtchn)
err = setup_netfront_split(queue);
......@@ -1972,24 +1957,10 @@ static int setup_netfront(struct xenbus_device *dev,
return 0;
/* If we fail to setup netfront, it is safe to just revoke access to
* granted pages because backend is not accessing it at this point.
*/
fail:
if (queue->rx_ring_ref != INVALID_GRANT_REF) {
gnttab_end_foreign_access(queue->rx_ring_ref,
(unsigned long)rxs);
queue->rx_ring_ref = INVALID_GRANT_REF;
} else {
free_page((unsigned long)rxs);
}
if (queue->tx_ring_ref != INVALID_GRANT_REF) {
gnttab_end_foreign_access(queue->tx_ring_ref,
(unsigned long)txs);
queue->tx_ring_ref = INVALID_GRANT_REF;
} else {
free_page((unsigned long)txs);
}
xenbus_teardown_ring((void **)&queue->rx.sring, 1, &queue->rx_ring_ref);
xenbus_teardown_ring((void **)&queue->tx.sring, 1, &queue->tx_ring_ref);
return err;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment