x86/mm/cpa: Make cpa_data::numpages invariant
[sfrench/cifs-2.6.git] / arch / x86 / mm / pageattr.c
index 351874259a71391acf60834a5246455f1be6f37d..12b69263e501589ad5972297ea46b777b7b0f997 100644 (file)
@@ -1625,14 +1625,15 @@ static int cpa_process_alias(struct cpa_data *cpa)
 static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
 {
        unsigned long numpages = cpa->numpages;
-       int ret;
+       unsigned long rempages = numpages;
+       int ret = 0;
 
-       while (numpages) {
+       while (rempages) {
                /*
                 * Store the remaining nr of pages for the large page
                 * preservation check.
                 */
-               cpa->numpages = numpages;
+               cpa->numpages = rempages;
                /* for array changes, we can't use large page */
                if (cpa->flags & (CPA_ARRAY | CPA_PAGES_ARRAY))
                        cpa->numpages = 1;
@@ -1643,12 +1644,12 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
                if (!debug_pagealloc_enabled())
                        spin_unlock(&cpa_lock);
                if (ret)
-                       return ret;
+                       goto out;
 
                if (checkalias) {
                        ret = cpa_process_alias(cpa);
                        if (ret)
-                               return ret;
+                               goto out;
                }
 
                /*
@@ -1656,11 +1657,15 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
                 * CPA operation. Either a large page has been
                 * preserved or a single page update happened.
                 */
-               BUG_ON(cpa->numpages > numpages || !cpa->numpages);
-               numpages -= cpa->numpages;
+               BUG_ON(cpa->numpages > rempages || !cpa->numpages);
+               rempages -= cpa->numpages;
                cpa->curpage += cpa->numpages;
        }
-       return 0;
+
+out:
+       /* Restore the original numpages */
+       cpa->numpages = numpages;
+       return ret;
 }
 
 /*