Skip to content

Commit

Permalink
xen/sndfront: use xenbus_setup_ring() and xenbus_teardown_ring()
Browse files Browse the repository at this point in the history
Simplify sndfront's ring creation and removal via xenbus_setup_ring()
and xenbus_teardown_ring().

Signed-off-by: Juergen Gross <[email protected]>
Reviewed-by: Oleksandr Tyshchenko <[email protected]>
Tested-by: Oleksandr Tyshchenko <[email protected]> # Arm64 only
Signed-off-by: Juergen Gross <[email protected]>
  • Loading branch information
jgross1 committed May 19, 2022
1 parent 2b3daf0 commit 360dc89
Showing 1 changed file with 10 additions and 34 deletions.
44 changes: 10 additions & 34 deletions sound/xen/xen_snd_front_evtchnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
struct xen_snd_front_evtchnl *channel)
{
unsigned long page = 0;
void *page = NULL;

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)
page = (unsigned long)channel->u.evt.page;
page = channel->u.evt.page;

if (!page)
return;
Expand All @@ -167,10 +167,7 @@ static void evtchnl_free(struct xen_snd_front_info *front_info,
xenbus_free_evtchn(front_info->xb_dev, channel->port);

/* End access and free the page. */
if (channel->gref != INVALID_GRANT_REF)
gnttab_end_foreign_access(channel->gref, page);
else
free_page(page);
xenbus_teardown_ring(&page, 1, &channel->gref);

memset(channel, 0, sizeof(*channel));
}
Expand All @@ -196,8 +193,7 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
enum xen_snd_front_evtchnl_type type)
{
struct xenbus_device *xb_dev = front_info->xb_dev;
unsigned long page;
grant_ref_t gref;
void *page;
irq_handler_t handler;
char *handler_name = NULL;
int ret;
Expand All @@ -207,12 +203,9 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
channel->index = index;
channel->front_info = front_info;
channel->state = EVTCHNL_STATE_DISCONNECTED;
channel->gref = INVALID_GRANT_REF;
page = get_zeroed_page(GFP_KERNEL);
if (!page) {
ret = -ENOMEM;
ret = xenbus_setup_ring(xb_dev, GFP_KERNEL, &page, 1, &channel->gref);
if (ret)
goto fail;
}

handler_name = kasprintf(GFP_KERNEL, "%s-%s", XENSND_DRIVER_NAME,
type == EVTCHNL_TYPE_REQ ?
Expand All @@ -226,33 +219,18 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
mutex_init(&channel->ring_io_lock);

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);
mutex_init(&channel->u.req.req_io_lock);
SHARED_RING_INIT(sring);
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;
}
XEN_FRONT_RING_INIT(&channel->u.req.ring, sring, XEN_PAGE_SIZE);

handler = evtchnl_interrupt_req;
} else {
ret = gnttab_grant_foreign_access(xb_dev->otherend_id,
virt_to_gfn((void *)page), 0);
if (ret < 0)
goto fail;

channel->u.evt.page = (struct xensnd_event_page *)page;
gref = ret;
channel->u.evt.page = page;
handler = evtchnl_interrupt_evt;
}

channel->gref = gref;

ret = xenbus_alloc_evtchn(xb_dev, &channel->port);
if (ret < 0)
goto fail;
Expand All @@ -279,8 +257,6 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
return 0;

fail:
if (page)
free_page(page);
kfree(handler_name);
dev_err(&xb_dev->dev, "Failed to allocate ring: %d\n", ret);
return ret;
Expand Down

0 comments on commit 360dc89

Please sign in to comment.