memblock: use memblock_free for freeing virtual pointers
authorMike Rapoport <rppt@linux.ibm.com>
Fri, 5 Nov 2021 20:43:22 +0000 (13:43 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 6 Nov 2021 20:30:41 +0000 (13:30 -0700)
Rename memblock_free_ptr() to memblock_free() and use memblock_free()
when freeing a virtual pointer so that memblock_free() will be a
counterpart of memblock_alloc()

The callers are updated with the below semantic patch and manual
addition of (void *) casting to pointers that are represented by
unsigned long variables.

    @@
    identifier vaddr;
    expression size;
    @@
    (
    - memblock_phys_free(__pa(vaddr), size);
    + memblock_free(vaddr, size);
    |
    - memblock_free_ptr(vaddr, size);
    + memblock_free(vaddr, size);
    )

[sfr@canb.auug.org.au: fixup]
Link: https://lkml.kernel.org/r/20211018192940.3d1d532f@canb.auug.org.au
Link: https://lkml.kernel.org/r/20210930185031.18648-7-rppt@kernel.org
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Juergen Gross <jgross@suse.com>
Cc: Shahab Vahedi <Shahab.Vahedi@synopsys.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
29 files changed:
arch/alpha/kernel/core_irongate.c
arch/mips/mm/init.c
arch/powerpc/kernel/dt_cpu_ftrs.c
arch/powerpc/kernel/setup-common.c
arch/powerpc/kernel/setup_64.c
arch/powerpc/platforms/powernv/pci-ioda.c
arch/powerpc/platforms/pseries/svm.c
arch/riscv/kernel/setup.c
arch/sparc/kernel/smp_64.c
arch/um/kernel/mem.c
arch/x86/kernel/setup_percpu.c
arch/x86/mm/kasan_init_64.c
arch/x86/mm/numa.c
arch/x86/mm/numa_emulation.c
arch/x86/xen/mmu_pv.c
arch/x86/xen/p2m.c
drivers/base/arch_numa.c
drivers/macintosh/smu.c
drivers/xen/swiotlb-xen.c
include/linux/memblock.h
init/initramfs.c
init/main.c
kernel/dma/swiotlb.c
kernel/printk/printk.c
lib/bootconfig.c
lib/cpumask.c
mm/memblock.c
mm/percpu.c
mm/sparse.c

index ee26dcc494186fd5526ba558e3a9ee8e0a0ecb4d..6b8ed12936b6f131c4276d2d1283d876d42846a6 100644 (file)
@@ -233,8 +233,7 @@ albacore_init_arch(void)
                        unsigned long size;
 
                        size = initrd_end - initrd_start;
-                       memblock_phys_free(__pa(initrd_start),
-                                          PAGE_ALIGN(size));
+                       memblock_free((void *)initrd_start, PAGE_ALIGN(size));
                        if (!move_initrd(pci_mem))
                                printk("irongate_init_arch: initrd too big "
                                       "(%ldK)\ndisabling initrd\n",
index 3be1c29084fa8b2f7bc09e3c47f13edcecab95b4..325e1552cbeada70d870ff2179a9ae70bf26c120 100644 (file)
@@ -529,7 +529,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size,
 
 static void __init pcpu_fc_free(void *ptr, size_t size)
 {
-       memblock_phys_free(__pa(ptr), size);
+       memblock_free(ptr, size);
 }
 
 void __init setup_per_cpu_areas(void)
index 42839d6bd486007e496b624dd94f3988edea8a4f..ba527fb529931bb700ba15a944d13ea5deeffb52 100644 (file)
@@ -1095,8 +1095,8 @@ static int __init dt_cpu_ftrs_scan_callback(unsigned long node, const char
 
        cpufeatures_setup_finished();
 
-       memblock_phys_free(__pa(dt_cpu_features),
-                          sizeof(struct dt_cpu_feature) * nr_dt_cpu_features);
+       memblock_free(dt_cpu_features,
+                     sizeof(struct dt_cpu_feature) * nr_dt_cpu_features);
 
        return 0;
 }
index 5af8993a8e6db591efee9cdc14bb7bf670f6f14d..6b1338db87795912d3c02989aa93dfd65d40225e 100644 (file)
@@ -825,7 +825,7 @@ static void __init smp_setup_pacas(void)
                set_hard_smp_processor_id(cpu, cpu_to_phys_id[cpu]);
        }
 
-       memblock_phys_free(__pa(cpu_to_phys_id), nr_cpu_ids * sizeof(u32));
+       memblock_free(cpu_to_phys_id, nr_cpu_ids * sizeof(u32));
        cpu_to_phys_id = NULL;
 }
 #endif
