Skip to content

Commit

Permalink
[NET]: Convert init_timer into setup_timer
Browse files Browse the repository at this point in the history
Many-many code in the kernel initialized the timer->function
and  timer->data together with calling init_timer(timer). There
is already a helper for this. Use it for networking code.

The patch is HUGE, but makes the code 130 lines shorter
(98 insertions(+), 228 deletions(-)).

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
xemul authored and davem330 committed Jan 28, 2008
1 parent a92aa31 commit b24b8a2
Show file tree
Hide file tree
Showing 47 changed files with 98 additions and 228 deletions.
4 changes: 1 addition & 3 deletions net/802/tr.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,8 @@ struct net_device *alloc_trdev(int sizeof_priv)

static int __init rif_init(void)
{
init_timer(&rif_timer);
rif_timer.expires = jiffies + sysctl_tr_rif_timeout;
rif_timer.data = 0L;
rif_timer.function = rif_check_expire;
setup_timer(&rif_timer, rif_check_expire, 0);
add_timer(&rif_timer);

proc_net_fops_create(&init_net, "tr_rif", S_IRUGO, &rif_seq_fops);
Expand Down
4 changes: 1 addition & 3 deletions net/appletalk/aarp.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,9 +874,7 @@ void __init aarp_proto_init(void)
aarp_dl = register_snap_client(aarp_snap_id, aarp_rcv);
if (!aarp_dl)
printk(KERN_CRIT "Unable to register AARP with SNAP.\n");
init_timer(&aarp_timer);
aarp_timer.function = aarp_expire_timeout;
aarp_timer.data = 0;
setup_timer(&aarp_timer, aarp_expire_timeout, 0);
aarp_timer.expires = jiffies + sysctl_aarp_expiry_time;
add_timer(&aarp_timer);
register_netdevice_notifier(&aarp_notifier);
Expand Down
5 changes: 2 additions & 3 deletions net/appletalk/ddp.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,9 @@ static inline void atalk_destroy_socket(struct sock *sk)

if (atomic_read(&sk->sk_wmem_alloc) ||
atomic_read(&sk->sk_rmem_alloc)) {
init_timer(&sk->sk_timer);
setup_timer(&sk->sk_timer, atalk_destroy_timer,
(unsigned long)sk);
sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME;
sk->sk_timer.function = atalk_destroy_timer;
sk->sk_timer.data = (unsigned long)sk;
add_timer(&sk->sk_timer);
} else
sock_put(sk);
Expand Down
5 changes: 2 additions & 3 deletions net/atm/lec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1789,9 +1789,8 @@ static struct lec_arp_table *make_entry(struct lec_priv *priv,
}
memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
INIT_HLIST_NODE(&to_return->next);
init_timer(&to_return->timer);
to_return->timer.function = lec_arp_expire_arp;
to_return->timer.data = (unsigned long)to_return;
setup_timer(&to_return->timer, lec_arp_expire_arp,
(unsigned long)to_return);
to_return->last_used = jiffies;
to_return->priv = priv;
skb_queue_head_init(&to_return->tx_wait);
Expand Down
5 changes: 2 additions & 3 deletions net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,9 @@ void ax25_destroy_socket(ax25_cb *ax25)
if (atomic_read(&ax25->sk->sk_wmem_alloc) ||
atomic_read(&ax25->sk->sk_rmem_alloc)) {
/* Defer: outstanding buffers */
init_timer(&ax25->dtimer);
setup_timer(&ax25->dtimer, ax25_destroy_timer,
(unsigned long)ax25);
ax25->dtimer.expires = jiffies + 2 * HZ;
ax25->dtimer.function = ax25_destroy_timer;
ax25->dtimer.data = (unsigned long)ax25;
add_timer(&ax25->dtimer);
} else {
struct sock *sk=ax25->sk;
Expand Down
9 changes: 2 additions & 7 deletions net/bluetooth/hci_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,8 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)

skb_queue_head_init(&conn->data_q);

init_timer(&conn->disc_timer);
conn->disc_timer.function = hci_conn_timeout;
conn->disc_timer.data = (unsigned long) conn;

init_timer(&conn->idle_timer);
conn->idle_timer.function = hci_conn_idle;
conn->idle_timer.data = (unsigned long) conn;
setup_timer(&conn->disc_timer, hci_conn_timeout, (unsigned long)conn);
setup_timer(&conn->idle_timer, hci_conn_idle, (unsigned long)conn);

atomic_set(&conn->refcnt, 0);

Expand Down
5 changes: 1 addition & 4 deletions net/bluetooth/hidp/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,7 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock,
session->intr_sock = intr_sock;
session->state = BT_CONNECTED;

init_timer(&session->timer);

session->timer.function = hidp_idle_timeout;
session->timer.data = (unsigned long) session;
setup_timer(&session->timer, hidp_idle_timeout, (unsigned long)session);

skb_queue_head_init(&session->ctrl_transmit);
skb_queue_head_init(&session->intr_transmit);
Expand Down
13 changes: 2 additions & 11 deletions net/bluetooth/l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ static void l2cap_sock_clear_timer(struct sock *sk)
sk_stop_timer(sk, &sk->sk_timer);
}

