diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 36529f3c6554a..133737580a7ec 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -2175,8 +2175,6 @@ int memory_failure(unsigned long pfn, int flags)
 		goto unlock_mutex;
 	}
 
-	hpage = compound_head(p);
-
 	/*
 	 * We need/can do nothing about count=0 pages.
 	 * 1) it's a free page, and therefore in safe hand:
@@ -2215,6 +2213,7 @@ int memory_failure(unsigned long pfn, int flags)
 		}
 	}
 
+	hpage = compound_head(p);
 	if (PageTransHuge(hpage)) {
 		/*
 		 * The flag must be set after the refcount is bumped