index 75bc294ac40d7fd834166e53690be0f157273b3a..1777e992b20bdb17d27432205a284bfba07899ca 100644 (file)
@@ -812,7 +812,7 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, size_t size,
 
 static void __init pcpu_free_bootmem(void *ptr, size_t size)
 {
-       memblock_phys_free(__pa(ptr), size);
+       memblock_free(ptr, size);
 }
 
 static int pcpu_cpu_distance(unsigned int from, unsigned int to)
index b5a9d343b7205f1254b4b4c4ea3880baafe9804f..004cd6a96c8a03d85cb17d6c0cacbed104654171 100644 (file)
@@ -2981,7 +2981,7 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
        if (!phb->hose) {
                pr_err("  Can't allocate PCI controller for %pOF\n",
                       np);
-               memblock_phys_free(__pa(phb), sizeof(struct pnv_phb));
+               memblock_free(phb, sizeof(struct pnv_phb));
                return;
        }
 
index b7c017bb40f7fe4b209461953765d62c6a836b23..6332365d28917cf4f511d53e0e8b29b3acb7ba16 100644 (file)
@@ -56,8 +56,7 @@ void __init svm_swiotlb_init(void)
                return;
 
 
-       memblock_phys_free(__pa(vstart),
-                          PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
+       memblock_free(vstart, PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
        panic("SVM: Cannot allocate SWIOTLB buffer");
 }
 
index 6ea7c53b82cd8d3c6aeb4114f5559850dd05380c..b42bfdc674823cec93ab3342235f12c5b867b611 100644 (file)
@@ -230,14 +230,13 @@ static void __init init_resources(void)
 
        /* Clean-up any unused pre-allocated resources */
        if (res_idx >= 0)
-               memblock_phys_free(__pa(mem_res),
-                                  (res_idx + 1) * sizeof(*mem_res));
+               memblock_free(mem_res, (res_idx + 1) * sizeof(*mem_res));
        return;
 
  error:
        /* Better an empty resource tree than an inconsistent one */
        release_child_resources(&iomem_resource);
-       memblock_phys_free(__pa(mem_res), mem_res_sz);
+       memblock_free(mem_res, mem_res_sz);
 }
 
 
index 2507549538df19c842b2215fa9ebbb9536f15f22..b98a7bbe6728a015b00f92e027c165b9003ef251 100644 (file)
@@ -1567,7 +1567,7 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, size_t size,
 
 static void __init pcpu_free_bootmem(void *ptr, size_t size)
 {
-       memblock_phys_free(__pa(ptr), size);
+       memblock_free(ptr, size);
 }
 
 static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
index d1710ebb44f4756dd1cf8b5874977829aff93de3..0039771eb01cd40f9bb163bedf5f914b95bdea5b 100644 (file)
@@ -47,7 +47,7 @@ void __init mem_init(void)
         */
        brk_end = (unsigned long) UML_ROUND_UP(sbrk(0));
        map_memory(brk_end, __pa(brk_end), uml_reserved - brk_end, 1, 1, 0);
-       memblock_phys_free(__pa(brk_end), uml_reserved - brk_end);
+       memblock_free((void *)brk_end, uml_reserved - brk_end);
        uml_reserved = brk_end;
 
        /* this will put all low memory onto the freelists */
index 5afd985591939cc285f0b035cc2e2fc810cef4e2..7b65275544b2c3dc7adc6b43c4f7681288e0e75e 100644 (file)
@@ -135,7 +135,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)
 
 static void __init pcpu_fc_free(void *ptr, size_t size)
 {
-       memblock_free_ptr(ptr, size);
+       memblock_free(ptr, size);
 }
 
 static int __init pcpu_cpu_distance(unsigned int from, unsigned int to)