static void l2cap_sock_init_timer(struct sock *sk)
{
init_timer(&sk->sk_timer);
sk->sk_timer.function = l2cap_sock_timeout;
sk->sk_timer.data = (unsigned long)sk;
}

/* ---- L2CAP channels ---- */
static struct sock *__l2cap_get_chan_by_dcid(struct l2cap_chan_list *l, u16 cid)
{
Expand Down Expand Up @@ -395,9 +388,7 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon, u8 status)

conn->feat_mask = 0;

init_timer(&conn->info_timer);
conn->info_timer.function = l2cap_info_timeout;
conn->info_timer.data = (unsigned long) conn;
setup_timer(&conn->info_timer, l2cap_info_timeout, (unsigned long)conn);

spin_lock_init(&conn->lock);
rwlock_init(&conn->chan_list.lock);
Expand Down Expand Up @@ -622,7 +613,7 @@ static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int p
sk->sk_protocol = proto;
sk->sk_state = BT_OPEN;

l2cap_sock_init_timer(sk);
setup_timer(&sk->sk_timer, l2cap_sock_timeout, (unsigned long)sk);

bt_sock_link(&l2cap_sk_list, sk);
return sk;
Expand Down
4 changes: 1 addition & 3 deletions net/bluetooth/rfcomm/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ struct rfcomm_dlc *rfcomm_dlc_alloc(gfp_t prio)
if (!d)
return NULL;

init_timer(&d->timer);
d->timer.function = rfcomm_dlc_timeout;
d->timer.data = (unsigned long) d;
setup_timer(&d->timer, rfcomm_dlc_timeout, (unsigned long)d);

skb_queue_head_init(&d->tx_queue);
spin_lock_init(&d->lock);
Expand Down
9 changes: 1 addition & 8 deletions net/bluetooth/sco.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ static void sco_sock_clear_timer(struct sock *sk)
sk_stop_timer(sk, &sk->sk_timer);
}

static void sco_sock_init_timer(struct sock *sk)
{
init_timer(&sk->sk_timer);
sk->sk_timer.function = sco_sock_timeout;
sk->sk_timer.data = (unsigned long)sk;
}

