Commit df28e869 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'net-better-const'



Eric Dumazet says:

====================
net: better const qualifier awareness

This is a follow-up of d27d367d ("inet: better const qualifier awareness")

Adopting container_of_const() to perform (struct sock *)->(protocol sock *)
operation is allowing us to propagate const qualifier and thus detect
misuses at compile time.

Most conversions are trivial, because most protocols did not adopt yet
const sk pointers where it could make sense.

Only mptcp and tcp patches (end of this series) are requiring small
adjustments.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 39a86d05 e9d9da91
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -305,10 +305,8 @@ struct dccp_sock {
	struct timer_list		dccps_xmit_timer;
};

static inline struct dccp_sock *dccp_sk(const struct sock *sk)
{
	return (struct dccp_sock *)sk;
}
#define dccp_sk(ptr)	container_of_const(ptr, struct dccp_sock, \
					   dccps_inet_connection.icsk_inet.sk)

static inline const char *dccp_role(const struct sock *sk)
{
+1 −4
Original line number Diff line number Diff line
@@ -336,10 +336,7 @@ static inline struct ipv6_pinfo *inet6_sk(const struct sock *__sk)
	return sk_fullsock(__sk) ? inet_sk(__sk)->pinet6 : NULL;
}

static inline struct raw6_sock *raw6_sk(const struct sock *sk)
{
	return (struct raw6_sock *)sk;
}
#define raw6_sk(ptr) container_of_const(ptr, struct raw6_sock, inet.sk)

#define ipv6_only_sock(sk)	(sk->sk_ipv6only)
#define ipv6_sk_rxinfo(sk)	((sk)->sk_family == PF_INET6 && \
+6 −4
Original line number Diff line number Diff line
@@ -472,10 +472,12 @@ enum tsq_flags {
	TCPF_MTU_REDUCED_DEFERRED	= (1UL << TCP_MTU_REDUCED_DEFERRED),
};

static inline struct tcp_sock *tcp_sk(const struct sock *sk)
{
	return (struct tcp_sock *)sk;
}
#define tcp_sk(ptr) container_of_const(ptr, struct tcp_sock, inet_conn.icsk_inet.sk)

/* Variant of tcp_sk() upgrading a const sock to a read/write tcp socket.
 * Used in context of (lockless) tcp listeners.
 */
#define tcp_sk_rw(ptr) container_of(ptr, struct tcp_sock, inet_conn.icsk_inet.sk)

struct tcp_timewait_sock {
	struct inet_timewait_sock tw_sk;
+1 −4
Original line number Diff line number Diff line
@@ -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)
{
+1 −4
Original line number Diff line number Diff line
@@ -74,10 +74,7 @@ struct unix_sock {
#endif
};

static inline struct unix_sock *unix_sk(const struct sock *sk)
{
	return (struct unix_sock *)sk;
}
#define unix_sk(ptr) container_of_const(ptr, struct unix_sock, sk)

#define peer_wait peer_wq.wait

Loading