index ef885370719a605876b3375e22db72f8d025cb64..e7b9b464a82f1d0798284a34ecc943db316e7095 100644 (file)
@@ -49,7 +49,7 @@ static void __init kasan_populate_pmd(pmd_t *pmd, unsigned long addr,
                        p = early_alloc(PMD_SIZE, nid, false);
                        if (p && pmd_set_huge(pmd, __pa(p), PAGE_KERNEL))
                                return;
-                       memblock_free_ptr(p, PMD_SIZE);
+                       memblock_free(p, PMD_SIZE);
                }
 
                p = early_alloc(PAGE_SIZE, nid, true);
@@ -85,7 +85,7 @@ static void __init kasan_populate_pud(pud_t *pud, unsigned long addr,
                        p = early_alloc(PUD_SIZE, nid, false);
                        if (p && pud_set_huge(pud, __pa(p), PAGE_KERNEL))
                                return;
-                       memblock_free_ptr(p, PUD_SIZE);
+                       memblock_free(p, PUD_SIZE);
                }
 
                p = early_alloc(PAGE_SIZE, nid, true);
index 1e9b93b088dbf0dc454d2ebb30dcab055d1f7f59..c6b1213086d6330222a5ee19f70eb7193b4b8ec9 100644 (file)
@@ -355,7 +355,7 @@ void __init numa_reset_distance(void)
 
        /* numa_distance could be 1LU marking allocation failure, test cnt */
        if (numa_distance_cnt)
-               memblock_free_ptr(numa_distance, size);
+               memblock_free(numa_distance, size);
        numa_distance_cnt = 0;
        numa_distance = NULL;   /* enable table creation */
 }
index e801e30089c436087681b8f09ad88e76d3046d56..1a02b791d273cb1e9981663d67131f01c211753e 100644 (file)
@@ -517,7 +517,7 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt)
        }
 
        /* free the copied physical distance table */
-       memblock_free_ptr(phys_dist, phys_size);
+       memblock_free(phys_dist, phys_size);
        return;
 
 no_emu:
index 676d8d292f8a317966d79547110b4cd86695b946..173de1e29bda983596e298890858319c8a01285d 100644 (file)
@@ -1151,7 +1151,7 @@ static void __init xen_pagetable_p2m_free(void)
                xen_cleanhighmap(addr, addr + size);
                size = PAGE_ALIGN(xen_start_info->nr_pages *
                                  sizeof(unsigned long));
-               memblock_phys_free(__pa(addr), size);
+               memblock_free((void *)addr, size);
        } else {
                xen_cleanmfnmap(addr);
        }
index 141bb9dbd2fbe06fc776aa97648ab86d675e8c5c..58db86f7b3846ef04b749154f0c9e9178654a806 100644 (file)
@@ -197,7 +197,7 @@ static void * __ref alloc_p2m_page(void)
 static void __ref free_p2m_page(void *p)
 {
        if (unlikely(!slab_is_available())) {
-               memblock_free_ptr(p, PAGE_SIZE);
+               memblock_free(p, PAGE_SIZE);
                return;
        }
 
index 712edef039295bb55e227c84a78c502f7e749e51..bc1876915457d47e2ea3e7c26729964fc4a97ef4 100644 (file)
@@ -166,7 +166,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size,
 
 static void __init pcpu_fc_free(void *ptr, size_t size)
 {
-       memblock_phys_free(__pa(ptr), size);
+       memblock_free(ptr, size);
 }
 
 #ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
@@ -326,7 +326,7 @@ void __init numa_free_distance(void)
        size = numa_distance_cnt * numa_distance_cnt *
                sizeof(numa_distance[0]);
 
-       memblock_free_ptr(numa_distance, size);
+       memblock_free(numa_distance, size);
        numa_distance_cnt = 0;
        numa_distance = NULL;
 }
index fe63d5ee201b866c0e0681b9605e60ba4aaf2720..f621521112363a96409b5558bf5500acfe68c163 100644 (file)
@@ -570,7 +570,7 @@ fail_msg_node:
 fail_db_node:
        of_node_put(smu->db_node);
 fail_bootmem:
-       memblock_free_ptr(smu, sizeof(struct smu_device));
+       memblock_free(smu, sizeof(struct smu_device));
        smu = NULL;
 fail_np:
        of_node_put(np);
