Skip to content

Commit 99767f2

Browse files
keesdavem330
authored andcommitted
net/core: Convert sk_timer users to use timer_setup()
In preparation for unconditionally passing the struct timer_list pointer to all timer callbacks, switch to using the new timer_setup() and from_timer() to pass the timer pointer explicitly for all users of sk_timer. Cc: "David S. Miller" <davem@davemloft.net> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Andrew Hendry <andrew.hendry@gmail.com> Cc: Eric Dumazet <edumazet@google.com> Cc: Paolo Abeni <pabeni@redhat.com> Cc: David Howells <dhowells@redhat.com> Cc: Julia Lawall <julia.lawall@lip6.fr> Cc: linzhang <xiaolou4617@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: netdev@vger.kernel.org Cc: linux-hams@vger.kernel.org Cc: linux-x25@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 26566ea commit 99767f2

6 files changed

Lines changed: 46 additions & 42 deletions

File tree

‎net/core/sock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
26832683
sk_init_common(sk);
26842684
sk->sk_send_head = NULL;
26852685

2686-
setup_timer(&sk->sk_timer, NULL, (unsigned long)sk);
2686+
timer_setup(&sk->sk_timer, NULL, 0);
26872687

26882688
sk->sk_allocation = GFP_KERNEL;
26892689
sk->sk_rcvbuf = sysctl_rmem_default;

‎net/netrom/af_netrom.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,9 @@ void nr_destroy_socket(struct sock *);
241241
/*
242242
* Handler for deferred kills.
243243
*/
244-
static void nr_destroy_timer(unsigned long data)
244+
static void nr_destroy_timer(struct timer_list *t)
245245
{
246-
struct sock *sk=(struct sock *)data;
246+
struct sock *sk = from_timer(sk, t, sk_timer);
247247
bh_lock_sock(sk);
248248
sock_hold(sk);
249249
nr_destroy_socket(sk);
@@ -284,7 +284,7 @@ void nr_destroy_socket(struct sock *sk)
284284

285285
if (sk_has_allocations(sk)) {
286286
/* Defer: outstanding buffers */
287-
sk->sk_timer.function = nr_destroy_timer;
287+
sk->sk_timer.function = (TIMER_FUNC_TYPE)nr_destroy_timer;
288288
sk->sk_timer.expires = jiffies + 2 * HZ;
289289
add_timer(&sk->sk_timer);
290290
} else

‎net/netrom/nr_timer.c‎

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@
2929
#include <linux/interrupt.h>
3030
#include <net/netrom.h>
3131

32-
static void nr_heartbeat_expiry(unsigned long);
33-
static void nr_t1timer_expiry(unsigned long);
34-
static void nr_t2timer_expiry(unsigned long);
35-
static void nr_t4timer_expiry(unsigned long);
36-
static void nr_idletimer_expiry(unsigned long);
32+
static void nr_heartbeat_expiry(struct timer_list *);
33+
static void nr_t1timer_expiry(struct timer_list *);
34+
static void nr_t2timer_expiry(struct timer_list *);
35+
static void nr_t4timer_expiry(struct timer_list *);
36+
static void nr_idletimer_expiry(struct timer_list *);
3737

3838
void nr_init_timers(struct sock *sk)
3939
{
4040
struct nr_sock *nr = nr_sk(sk);
4141

42-
setup_timer(&nr->t1timer, nr_t1timer_expiry, (unsigned long)sk);
43-
setup_timer(&nr->t2timer, nr_t2timer_expiry, (unsigned long)sk);
44-
setup_timer(&nr->t4timer, nr_t4timer_expiry, (unsigned long)sk);
45-
setup_timer(&nr->idletimer, nr_idletimer_expiry, (unsigned long)sk);
42+
timer_setup(&nr->t1timer, nr_t1timer_expiry, 0);
43+
timer_setup(&nr->t2timer, nr_t2timer_expiry, 0);
44+
timer_setup(&nr->t4timer, nr_t4timer_expiry, 0);
45+
timer_setup(&nr->idletimer, nr_idletimer_expiry, 0);
4646

4747
/* initialized by sock_init_data */
48-
sk->sk_timer.function = &nr_heartbeat_expiry;
48+
sk->sk_timer.function = (TIMER_FUNC_TYPE)nr_heartbeat_expiry;
4949
}
5050

5151
void nr_start_t1timer(struct sock *sk)
@@ -112,9 +112,9 @@ int nr_t1timer_running(struct sock *sk)
112112
return timer_pending(&nr_sk(sk)->t1timer);
113113
}
114114