/* ---- SCO connections ---- */
static struct sco_conn *sco_conn_add(struct hci_conn *hcon, __u8 status)
{
Expand Down Expand Up @@ -436,7 +429,7 @@ static struct sock *sco_sock_alloc(struct net *net, struct socket *sock, int pro
sk->sk_protocol = proto;
sk->sk_state = BT_OPEN;

sco_sock_init_timer(sk);
setup_timer(&sk->sk_timer, sco_sock_timeout, (unsigned long)sk);

bt_sock_link(&sco_sk_list, sk);
return sk;
Expand Down
3 changes: 1 addition & 2 deletions net/core/flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ static int __init flow_cache_init(void)
flow_lwm = 2 * flow_hash_size;
flow_hwm = 4 * flow_hash_size;

init_timer(&flow_hash_rnd_timer);
flow_hash_rnd_timer.function = flow_cache_new_hashrnd;
setup_timer(&flow_hash_rnd_timer, flow_cache_new_hashrnd, 0);
flow_hash_rnd_timer.expires = jiffies + FLOW_HASH_RND_PERIOD;
add_timer(&flow_hash_rnd_timer);

Expand Down
12 changes: 3 additions & 9 deletions net/core/neighbour.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ static struct neighbour *neigh_alloc(struct neigh_table *tbl)
n->nud_state = NUD_NONE;
n->output = neigh_blackhole;
n->parms = neigh_parms_clone(&tbl->parms);
init_timer(&n->timer);
n->timer.function = neigh_timer_handler;
n->timer.data = (unsigned long)n;
setup_timer(&n->timer, neigh_timer_handler, (unsigned long)n);

NEIGH_CACHE_STAT_INC(tbl, allocs);
n->tbl = tbl;
Expand Down Expand Up @@ -1372,15 +1370,11 @@ void neigh_table_init_no_netlink(struct neigh_table *tbl)
get_random_bytes(&tbl->hash_rnd, sizeof(tbl->hash_rnd));

rwlock_init(&tbl->lock);
init_timer(&tbl->gc_timer);
tbl->gc_timer.data = (unsigned long)tbl;
tbl->gc_timer.function = neigh_periodic_timer;
setup_timer(&tbl->gc_timer, neigh_periodic_timer, (unsigned long)tbl);
tbl->gc_timer.expires = now + 1;
add_timer(&tbl->gc_timer);

init_timer(&tbl->proxy_timer);
tbl->proxy_timer.data = (unsigned long)tbl;
tbl->proxy_timer.function = neigh_proxy_process;
setup_timer(&tbl->proxy_timer, neigh_proxy_process, (unsigned long)tbl);
skb_queue_head_init_class(&tbl->proxy_queue,
&neigh_table_proxy_queue_class);

Expand Down
6 changes: 2 additions & 4 deletions net/dccp/ccids/ccid2.c
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,8 @@ static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
hctx->ccid2hctx_rttvar = -1;
hctx->ccid2hctx_rpdupack = -1;
hctx->ccid2hctx_last_cong = jiffies;

hctx->ccid2hctx_rtotimer.function = &ccid2_hc_tx_rto_expire;
hctx->ccid2hctx_rtotimer.data = (unsigned long)sk;
init_timer(&hctx->ccid2hctx_rtotimer);
setup_timer(&hctx->ccid2hctx_rtotimer, ccid2_hc_tx_rto_expire,
(unsigned long)sk);

ccid2_hc_tx_check_sanity(hctx);
return 0;
Expand Down
7 changes: 2 additions & 5 deletions net/dccp/ccids/ccid3.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,8 @@ static int ccid3_hc_tx_init(struct ccid *ccid, struct sock *sk)

hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT;
INIT_LIST_HEAD(&hctx->ccid3hctx_hist);

hctx->ccid3hctx_no_feedback_timer.function =
ccid3_hc_tx_no_feedback_timer;
hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk;
init_timer(&hctx->ccid3hctx_no_feedback_timer);
setup_timer(&hctx->ccid3hctx_no_feedback_timer,
ccid3_hc_tx_no_feedback_timer, (unsigned long)sk);

return 0;
}
Expand Down
5 changes: 2 additions & 3 deletions net/dccp/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,8 @@ static void dccp_init_write_xmit_timer(struct sock *sk)
{
struct dccp_sock *dp = dccp_sk(sk);

init_timer(&dp->dccps_xmit_timer);
dp->dccps_xmit_timer.data = (unsigned long)sk;
dp->dccps_xmit_timer.function = dccp_write_xmit_timer;
setup_timer(&dp->dccps_xmit_timer, dccp_write_xmit_timer,
(unsigned long)sk);
}

void dccp_init_xmit_timers(struct sock *sk)
Expand Down
3 changes: 1 addition & 2 deletions net/decnet/dn_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -1752,8 +1752,7 @@ void __init dn_route_init(void)
dn_dst_ops.kmem_cachep =
kmem_cache_create("dn_dst_cache", sizeof(struct dn_route), 0,
SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
init_timer(&dn_route_timer);
dn_route_timer.function = dn_dst_check_expire;
setup_timer(&dn_route_timer, dn_dst_check_expire, 0);
dn_route_timer.expires = jiffies + decnet_dst_gc_interval * HZ;
add_timer(&dn_route_timer);

Expand Down
3 changes: 1 addition & 2 deletions net/econet/af_econet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,9 +1014,8 @@ static int __init aun_udp_initialise(void)

skb_queue_head_init(&aun_queue);
spin_lock_init(&aun_queue_lock);
init_timer(&ab_cleanup_timer);
setup_timer(&ab_cleanup_timer, ab_cleanup, 0);
ab_cleanup_timer.expires = jiffies + (HZ*2);
ab_cleanup_timer.function = ab_cleanup;
add_timer(&ab_cleanup_timer);

memset(&sin, 0, sizeof(sin));
Expand Down
5 changes: 2 additions & 3 deletions net/ieee80211/ieee80211_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,8 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
ieee->ieee802_1x = 1; /* Default to supporting 802.1x */

INIT_LIST_HEAD(&ieee->crypt_deinit_list);
init_timer(&ieee->crypt_deinit_timer);
ieee->crypt_deinit_timer.data = (unsigned long)ieee;
ieee->crypt_deinit_timer.function = ieee80211_crypt_deinit_handler;
setup_timer(&ieee->crypt_deinit_timer, ieee80211_crypt_deinit_handler,
(unsigned long)ieee);
ieee->crypt_quiesced = 0;

spin_lock_init(&ieee->lock);
Expand Down
14 changes: 5 additions & 9 deletions net/ipv4/igmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1234,9 +1234,7 @@ void ip_mc_inc_group(struct in_device *in_dev, __be32 addr)
spin_lock_init(&im->lock);
#ifdef CONFIG_IP_MULTICAST
im->tm_running=0;
init_timer(&im->timer);
im->timer.data=(unsigned long)im;
im->timer.function=&igmp_timer_expire;
setup_timer(&im->timer, &igmp_timer_expire, (unsigned long)im);
im->unsolicit_count = IGMP_Unsolicited_Report_Count;
im->reporter = 0;
im->gsquery = 0;
Expand Down Expand Up @@ -1338,13 +1336,11 @@ void ip_mc_init_dev(struct in_device *in_dev)
in_dev->mc_tomb = NULL;
#ifdef CONFIG_IP_MULTICAST
in_dev->mr_gq_running = 0;
init_timer(&in_dev->mr_gq_timer);
in_dev->mr_gq_timer.data=(unsigned long) in_dev;
in_dev->mr_gq_timer.function=&igmp_gq_timer_expire;
setup_timer(&in_dev->mr_gq_timer, igmp_gq_timer_expire,
(unsigned long)in_dev);
in_dev->mr_ifc_count = 0;
init_timer(&in_dev->mr_ifc_timer);
in_dev->mr_ifc_timer.data=(unsigned long) in_dev;
in_dev->mr_ifc_timer.function=&igmp_ifc_timer_expire;
setup_timer(&in_dev->mr_ifc_timer, igmp_ifc_timer_expire,
(unsigned long)in_dev);
in_dev->mr_qrv = IGMP_Unsolicited_Report_Count;
#endif

Expand Down
17 changes: 5 additions & 12 deletions net/ipv4/inet_connection_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,11 @@ void inet_csk_init_xmit_timers(struct sock *sk,
{
struct inet_connection_sock *icsk = inet_csk(sk);

init_timer(&icsk->icsk_retransmit_timer);
init_timer(&icsk->icsk_delack_timer);
init_timer(&sk->sk_timer);

icsk->icsk_retransmit_timer.function = retransmit_handler;
icsk->icsk_delack_timer.function = delack_handler;
sk->sk_timer.function = keepalive_handler;

icsk->icsk_retransmit_timer.data =
icsk->icsk_delack_timer.data =
sk->sk_timer.data = (unsigned long)sk;

setup_timer(&icsk->icsk_retransmit_timer, retransmit_handler,
(unsigned long)sk);
setup_timer(&icsk->icsk_delack_timer, delack_handler,
(unsigned long)sk);
setup_timer(&sk->sk_timer, keepalive_handler, (unsigned long)sk);
icsk->icsk_pending = icsk->icsk_ack.pending = 0;
}

Expand Down
5 changes: 2 additions & 3 deletions net/ipv4/inet_fragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ void inet_frags_init(struct inet_frags *f)
f->nqueues = 0;
atomic_set(&f->mem, 0);

init_timer(&f->secret_timer);
f->secret_timer.function = inet_frag_secret_rebuild;
f->secret_timer.data = (unsigned long)f;
setup_timer(&f->secret_timer, inet_frag_secret_rebuild,
(unsigned long)f);
f->secret_timer.expires = jiffies + f->ctl->secret_interval;
add_timer(&f->secret_timer);
}
Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/ipmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1889,8 +1889,7 @@ void __init ip_mr_init(void)
sizeof(struct mfc_cache),
0, SLAB_HWCACHE_ALIGN|SLAB_PANIC,
NULL);
init_timer(&ipmr_expire_timer);
ipmr_expire_timer.function=ipmr_expire_process;
setup_timer(&ipmr_expire_timer, ipmr_expire_process, 0);
register_netdevice_notifier(&ip_mr_notifier);
#ifdef CONFIG_PROC_FS
proc_net_fops_create(&init_net, "ip_mr_vif", 0, &ipmr_vif_fops);
Expand Down
4 changes: 1 addition & 3 deletions net/ipv4/ipvs/ip_vs_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,7 @@ ip_vs_conn_new(int proto, __be32 caddr, __be16 cport, __be32 vaddr, __be16 vport
}

INIT_LIST_HEAD(&cp->c_list);
init_timer(&cp->timer);
cp->timer.data = (unsigned long)cp;
cp->timer.function = ip_vs_conn_expire;
setup_timer(&cp->timer, ip_vs_conn_expire, (unsigned long)cp);
cp->protocol = proto;
cp->caddr = caddr;
cp->cport = cport;
Expand Down
3 changes: 1 addition & 2 deletions net/ipv4/ipvs/ip_vs_est.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ int ip_vs_new_estimator(struct ip_vs_stats *stats)
write_lock_bh(&est_lock);
est->next = est_list;
if (est->next == NULL) {
init_timer(&est_timer);
setup_timer(&est_timer, estimation_timer, 0);
est_timer.expires = jiffies + 2*HZ;
est_timer.function = estimation_timer;
add_timer(&est_timer);
}
est_list = est;
Expand Down
5 changes: 2 additions & 3 deletions net/ipv4/ipvs/ip_vs_lblc.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,8 @@ static int ip_vs_lblc_init_svc(struct ip_vs_service *svc)
/*
* Hook periodic timer for garbage collection
*/
init_timer(&tbl->periodic_timer);
tbl->periodic_timer.data = (unsigned long)tbl;
tbl->periodic_timer.function = ip_vs_lblc_check_expire;
setup_timer(&tbl->periodic_timer, ip_vs_lblc_check_expire,
(unsigned long)tbl);
tbl->periodic_timer.expires = jiffies+CHECK_EXPIRE_INTERVAL;
add_timer(&tbl->periodic_timer);

Expand Down
5 changes: 2 additions & 3 deletions net/ipv4/ipvs/ip_vs_lblcr.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,8 @@ static int ip_vs_lblcr_init_svc(struct ip_vs_service *svc)
/*
* Hook periodic timer for garbage collection
*/
init_timer(&tbl->periodic_timer);
tbl->periodic_timer.data = (unsigned long)tbl;
tbl->periodic_timer.function = ip_vs_lblcr_check_expire;
setup_timer(&tbl->periodic_timer, ip_vs_lblcr_check_expire,
(unsigned long)tbl);
tbl->periodic_timer.expires = jiffies+CHECK_EXPIRE_INTERVAL;
add_timer(&tbl->periodic_timer);

Expand Down
Loading

0 comments on commit b24b8a2

Please sign in to comment.