* [PATCH 0/2] csky: Convert memory accessors to static inlines
@ 2023-08-08 8:25 Linus Walleij
2023-08-08 8:25 ` [PATCH 1/2] csky: Cast argument to virt_to_pfn() to (void *) Linus Walleij
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Linus Walleij @ 2023-08-08 8:25 UTC (permalink / raw)
To: Vineet Gupta, Guo Ren
Cc: linux-snps-arc, linux-kernel, linux-csky, Linus Walleij
This converts the virt_to_pfn and pfn_to_virt macros
into static inlines so we get proper type checking on
the pointers passed in.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
Linus Walleij (2):
csky: Cast argument to virt_to_pfn() to (void *)
csky: Make pfn accessors static inlines
arch/arc/include/asm/page.h | 2 +-
arch/csky/include/asm/page.h | 13 ++++++++++---
2 files changed, 11 insertions(+), 4 deletions(-)
---
base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
change-id: 20230808-csky-virt-to-phys-3d80c17211f9
Best regards,
--
Linus Walleij <linus.walleij@linaro.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] csky: Cast argument to virt_to_pfn() to (void *)
2023-08-08 8:25 [PATCH 0/2] csky: Convert memory accessors to static inlines Linus Walleij
@ 2023-08-08 8:25 ` Linus Walleij
2023-08-08 8:25 ` [PATCH 2/2] csky: Make pfn accessors static inlines Linus Walleij
2023-08-09 0:15 ` [PATCH 0/2] csky: Convert memory accessors to " Guo Ren
2 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2023-08-08 8:25 UTC (permalink / raw)
To: Vineet Gupta, Guo Ren
Cc: linux-snps-arc, linux-kernel, linux-csky, Linus Walleij
The virt_to_pfn() function takes a (void *) as argument, fix
this up to avoid exploiting the unintended polymorphism of
virt_to_pfn.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
arch/arc/include/asm/page.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h
index e43fe27ec54d..02b53ad811fb 100644
--- a/arch/arc/include/asm/page.h
+++ b/arch/arc/include/asm/page.h
@@ -108,7 +108,7 @@ extern int pfn_valid(unsigned long pfn);
#else /* CONFIG_HIGHMEM */
-#define ARCH_PFN_OFFSET virt_to_pfn(CONFIG_LINUX_RAM_BASE)
+#define ARCH_PFN_OFFSET virt_to_pfn((void *)CONFIG_LINUX_RAM_BASE)
#endif /* CONFIG_HIGHMEM */
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] csky: Make pfn accessors static inlines
2023-08-08 8:25 [PATCH 0/2] csky: Convert memory accessors to static inlines Linus Walleij
2023-08-08 8:25 ` [PATCH 1/2] csky: Cast argument to virt_to_pfn() to (void *) Linus Walleij
@ 2023-08-08 8:25 ` Linus Walleij
2023-08-09 0:15 ` [PATCH 0/2] csky: Convert memory accessors to " Guo Ren
2 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2023-08-08 8:25 UTC (permalink / raw)
To: Vineet Gupta, Guo Ren
Cc: linux-snps-arc, linux-kernel, linux-csky, Linus Walleij
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 to the same thing with pfn_to_virt().
In order to do this we move the virt_to_phys() and
phys_to_virt() below the definitions of the __pa()
and __va() macros so it compiles. The macro version was also
able to do recursive symbol resolution.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
arch/csky/include/asm/page.h | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/arch/csky/include/asm/page.h b/arch/csky/include/asm/page.h
index b23e3006a9e0..80da7e96a8fa 100644
--- a/arch/csky/include/asm/page.h
+++ b/arch/csky/include/asm/page.h
@@ -34,9 +34,6 @@
#include <linux/pfn.h>
-#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
-#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)
-
#define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && \
(void *)(kaddr) < high_memory)
@@ -80,6 +77,16 @@ extern unsigned long va_pa_offset;
#define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
+static inline unsigned long virt_to_pfn(const void *kaddr)
+{
+ return __pa(kaddr) >> PAGE_SHIFT;
+}
+
+static inline void * pfn_to_virt(unsigned long pfn)
+{
+ return __va(pfn) << PAGE_SHIFT;
+}
+
#define MAP_NR(x) PFN_DOWN((unsigned long)(x) - PAGE_OFFSET - \
PHYS_OFFSET_OFFSET)
#define virt_to_page(x) (mem_map + MAP_NR(x))
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] csky: Convert memory accessors to static inlines
2023-08-08 8:25 [PATCH 0/2] csky: Convert memory accessors to static inlines Linus Walleij
2023-08-08 8:25 ` [PATCH 1/2] csky: Cast argument to virt_to_pfn() to (void *) Linus Walleij
2023-08-08 8:25 ` [PATCH 2/2] csky: Make pfn accessors static inlines Linus Walleij
@ 2023-08-09 0:15 ` Guo Ren
2 siblings, 0 replies; 4+ messages in thread
From: Guo Ren @ 2023-08-09 0:15 UTC (permalink / raw)
To: Linus Walleij; +Cc: Vineet Gupta, linux-snps-arc, linux-kernel, linux-csky
On Tue, Aug 8, 2023 at 4:26 PM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> This converts the virt_to_pfn and pfn_to_virt macros
> into static inlines so we get proper type checking on
> the pointers passed in.
>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> Linus Walleij (2):
> csky: Cast argument to virt_to_pfn() to (void *)
> csky: Make pfn accessors static inlines
>
> arch/arc/include/asm/page.h | 2 +-
> arch/csky/include/asm/page.h | 13 ++++++++++---
> 2 files changed, 11 insertions(+), 4 deletions(-)
> ---
> base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
> change-id: 20230808-csky-virt-to-phys-3d80c17211f9
>
> Best regards,
> --
> Linus Walleij <linus.walleij@linaro.org>
>
Thx, Approved.
--
Best Regards
Guo Ren
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-09 0:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-08 8:25 [PATCH 0/2] csky: Convert memory accessors to static inlines Linus Walleij
2023-08-08 8:25 ` [PATCH 1/2] csky: Cast argument to virt_to_pfn() to (void *) Linus Walleij
2023-08-08 8:25 ` [PATCH 2/2] csky: Make pfn accessors static inlines Linus Walleij
2023-08-09 0:15 ` [PATCH 0/2] csky: Convert memory accessors to " Guo Ren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).