115-
static void nr_heartbeat_expiry(unsigned long param)
115+
static void nr_heartbeat_expiry(struct timer_list *t)
116116
{
117-
struct sock *sk = (struct sock *)param;
117+
struct sock *sk = from_timer(sk, t, sk_timer);
118118
struct nr_sock *nr = nr_sk(sk);
119119

120120
bh_lock_sock(sk);
@@ -151,10 +151,10 @@ static void nr_heartbeat_expiry(unsigned long param)
151151
bh_unlock_sock(sk);
152152
}
153153

154-
static void nr_t2timer_expiry(unsigned long param)
154+
static void nr_t2timer_expiry(struct timer_list *t)
155155
{
156-
struct sock *sk = (struct sock *)param;
157-
struct nr_sock *nr = nr_sk(sk);
156+
struct nr_sock *nr = from_timer(nr, t, t2timer);
157+
struct sock *sk = &nr->sock;
158158

159159
bh_lock_sock(sk);
160160
if (nr->condition & NR_COND_ACK_PENDING) {
@@ -164,19 +164,20 @@ static void nr_t2timer_expiry(unsigned long param)
164164
bh_unlock_sock(sk);
165165
}
166166

167-
static void nr_t4timer_expiry(unsigned long param)
167+
static void nr_t4timer_expiry(struct timer_list *t)
168168
{
169-
struct sock *sk = (struct sock *)param;
169+
struct nr_sock *nr = from_timer(nr, t, t4timer);
170+
struct sock *sk = &nr->sock;
170171

171172
bh_lock_sock(sk);
172173
nr_sk(sk)->condition &= ~NR_COND_PEER_RX_BUSY;
173174
bh_unlock_sock(sk);
174175
}
175176

176-
static void nr_idletimer_expiry(unsigned long param)
177+
static void nr_idletimer_expiry(struct timer_list *t)
177178
{
178-
struct sock *sk = (struct sock *)param;
179-
struct nr_sock *nr = nr_sk(sk);
179+
struct nr_sock *nr = from_timer(nr, t, idletimer);
180+
struct sock *sk = &nr->sock;
180181

181182
bh_lock_sock(sk);
182183

@@ -201,10 +202,10 @@ static void nr_idletimer_expiry(unsigned long param)
201202
bh_unlock_sock(sk);
202203
}
203204

204-
static void nr_t1timer_expiry(unsigned long param)
205+
static void nr_t1timer_expiry(struct timer_list *t)
205206
{
206-
struct sock *sk = (struct sock *)param;
207-
struct nr_sock *nr = nr_sk(sk);
207+
struct nr_sock *nr = from_timer(nr, t, t1timer);
208+
struct sock *sk = &nr->sock;
208209

209210
bh_lock_sock(sk);
210211
switch (nr->state) {

‎net/rose/rose_timer.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
#include <linux/interrupt.h>
2929
#include <net/rose.h>
3030

31-
static void rose_heartbeat_expiry(unsigned long);
31+
static void rose_heartbeat_expiry(struct timer_list *t);
3232
static void rose_timer_expiry(struct timer_list *);
3333
static void rose_idletimer_expiry(struct timer_list *);
3434

3535
void rose_start_heartbeat(struct sock *sk)
3636
{
3737
del_timer(&sk->sk_timer);
3838

39-
sk->sk_timer.function = &rose_heartbeat_expiry;
39+
sk->sk_timer.function = (TIMER_FUNC_TYPE)rose_heartbeat_expiry;
4040
sk->sk_timer.expires = jiffies + 5 * HZ;
4141

4242
add_timer(&sk->sk_timer);
@@ -119,9 +119,9 @@ void rose_stop_idletimer(struct sock *sk)
119119
del_timer(&rose_sk(sk)->idletimer);
120120
}
121121

122-
static void rose_heartbeat_expiry(unsigned long param)
122+
static void rose_heartbeat_expiry(struct timer_list *t)
123123
{
124-
struct sock *sk = (struct sock *)param;
124+
struct sock *sk = from_timer(sk, t, sk_timer);
125125
struct rose_sock *rose = rose_sk(sk);
126126

127127
bh_lock_sock(sk);

‎net/x25/af_x25.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,11 @@ static void __x25_destroy_socket(struct sock *);
374374
/*
375375
* handler for deferred kills.
376376
*/
377-
static void x25_destroy_timer(unsigned long data)
377+
static void x25_destroy_timer(struct timer_list *t)
378378
{
379-
x25_destroy_socket_from_timer((struct sock *)data);
379+
struct sock *sk = from_timer(sk, t, sk_timer);
380+
381+
x25_destroy_socket_from_timer(sk);
380382
}
381383

382384
/*
@@ -413,7 +415,7 @@ static void __x25_destroy_socket(struct sock *sk)
413415
if (sk_has_allocations(sk)) {
414416
/* Defer: outstanding buffers */
415417
sk->sk_timer.expires = jiffies + 10 * HZ;
416-
sk->sk_timer.function = x25_destroy_timer;
418+
sk->sk_timer.function = (TIMER_FUNC_TYPE)x25_destroy_timer;
417419
add_timer(&sk->sk_timer);
418420
} else {
419421
/* drop last reference so sock_put will free */

‎net/x25/x25_timer.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
#include <net/tcp_states.h>
2727
#include <net/x25.h>
2828

29-
static void x25_heartbeat_expiry(unsigned long);
30-
static void x25_timer_expiry(unsigned long);
29+
static void x25_heartbeat_expiry(struct timer_list *t);
30+
static void x25_timer_expiry(struct timer_list *t);
3131

3232
void x25_init_timers(struct sock *sk)
3333
{
3434
struct x25_sock *x25 = x25_sk(sk);
3535

36-
setup_timer(&x25->timer, x25_timer_expiry, (unsigned long)sk);
36+
timer_setup(&x25->timer, x25_timer_expiry, 0);
3737

3838
/* initialized by sock_init_data */
39-
sk->sk_timer.function = &x25_heartbeat_expiry;
39+
sk->sk_timer.function = (TIMER_FUNC_TYPE)x25_heartbeat_expiry;
4040
}
4141

4242
void x25_start_heartbeat(struct sock *sk)
@@ -92,9 +92,9 @@ unsigned long x25_display_timer(struct sock *sk)
9292
return x25->timer.expires - jiffies;
9393
}
9494

95-
static void x25_heartbeat_expiry(unsigned long param)
95+
static void x25_heartbeat_expiry(struct timer_list *t)
9696
{
97-
struct sock *sk = (struct sock *)param;
97+
struct sock *sk = from_timer(sk, t, sk_timer);
9898

9999
bh_lock_sock(sk);
100100
if (sock_owned_by_user(sk)) /* can currently only occur in state 3 */
@@ -159,9 +159,10 @@ static inline void x25_do_timer_expiry(struct sock * sk)
159159
}
160160
}
161161

162-
static void x25_timer_expiry(unsigned long param)
162+
static void x25_timer_expiry(struct timer_list *t)
163163
{
164-
struct sock *sk = (struct sock *)param;
164+
struct x25_sock *x25 = from_timer(x25, t, timer);
165+
struct sock *sk = &x25->sk;
165166

166167
bh_lock_sock(sk);
167168
if (sock_owned_by_user(sk)) { /* can currently only occur in state 3 */

0 commit comments

Comments
 (0)