Skip to content

Commit 2d1494f

Browse files
Linus Walleijhcahca
authored andcommitted
s390/mm: make virt_to_pfn() a static inline
Making virt_to_pfn() a static inline taking a strongly typed (const void *) makes the contract of a passing a pointer of that type to the function explicit and exposes any misuse of the macro virt_to_pfn() acting polymorphic and accepting many types such as (void *), (unitptr_t) or (unsigned long) as arguments without warnings. For symmetry do the same with pfn_to_virt() reflecting the current layout in asm-generic/page.h. Doing this reveals a number of offenders in the arch code and the S390-specific drivers, so just bite the bullet and fix up all of those as well. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com> Link: https://lore.kernel.org/r/20230812-virt-to-phys-s390-v2-1-6c40f31fe36f@linaro.org Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent 5cfdff0 commit 2d1494f

6 files changed

Lines changed: 15 additions & 7 deletions

File tree

arch/s390/include/asm/kfence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static __always_inline void kfence_split_mapping(void)
3535

3636
static inline bool kfence_protect_page(unsigned long addr, bool protect)
3737
{
38-
__kernel_map_pages(virt_to_page(addr), 1, !protect);
38+
__kernel_map_pages(virt_to_page((void *)addr), 1, !protect);
3939
return true;
4040
}
4141

arch/s390/include/asm/page.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,16 @@ int arch_make_page_accessible(struct page *page);
191191
#define phys_to_page(phys) pfn_to_page(phys_to_pfn(phys))
192192
#define page_to_phys(page) pfn_to_phys(page_to_pfn(page))
193193

194-
#define pfn_to_virt(pfn) __va(pfn_to_phys(pfn))
195-
#define virt_to_pfn(kaddr) (phys_to_pfn(__pa(kaddr)))
194+
static inline void *pfn_to_virt(unsigned long pfn)
195+
{
196+
return __va(pfn_to_phys(pfn));
197+
}
198+
199+
static inline unsigned long virt_to_pfn(const void *kaddr)
200+
{
201+
return phys_to_pfn(__pa(kaddr));
202+
}
203+
196204
#define pfn_to_kaddr(pfn) pfn_to_virt(pfn)
197205

198206
#define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr))

arch/s390/mm/cmm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static long cmm_alloc_pages(long nr, long *counter,
9090
} else
9191
free_page((unsigned long) npa);
9292
}
93-
diag10_range(virt_to_pfn(addr), 1);
93+
diag10_range(virt_to_pfn((void *)addr), 1);
9494
pa->pages[pa->index++] = addr;
9595
(*counter)++;
9696
spin_unlock(&cmm_lock);

arch/s390/mm/vmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void vmem_free_pages(unsigned long addr, int order)
3636
{
3737
/* We don't expect boot memory to be removed ever. */
3838
if (!slab_is_available() ||
39-
WARN_ON_ONCE(PageReserved(virt_to_page(addr))))
39+
WARN_ON_ONCE(PageReserved(virt_to_page((void *)addr))))
4040
return;
4141
free_pages(addr, order);
4242
}

drivers/s390/block/scm_blk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static void scm_request_done(struct scm_request *scmrq)
134134

135135
if ((msb->flags & MSB_FLAG_IDA) && aidaw &&
136136
IS_ALIGNED(aidaw, PAGE_SIZE))
137-
mempool_free(virt_to_page(aidaw), aidaw_pool);
137+
mempool_free(virt_to_page((void *)aidaw), aidaw_pool);
138138
}
139139

140140
spin_lock_irqsave(&list_lock, flags);

drivers/s390/char/vmcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static void vmcp_response_free(struct vmcp_session *session)
8989
order = get_order(session->bufsize);
9090
nr_pages = ALIGN(session->bufsize, PAGE_SIZE) >> PAGE_SHIFT;
9191
if (session->cma_alloc) {
92-
page = virt_to_page((unsigned long)session->response);
92+
page = virt_to_page(session->response);
9393
cma_release(vmcp_cma, page, nr_pages);
9494
session->cma_alloc = 0;
9595
} else {

0 commit comments

Comments
 (0)