@@ -143,12 +143,12 @@ void xen_snd_front_evtchnl_flush(struct xen_snd_front_evtchnl *channel)
143143static void evtchnl_free (struct xen_snd_front_info * front_info ,
144144 struct xen_snd_front_evtchnl * channel )
145145{
146- unsigned long page = 0 ;
146+ void * page = NULL ;
147147
148148 if (channel -> type == EVTCHNL_TYPE_REQ )
149- page = ( unsigned long ) channel -> u .req .ring .sring ;
149+ page = channel -> u .req .ring .sring ;
150150 else if (channel -> type == EVTCHNL_TYPE_EVT )
151- page = ( unsigned long ) channel -> u .evt .page ;
151+ page = channel -> u .evt .page ;
152152
153153 if (!page )
154154 return ;
@@ -167,10 +167,7 @@ static void evtchnl_free(struct xen_snd_front_info *front_info,
167167 xenbus_free_evtchn (front_info -> xb_dev , channel -> port );
168168
169169 /* End access and free the page. */
170- if (channel -> gref != INVALID_GRANT_REF )
171- gnttab_end_foreign_access (channel -> gref , page );
172- else
173- free_page (page );
170+ xenbus_teardown_ring (& page , 1 , & channel -> gref );
174171
175172 memset (channel , 0 , sizeof (* channel ));
176173}
@@ -196,8 +193,7 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
196193 enum xen_snd_front_evtchnl_type type )
197194{
198195 struct xenbus_device * xb_dev = front_info -> xb_dev ;
199- unsigned long page ;
200- grant_ref_t gref ;
196+ void * page ;
201197 irq_handler_t handler ;
202198 char * handler_name = NULL ;
203199 int ret ;
@@ -207,12 +203,9 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
207203 channel -> index = index ;
208204 channel -> front_info = front_info ;
209205 channel -> state = EVTCHNL_STATE_DISCONNECTED ;
210- channel -> gref = INVALID_GRANT_REF ;
211- page = get_zeroed_page (GFP_KERNEL );
212- if (!page ) {
213- ret = - ENOMEM ;
206+ ret = xenbus_setup_ring (xb_dev , GFP_KERNEL , & page , 1 , & channel -> gref );
207+ if (ret )
214208 goto fail ;
215- }
216209
217210 handler_name = kasprintf (GFP_KERNEL , "%s-%s" , XENSND_DRIVER_NAME ,
218211 type == EVTCHNL_TYPE_REQ ?
@@ -226,33 +219,18 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
226219 mutex_init (& channel -> ring_io_lock );
227220
228221 if (type == EVTCHNL_TYPE_REQ ) {
229- struct xen_sndif_sring * sring = ( struct xen_sndif_sring * ) page ;
222+ struct xen_sndif_sring * sring = page ;
230223
231224 init_completion (& channel -> u .req .completion );
232225 mutex_init (& channel -> u .req .req_io_lock );
233- SHARED_RING_INIT (sring );
234- FRONT_RING_INIT (& channel -> u .req .ring , sring , XEN_PAGE_SIZE );
235-
236- ret = xenbus_grant_ring (xb_dev , sring , 1 , & gref );
237- if (ret < 0 ) {
238- channel -> u .req .ring .sring = NULL ;
239- goto fail ;
240- }
226+ XEN_FRONT_RING_INIT (& channel -> u .req .ring , sring , XEN_PAGE_SIZE );
241227
242228 handler = evtchnl_interrupt_req ;
243229 } else {
244- ret = gnttab_grant_foreign_access (xb_dev -> otherend_id ,
245- virt_to_gfn ((void * )page ), 0 );
246- if (ret < 0 )
247- goto fail ;
248-
249- channel -> u .evt .page = (struct xensnd_event_page * )page ;
250- gref = ret ;
230+ channel -> u .evt .page = page ;
251231 handler = evtchnl_interrupt_evt ;
252232 }
253233
254- channel -> gref = gref ;
255-
256234 ret = xenbus_alloc_evtchn (xb_dev , & channel -> port );
257235 if (ret < 0 )
258236 goto fail ;
@@ -279,8 +257,6 @@ static int evtchnl_alloc(struct xen_snd_front_info *front_info, int index,
279257 return 0 ;
280258
281259fail :
282- if (page )
283- free_page (page );
284260 kfree (handler_name );
285261 dev_err (& xb_dev -> dev , "Failed to allocate ring: %d\n" , ret );
286262 return ret ;
0 commit comments