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

Simplify sndfront's ring creation and removal via xenbus_setup_ring()
and xenbus_teardown_ring().

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Tested-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com> # Arm64 only
Signed-off-by: Juergen Gross <jgross@suse.com>
This commit is contained in:
Juergen Gross 2022-04-28 09:01:05 +02:00
parent 2b3daf083a
commit 360dc89d12

View File

@ -143,12 +143,12 @@ void xen_snd_front_evtchnl_flush(struct xen_snd_front_evtchnl *channel)
static void evtchnl_free(struct xen_snd_front_info *front_info, static void evtchnl_free(struct xen_snd_front_info *front_info,
struct xen_snd_front_evtchnl *channel) struct xen_snd_front_evtchnl *channel)
{ {
unsigned long page = 0; void *page = NULL;
if (channel->type == EVTCHNL_TYPE_REQ) if (channel->type == EVTCHNL_TYPE_REQ)
page = (unsigned long)channel->u.req.ring.sring; page = channel->u.req.ring.sring;
else if (channel->type == EVTCHNL_TYPE_EVT) else if (channel->type == EVTCHNL_TYPE_EVT)
page = (unsigned long)channel->u.evt.page; page = channel->u.evt.page;
if (!page) if (!page)
return; return;
@ -167,10 +167,7 @@ static void evtchnl_free(struct xen_snd_front_info *front_info,
xenbus_free_evtchn(front_info->xb_dev, channel->port); xenbus_free_evtchn(front_info->xb_dev, channel->port);
/* End access and free the page. */ /* End access and free the page. */
if (channel->gref != INVALID_GRANT_REF) xenbus_teardown_ring(&page, 1, &channel->gref);
gnttab_end_foreign_access(channel->gref, page);
else
free_page(page);
memset(channel, 0, sizeof(*channel)); memset(channel, 0, sizeof(*channel));
} }
@ -196,8 +193,7 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
enum xen_snd_front_evtchnl_type type) enum xen_snd_front_evtchnl_type type)
{ {
struct xenbus_device *xb_dev = front_info->xb_dev; struct xenbus_device *xb_dev = front_info->xb_dev;
unsigned long page; void *page;
grant_ref_t gref;
irq_handler_t handler; irq_handler_t handler;
char *handler_name = NULL; char *handler_name = NULL;
int ret; int ret;
@ -207,12 +203,9 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
channel->index = index; channel->index = index;
channel->front_info = front_info; channel->front_info = front_info;
channel->state = EVTCHNL_STATE_DISCONNECTED; channel->state = EVTCHNL_STATE_DISCONNECTED;
channel->gref = INVALID_GRANT_REF; ret = xenbus_setup_ring(xb_dev, GFP_KERNEL, &page, 1, &channel->gref);
page = get_zeroed_page(GFP_KERNEL); if (ret)
if (!page) {
ret = -ENOMEM;
goto fail; goto fail;
}
handler_name = kasprintf(GFP_KERNEL, "%s-%s", XENSND_DRIVER_NAME, handler_name = kasprintf(GFP_KERNEL, "%s-%s", XENSND_DRIVER_NAME,
type == EVTCHNL_TYPE_REQ ? type == EVTCHNL_TYPE_REQ ?
@ -226,33 +219,18 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
mutex_init(&channel->ring_io_lock); mutex_init(&channel->ring_io_lock);
if (type == EVTCHNL_TYPE_REQ) { if (type == EVTCHNL_TYPE_REQ) {
struct xen_sndif_sring *sring = (struct xen_sndif_sring *)page; struct xen_sndif_sring *sring = page;
init_completion(&channel->u.req.completion); init_completion(&channel->u.req.completion);
mutex_init(&channel->u.req.req_io_lock); mutex_init(&channel->u.req.req_io_lock);
SHARED_RING_INIT(sring); XEN_FRONT_RING_INIT(&channel->u.req.ring, sring, XEN_PAGE_SIZE);
FRONT_RING_INIT(&channel->u.req.ring, sring, XEN_PAGE_SIZE);
ret = xenbus_grant_ring(xb_dev, sring, 1, &gref);
if (ret < 0) {
channel->u.req.ring.sring = NULL;
goto fail;
}
handler = evtchnl_interrupt_req; handler = evtchnl_interrupt_req;
} else { } else {
ret = gnttab_grant_foreign_access(xb_dev->otherend_id, channel->u.evt.page = page;
virt_to_gfn((void *)page), 0);
if (ret < 0)
goto fail;
channel->u.evt.page = (struct xensnd_event_page *)page;
gref = ret;
handler = evtchnl_interrupt_evt; handler = evtchnl_interrupt_evt;
} }
channel->gref = gref;
ret = xenbus_alloc_evtchn(xb_dev, &channel->port); ret = xenbus_alloc_evtchn(xb_dev, &channel->port);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
@ -279,8 +257,6 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
return 0; return 0;
fail: fail:
if (page)
free_page(page);
kfree(handler_name); kfree(handler_name);
dev_err(&xb_dev->dev, "Failed to allocate ring: %d\n", ret); dev_err(&xb_dev->dev, "Failed to allocate ring: %d\n", ret);
return ret; return ret;