Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9cbb4cb2 authored by Nick Piggin's avatar Nick Piggin Committed by Linus Torvalds
Browse files

mm: find_get_pages_contig fixlet



Testing ->mapping and ->index without a ref is not stable as the page
may have been reused at this point.

Signed-off-by: default avatarNick Piggin <npiggin@kernel.dk>
Reviewed-by: default avatarWu Fengguang <fengguang.wu@intel.com>
Reviewed-by: default avatarMinchan Kim <minchan.kim@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f0bc0a60
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -837,9 +837,6 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index,
		if (radix_tree_deref_retry(page))
			goto restart;

		if (page->mapping == NULL || page->index != index)
			break;

		if (!page_cache_get_speculative(page))
			goto repeat;

@@ -849,6 +846,16 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index,
			goto repeat;
		}

		/*
		 * must check mapping and index after taking the ref.
		 * otherwise we can get both false positives and false
		 * negatives, which is just confusing to the caller.
		 */
		if (page->mapping == NULL || page->index != index) {
			page_cache_release(page);
			break;
		}

		pages[ret] = page;
		ret++;
		index++;