index 4b671cc0a7ea5f9d0bcf6773319d3fb70f14e5bd..f083194e26344bc37f4597036968db5e555a7865 100644 (file)
@@ -241,7 +241,7 @@ retry:
         */
        rc = xen_swiotlb_fixup(start, nslabs);
        if (rc) {
-               memblock_phys_free(__pa(start), PAGE_ALIGN(bytes));
+               memblock_free(start, PAGE_ALIGN(bytes));
                if (nslabs > 1024 && repeat--) {
                        /* Min is 2MB */
                        nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
index d32d417095137206f81a6b5c6ef6da42ee24b5c8..484650681beeb88571416328b5068caa02e1fa59 100644 (file)
@@ -118,7 +118,7 @@ int memblock_mark_nomap(phys_addr_t base, phys_addr_t size);
 int memblock_clear_nomap(phys_addr_t base, phys_addr_t size);
 
 void memblock_free_all(void);
-void memblock_free_ptr(void *ptr, size_t size);
+void memblock_free(void *ptr, size_t size);
 void reset_node_managed_pages(pg_data_t *pgdat);
 void reset_all_zones_managed_pages(void);
 
index 1a971f070dd40e43b1cec74fcfd9f3eb6c8d7b06..2f3d96dc3db6d0a689f5c17a5f572ea5bd07f2f2 100644 (file)
@@ -607,7 +607,7 @@ void __weak __init free_initrd_mem(unsigned long start, unsigned long end)
        unsigned long aligned_start = ALIGN_DOWN(start, PAGE_SIZE);
        unsigned long aligned_end = ALIGN(end, PAGE_SIZE);
 
-       memblock_phys_free(__pa(aligned_start), aligned_end - aligned_start);
+       memblock_free((void *)aligned_start, aligned_end - aligned_start);
 #endif
 
        free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
index 767ee2672176022f6f9529d7606e54abfaa78da2..f0001af8ebb90b428d0a8847e411b194f71214de 100644 (file)
@@ -382,7 +382,7 @@ static char * __init xbc_make_cmdline(const char *key)
        ret = xbc_snprint_cmdline(new_cmdline, len + 1, root);
        if (ret < 0 || ret > len) {
                pr_err("Failed to print extra kernel cmdline.\n");
-               memblock_free_ptr(new_cmdline, len + 1);
+               memblock_free(new_cmdline, len + 1);
                return NULL;
        }
 
@@ -925,7 +925,7 @@ static void __init print_unknown_bootoptions(void)
                end += sprintf(end, " %s", *p);
 
        pr_notice("Unknown command line parameters:%s\n", unknown_options);
-       memblock_free_ptr(unknown_options, len);
+       memblock_free(unknown_options, len);
 }
 
 asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
index b9fa173e5e56d57c8f625a49fd6e47046a25fb6a..02656d7ccbfd1e4cbd5db690235d85bd1c6e4680 100644 (file)
@@ -247,7 +247,7 @@ swiotlb_init(int verbose)
        return;
 
 fail_free_mem:
-       memblock_phys_free(__pa(tlb), bytes);
+       memblock_free(tlb, bytes);
 fail:
        pr_warn("Cannot allocate buffer");
 }
index a8d0a58deebc708b08574bee0e29bbbe5ff961b1..2cae1bfa6be7be611df60f70d6be13abfa98e744 100644 (file)
@@ -1166,9 +1166,9 @@ void __init setup_log_buf(int early)
        return;
 
 err_free_descs:
-       memblock_free_ptr(new_descs, new_descs_size);
+       memblock_free(new_descs, new_descs_size);
 err_free_log_buf:
-       memblock_free_ptr(new_log_buf, new_log_buf_len);
+       memblock_free(new_log_buf, new_log_buf_len);
 }
 
 static bool __read_mostly ignore_loglevel;
index 5ae248b2937389363c9519954a14f86877def4c7..547558d80e64cbe9287e93de0d3e18b33f7759ae 100644 (file)
@@ -792,7 +792,7 @@ void __init xbc_destroy_all(void)
        xbc_data = NULL;
        xbc_data_size = 0;
        xbc_node_num = 0;
