@@ -769,44 +769,49 @@ void gnttab_free_auto_xlat_frames(void)
769
769
}
770
770
EXPORT_SYMBOL_GPL (gnttab_free_auto_xlat_frames );
771
771
772
- /**
773
- * gnttab_alloc_pages - alloc pages suitable for grant mapping into
774
- * @nr_pages: number of pages to alloc
775
- * @pages: returns the pages
776
- */
777
- int gnttab_alloc_pages (int nr_pages , struct page * * pages )
772
+ int gnttab_pages_set_private (int nr_pages , struct page * * pages )
778
773
{
779
774
int i ;
780
- int ret ;
781
-
782
- ret = alloc_xenballooned_pages (nr_pages , pages );
783
- if (ret < 0 )
784
- return ret ;
785
775
786
776
for (i = 0 ; i < nr_pages ; i ++ ) {
787
777
#if BITS_PER_LONG < 64
788
778
struct xen_page_foreign * foreign ;
789
779
790
780
foreign = kzalloc (sizeof (* foreign ), GFP_KERNEL );
791
- if (!foreign ) {
792
- gnttab_free_pages (nr_pages , pages );
781
+ if (!foreign )
793
782
return - ENOMEM ;
794
- }
783
+
795
784
set_page_private (pages [i ], (unsigned long )foreign );
796
785
#endif
797
786
SetPagePrivate (pages [i ]);
798
787
}
799
788
800
789
return 0 ;
801
790
}
802
- EXPORT_SYMBOL_GPL (gnttab_alloc_pages );
791
+ EXPORT_SYMBOL_GPL (gnttab_pages_set_private );
803
792
804
793
/**
805
- * gnttab_free_pages - free pages allocated by gnttab_alloc_pages()
806
- * @nr_pages; number of pages to free
807
- * @pages: the pages
794
+ * gnttab_alloc_pages - alloc pages suitable for grant mapping into
795
+ * @nr_pages: number of pages to alloc
796
+ * @pages: returns the pages
808
797
*/
809
- void gnttab_free_pages (int nr_pages , struct page * * pages )
798
+ int gnttab_alloc_pages (int nr_pages , struct page * * pages )
799
+ {
800
+ int ret ;
801
+
802
+ ret = alloc_xenballooned_pages (nr_pages , pages );
803
+ if (ret < 0 )
804
+ return ret ;
805
+
806
+ ret = gnttab_pages_set_private (nr_pages , pages );
807
+ if (ret < 0 )
808
+ gnttab_free_pages (nr_pages , pages );
809
+
810
+ return ret ;
811
+ }
812
+ EXPORT_SYMBOL_GPL (gnttab_alloc_pages );
813
+
814
+ void gnttab_pages_clear_private (int nr_pages , struct page * * pages )
810
815
{
811
816
int i ;
812
817
@@ -818,6 +823,17 @@ void gnttab_free_pages(int nr_pages, struct page **pages)
818
823
ClearPagePrivate (pages [i ]);
819
824
}
820
825
}
826
+ }
827
+ EXPORT_SYMBOL_GPL (gnttab_pages_clear_private );
828
+
829
+ /**
830
+ * gnttab_free_pages - free pages allocated by gnttab_alloc_pages()
831
+ * @nr_pages; number of pages to free
832
+ * @pages: the pages
833
+ */
834
+ void gnttab_free_pages (int nr_pages , struct page * * pages )
835
+ {
836
+ gnttab_pages_clear_private (nr_pages , pages );
821
837
free_xenballooned_pages (nr_pages , pages );
822
838
}
823
839
EXPORT_SYMBOL_GPL (gnttab_free_pages );
0 commit comments