瀏覽代碼

mm: add gfp mask checking for __get_free_pages()

__get_free_pages() with __GFP_HIGHMEM is not safe because the return
address cannot represent a highmem page.  get_zeroed_page() already has
such a debug checking.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Akinobu Mita 15 年之前
父節點
當前提交
945a11136e
共有 1 個文件被更改,包括 9 次插入15 次删除
  1. 9 15
      mm/page_alloc.c

+ 9 - 15
mm/page_alloc.c

@@ -1922,31 +1922,25 @@ EXPORT_SYMBOL(__alloc_pages_nodemask);
  */
  */
 unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order)
 unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order)
 {
 {
-	struct page * page;
+	struct page *page;
+
+	/*
+	 * __get_free_pages() returns a 32-bit address, which cannot represent
+	 * a highmem page
+	 */
+	VM_BUG_ON((gfp_mask & __GFP_HIGHMEM) != 0);
+
 	page = alloc_pages(gfp_mask, order);
 	page = alloc_pages(gfp_mask, order);
 	if (!page)
 	if (!page)
 		return 0;
 		return 0;
 	return (unsigned long) page_address(page);
 	return (unsigned long) page_address(page);
 }
 }
-
 EXPORT_SYMBOL(__get_free_pages);
 EXPORT_SYMBOL(__get_free_pages);
 
 
 unsigned long get_zeroed_page(gfp_t gfp_mask)
 unsigned long get_zeroed_page(gfp_t gfp_mask)
 {
 {
-	struct page * page;
-
-	/*
-	 * get_zeroed_page() returns a 32-bit address, which cannot represent
-	 * a highmem page
-	 */
-	VM_BUG_ON((gfp_mask & __GFP_HIGHMEM) != 0);
-
-	page = alloc_pages(gfp_mask | __GFP_ZERO, 0);
-	if (page)
-		return (unsigned long) page_address(page);
-	return 0;
+	return __get_free_pages(gfp_mask | __GFP_ZERO, 0);
 }
 }
-
 EXPORT_SYMBOL(get_zeroed_page);
 EXPORT_SYMBOL(get_zeroed_page);
 
 
 void __pagevec_free(struct pagevec *pvec)
 void __pagevec_free(struct pagevec *pvec)