-       memblock_free_ptr(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX);
+       memblock_free(xbc_nodes, sizeof(struct xbc_node) * XBC_NODE_MAX);
        xbc_nodes = NULL;
        brace_index = 0;
 }
index a90786b77c1c283137e74a46592aa9b92a151568..a971a82d2f43607c41a6a4f1b16e49a1a1449421 100644 (file)
@@ -188,7 +188,7 @@ EXPORT_SYMBOL(free_cpumask_var);
  */
 void __init free_bootmem_cpumask_var(cpumask_var_t mask)
 {
-       memblock_phys_free(__pa(mask), cpumask_size());
+       memblock_free(mask, cpumask_size());
 }
 #endif
 
index 52e34abc4abeb92a63f85f699104c35aee562d71..fb0c7f48e627d267630394c5ac6c57f177eebde0 100644 (file)
@@ -472,7 +472,7 @@ static int __init_memblock memblock_double_array(struct memblock_type *type,
                kfree(old_array);
        else if (old_array != memblock_memory_init_regions &&
                 old_array != memblock_reserved_init_regions)
-               memblock_free_ptr(old_array, old_alloc_size);
+               memblock_free(old_array, old_alloc_size);
 
        /*
         * Reserve the new array if that comes from the memblock.  Otherwise, we
@@ -796,14 +796,14 @@ int __init_memblock memblock_remove(phys_addr_t base, phys_addr_t size)
 }
 
 /**
- * memblock_free_ptr - free boot memory allocation
+ * memblock_free - free boot memory allocation
  * @ptr: starting address of the  boot memory allocation
  * @size: size of the boot memory block in bytes
  *
  * Free boot memory block previously allocated by memblock_alloc_xx() API.
  * The freeing memory will not be released to the buddy allocator.
  */
-void __init_memblock memblock_free_ptr(void *ptr, size_t size)
+void __init_memblock memblock_free(void *ptr, size_t size)
 {
        if (ptr)
                memblock_phys_free(__pa(ptr), size);
index d65ddf6f2a353487b9ade8e5e8fed98540297bd2..f5b2c2ea5a548adf4704ee7aacfdade4be3c1c13 100644 (file)
@@ -2472,7 +2472,7 @@ struct pcpu_alloc_info * __init pcpu_alloc_alloc_info(int nr_groups,
  */
 void __init pcpu_free_alloc_info(struct pcpu_alloc_info *ai)
 {
-       memblock_phys_free(__pa(ai), ai->__ai_size);
+       memblock_free(ai, ai->__ai_size);
 }
 
 /**
@@ -3134,7 +3134,7 @@ out_free_areas:
 out_free:
        pcpu_free_alloc_info(ai);
        if (areas)
-               memblock_phys_free(__pa(areas), areas_size);
+               memblock_free(areas, areas_size);
        return rc;
 }
 #endif /* BUILD_EMBED_FIRST_CHUNK */
@@ -3256,7 +3256,7 @@ enomem:
                free_fn(page_address(pages[j]), PAGE_SIZE);
        rc = -ENOMEM;
 out_free_ar:
-       memblock_phys_free(__pa(pages), pages_size);
+       memblock_free(pages, pages_size);
        pcpu_free_alloc_info(ai);
        return rc;
 }
@@ -3286,7 +3286,7 @@ static void * __init pcpu_dfl_fc_alloc(unsigned int cpu, size_t size,
 
 static void __init pcpu_dfl_fc_free(void *ptr, size_t size)
 {
-       memblock_phys_free(__pa(ptr), size);
+       memblock_free(ptr, size);
 }
 
 void __init setup_per_cpu_areas(void)
index fc3ab8d3b6bcdf2117117b9e6b7bcc39056ef273..e5c84b0cf0c9384733477bc3707f61852e07cdb6 100644 (file)
@@ -451,7 +451,7 @@ static void *sparsemap_buf_end __meminitdata;
 static inline void __meminit sparse_buffer_free(unsigned long size)
 {
        WARN_ON(!sparsemap_buf || size == 0);
-       memblock_phys_free(__pa(sparsemap_buf), size);
+       memblock_free(sparsemap_buf, size);
 }
 
 static void __init sparse_buffer_init(unsigned long size, int nid)