Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netmem: use _Generic to cover const casting for page_to_netmem()

The current page_to_netmem() doesn't cover const casting resulting in
trying to cast const struct page * to const netmem_ref fails.

To cover the case, change page_to_netmem() to use macro and _Generic.

Signed-off-by: Byungchul Park <byungchul@sk.com>
Reviewed-by: Mina Almasry <almasrymina@google.com>
Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://patch.msgid.link/20250702053256.4594-5-byungchul@sk.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Byungchul Park and committed by
Jakub Kicinski
4369d40d b56ce868

+3 -4
+3 -4
include/net/netmem.h
··· 139 139 return (__force netmem_ref)((unsigned long)niov | NET_IOV); 140 140 } 141 141 142 - static inline netmem_ref page_to_netmem(const struct page *page) 143 - { 144 - return (__force netmem_ref)page; 145 - } 142 + #define page_to_netmem(p) (_Generic((p), \ 143 + const struct page * : (__force const netmem_ref)(p), \ 144 + struct page * : (__force netmem_ref)(p))) 146 145 147 146 /** 148 147 * virt_to_netmem - convert virtual memory pointer to a netmem reference