@@ -1921,42 +1921,27 @@ static int setup_netfront(struct xenbus_device *dev,
19211921 struct netfront_queue * queue , unsigned int feature_split_evtchn )
19221922{
19231923 struct xen_netif_tx_sring * txs ;
1924- struct xen_netif_rx_sring * rxs = NULL ;
1925- grant_ref_t gref ;
1924+ struct xen_netif_rx_sring * rxs ;
19261925 int err ;
19271926
19281927 queue -> tx_ring_ref = INVALID_GRANT_REF ;
19291928 queue -> rx_ring_ref = INVALID_GRANT_REF ;
19301929 queue -> rx .sring = NULL ;
19311930 queue -> tx .sring = NULL ;
19321931
1933- txs = (struct xen_netif_tx_sring * )get_zeroed_page (GFP_NOIO | __GFP_HIGH );
1934- if (!txs ) {
1935- err = - ENOMEM ;
1936- xenbus_dev_fatal (dev , err , "allocating tx ring page" );
1932+ err = xenbus_setup_ring (dev , GFP_NOIO | __GFP_HIGH , (void * * )& txs ,
1933+ 1 , & queue -> tx_ring_ref );
1934+ if (err )
19371935 goto fail ;
1938- }
1939- SHARED_RING_INIT (txs );
1940- FRONT_RING_INIT (& queue -> tx , txs , XEN_PAGE_SIZE );
19411936
1942- err = xenbus_grant_ring (dev , txs , 1 , & gref );
1943- if (err < 0 )
1944- goto fail ;
1945- queue -> tx_ring_ref = gref ;
1937+ XEN_FRONT_RING_INIT (& queue -> tx , txs , XEN_PAGE_SIZE );
19461938
1947- rxs = (struct xen_netif_rx_sring * )get_zeroed_page (GFP_NOIO | __GFP_HIGH );
1948- if (!rxs ) {
1949- err = - ENOMEM ;
1950- xenbus_dev_fatal (dev , err , "allocating rx ring page" );
1939+ err = xenbus_setup_ring (dev , GFP_NOIO | __GFP_HIGH , (void * * )& rxs ,
1940+ 1 , & queue -> rx_ring_ref );
1941+ if (err )
19511942 goto fail ;
1952- }
1953- SHARED_RING_INIT (rxs );
1954- FRONT_RING_INIT (& queue -> rx , rxs , XEN_PAGE_SIZE );
19551943
1956- err = xenbus_grant_ring (dev , rxs , 1 , & gref );
1957- if (err < 0 )
1958- goto fail ;
1959- queue -> rx_ring_ref = gref ;
1944+ XEN_FRONT_RING_INIT (& queue -> rx , rxs , XEN_PAGE_SIZE );
19601945
19611946 if (feature_split_evtchn )
19621947 err = setup_netfront_split (queue );
@@ -1972,24 +1957,10 @@ static int setup_netfront(struct xenbus_device *dev,
19721957
19731958 return 0 ;
19741959
1975- /* If we fail to setup netfront, it is safe to just revoke access to
1976- * granted pages because backend is not accessing it at this point.
1977- */
19781960 fail :
1979- if (queue -> rx_ring_ref != INVALID_GRANT_REF ) {
1980- gnttab_end_foreign_access (queue -> rx_ring_ref ,
1981- (unsigned long )rxs );
1982- queue -> rx_ring_ref = INVALID_GRANT_REF ;
1983- } else {
1984- free_page ((unsigned long )rxs );
1985- }
1986- if (queue -> tx_ring_ref != INVALID_GRANT_REF ) {
1987- gnttab_end_foreign_access (queue -> tx_ring_ref ,
1988- (unsigned long )txs );
1989- queue -> tx_ring_ref = INVALID_GRANT_REF ;
1990- } else {
1991- free_page ((unsigned long )txs );
1992- }
1961+ xenbus_teardown_ring ((void * * )& queue -> rx .sring , 1 , & queue -> rx_ring_ref );
1962+ xenbus_teardown_ring ((void * * )& queue -> tx .sring , 1 , & queue -> tx_ring_ref );
1963+
19931964 return err ;
19941965}
19951966
0 commit comments