Re: [PATCH 14/18] netmem: use _Generic to cover const casting for page_to_netmem()

From
Mina Almasry <hidden>
Date
2025-05-23 17:15:07
Also in
bpf, linux-mm, linux-rdma, lkml
Reply to
Byungchul Park, 2025-05-23
On Thu, May 22, 2025 at 8:26 PM Byungchul Park [off-list ref] wrote:
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 <redacted>
quoted hunk ↗ jump to hunk
---
 include/net/netmem.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/include/net/netmem.h b/include/net/netmem.h
index 29c005d70c4f..c2eb121181c2 100644
--- a/include/net/netmem.h
+++ b/include/net/netmem.h
@@ -172,10 +172,9 @@ static inline netmem_ref net_iov_to_netmem(struct net_iov *niov)
        return (__force netmem_ref)((unsigned long)niov | NET_IOV);
 }

-static inline netmem_ref page_to_netmem(struct page *page)
-{
-       return (__force netmem_ref)page;
-}
+#define page_to_netmem(p)      (_Generic((p),                  \
+       const struct page *:    (__force const netmem_ref)(p),  \
+       struct page *:          (__force netmem_ref)(p)))

 static inline netmem_ref alloc_netmems_node(int nid, gfp_t gfp_mask,
                unsigned int order)
--
2.17.1

-- 
Thanks,
Mina
Thread (72 messages) 72 messages, 7 authors, last reply 2025-05-28
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help