af_packet: preserve const qualifier in pkt_sk()
authorEric Dumazet <edumazet@google.com>
Fri, 17 Mar 2023 15:55:31 +0000 (15:55 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 18 Mar 2023 12:23:33 +0000 (12:23 +0000)
We can change pkt_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>
net/packet/internal.h

index 680703dbce5e04fc26d0fdeab1c1c911b71a8729..e793e99646f1c60f61a8dc5e765f8f544de83972 100644 (file)
@@ -133,10 +133,7 @@ struct packet_sock {
        atomic_t                tp_drops ____cacheline_aligned_in_smp;
 };
 
-static inline struct packet_sock *pkt_sk(struct sock *sk)
-{
-       return (struct packet_sock *)sk;
-}
+#define pkt_sk(ptr) container_of_const(ptr, struct packet_sock, sk)
 
 enum packet_sock_flags {
        PACKET_SOCK_ORIGDEV,