drm/msms/dp: fixed link clock divider bits be over written in BPC unknown case
[platform/kernel/linux-starfive.git] / mm / sparse.c
index 77d91e5..338cf94 100644 (file)
@@ -792,6 +792,13 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages,
                unsigned long section_nr = pfn_to_section_nr(pfn);
 
                /*
+                * Mark the section invalid so that valid_section()
+                * return false. This prevents code from dereferencing
+                * ms->usage array.
+                */
+               ms->section_mem_map &= ~SECTION_HAS_MEM_MAP;
+
+               /*
                 * When removing an early section, the usage map is kept (as the
                 * usage maps of other sections fall into the same page). It
                 * will be re-used when re-adding the section - which is then no
@@ -799,16 +806,10 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages,
                 * was allocated during boot.
                 */
                if (!PageReserved(virt_to_page(ms->usage))) {
-                       kfree(ms->usage);
-                       ms->usage = NULL;
+                       kfree_rcu(ms->usage, rcu);
+                       WRITE_ONCE(ms->usage, NULL);
                }
                memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr);
-               /*
-                * Mark the section invalid so that valid_section()
-                * return false. This prevents code from dereferencing
-                * ms->usage array.
-                */
-               ms->section_mem_map &= ~SECTION_HAS_MEM_MAP;
        }
 
        /*