udp: preserve const qualifier in udp_sk()
authorEric Dumazet <edumazet@google.com>
Fri, 17 Mar 2023 15:55:30 +0000 (15:55 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 18 Mar 2023 12:23:33 +0000 (12:23 +0000)
We can change udp_sk() to propagate const qualifier of its argument,
thanks to container_of_const()

This should avoid some potential errors caused by accidental
(const -> not_const) promotion.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Willem de Bruijn <willemb@google.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/udp.h

index a2892e151644ec347ad52d426400678e4a53b359..43c1fb2d2c21afc01abdf20e4b9c03f04932c19b 100644 (file)
@@ -97,10 +97,7 @@ struct udp_sock {
 
 #define UDP_MAX_SEGMENTS       (1 << 6UL)
 
-static inline struct udp_sock *udp_sk(const struct sock *sk)
-{
-       return (struct udp_sock *)sk;
-}
+#define udp_sk(ptr) container_of_const(ptr, struct udp_sock, inet.sk)
 
 static inline void udp_set_no_check6_tx(struct sock *sk, bool val)
 {