Skip to content

Commit 58169ec

Browse files
edumazetkuba-moo
authored andcommitted
inet: preserve const qualifier in inet_csk()
We can change inet_csk() to propagate its argument const qualifier, thanks to container_of_const(). We have to fix few places that had mistakes, like tcp_bound_rto(). Signed-off-by: Eric Dumazet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 513bebc commit 58169ec

File tree

7 files changed

+8
-11
lines changed

7 files changed

+8
-11
lines changed

include/net/espintcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct espintcp_ctx {
3232

3333
static inline struct espintcp_ctx *espintcp_getctx(const struct sock *sk)
3434
{
35-
struct inet_connection_sock *icsk = inet_csk(sk);
35+
const struct inet_connection_sock *icsk = inet_csk(sk);
3636

3737
/* RCU is only needed for diag */
3838
return (__force void *)icsk->icsk_ulp_data;

include/net/inet_connection_sock.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ struct inet_connection_sock {
147147
#define ICSK_TIME_LOSS_PROBE 5 /* Tail loss probe timer */
148148
#define ICSK_TIME_REO_TIMEOUT 6 /* Reordering timer */
149149

150-
static inline struct inet_connection_sock *inet_csk(const struct sock *sk)
151-
{
152-
return (struct inet_connection_sock *)sk;
153-
}
150+
#define inet_csk(ptr) container_of_const(ptr, struct inet_connection_sock, icsk_inet.sk)
154151

155152
static inline void *inet_csk_ca(const struct sock *sk)
156153
{

include/net/tcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ int tcp_mtu_to_mss(struct sock *sk, int pmtu);
742742
int tcp_mss_to_mtu(struct sock *sk, int mss);
743743
void tcp_mtup_init(struct sock *sk);
744744

745-
static inline void tcp_bound_rto(const struct sock *sk)
745+
static inline void tcp_bound_rto(struct sock *sk)
746746
{
747747
if (inet_csk(sk)->icsk_rto > TCP_RTO_MAX)
748748
inet_csk(sk)->icsk_rto = TCP_RTO_MAX;

include/net/tls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static inline bool tls_is_skb_tx_device_offloaded(const struct sk_buff *skb)
361361

362362
static inline struct tls_context *tls_get_ctx(const struct sock *sk)
363363
{
364-
struct inet_connection_sock *icsk = inet_csk(sk);
364+
const struct inet_connection_sock *icsk = inet_csk(sk);
365365

366366
/* Use RCU on icsk_ulp_data only for sock diag code,
367367
* TLS data path doesn't need rcu_dereference().

net/ipv4/tcp_input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6999,7 +6999,7 @@ EXPORT_SYMBOL(inet_reqsk_alloc);
69996999
/*
70007000
* Return true if a syncookie should be sent
70017001
*/
7002-
static bool tcp_syn_flood_action(const struct sock *sk, const char *proto)
7002+
static bool tcp_syn_flood_action(struct sock *sk, const char *proto)
70037003
{
70047004
struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue;
70057005
const char *msg = "Dropping request";

net/ipv4/tcp_timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)
2727
{
28-
struct inet_connection_sock *icsk = inet_csk(sk);
28+
const struct inet_connection_sock *icsk = inet_csk(sk);
2929
const struct tcp_sock *tp = tcp_sk(sk);
3030
u32 elapsed, user_timeout;
3131
s32 remaining;
@@ -47,7 +47,7 @@ static u32 tcp_clamp_rto_to_user_timeout(const struct sock *sk)
4747

4848
u32 tcp_clamp_probe0_to_user_timeout(const struct sock *sk, u32 when)
4949
{
50-
struct inet_connection_sock *icsk = inet_csk(sk);
50+
const struct inet_connection_sock *icsk = inet_csk(sk);
5151
u32 remaining, user_timeout;
5252
s32 elapsed;
5353

net/mptcp/protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ struct mptcp_subflow_context {
558558
static inline struct mptcp_subflow_context *
559559
mptcp_subflow_ctx(const struct sock *sk)
560560
{
561-
struct inet_connection_sock *icsk = inet_csk(sk);
561+
const struct inet_connection_sock *icsk = inet_csk(sk);
562562

563563
/* Use RCU on icsk_ulp_data only for sock diag code */
564564
return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data;

0 commit comments

Comments
 (0)