* [PATCH] net: rose: Use mod_timer
@ 2015-06-06 4:22 Vaishali Thakkar
2015-06-06 8:02 ` Ralf Baechle DL5RB
0 siblings, 1 reply; 2+ messages in thread
From: Vaishali Thakkar @ 2015-06-06 4:22 UTC (permalink / raw)
To: Ralf Baechle
Cc: David S. Miller, linux-hams, netdev, linux-kernel, Julia Lawall
Use mod_timer instead of del_timer followed by add_timer to update
the expire field of the active timer.
The semantic patch that performs this transformation is as follows:
@change@
expression e1, e2, e3, e4;
@@
- del_timer(&e1);
... when != e1 = e3
- e1.expires = e2;
... when != e1 = e4
- add_timer (&e1);
+ mod_timer (&e1, e2);
Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
---
net/rose/rose_link.c | 16 ++++------------
net/rose/rose_loopback.c | 6 +-----
net/rose/rose_timer.c | 30 +++++-------------------------
3 files changed, 10 insertions(+), 42 deletions(-)
diff --git a/net/rose/rose_link.c b/net/rose/rose_link.c
index e873d7d..a2409bb 100644
--- a/net/rose/rose_link.c
+++ b/net/rose/rose_link.c
@@ -36,26 +36,18 @@ static void rose_transmit_restart_request(struct rose_neigh *neigh);
void rose_start_ftimer(struct rose_neigh *neigh)
{
- del_timer(&neigh->ftimer);
-
neigh->ftimer.data = (unsigned long)neigh;
neigh->ftimer.function = &rose_ftimer_expiry;
- neigh->ftimer.expires =
- jiffies + msecs_to_jiffies(sysctl_rose_link_fail_timeout);
-
- add_timer(&neigh->ftimer);
+ mod_timer(&neigh->ftimer,
+ jiffies + msecs_to_jiffies(sysctl_rose_link_fail_timeout));
}
static void rose_start_t0timer(struct rose_neigh *neigh)
{
- del_timer(&neigh->t0timer);
-
neigh->t0timer.data = (unsigned long)neigh;
neigh->t0timer.function = &rose_t0timer_expiry;
- neigh->t0timer.expires =
- jiffies + msecs_to_jiffies(sysctl_rose_restart_request_timeout);
-
- add_timer(&neigh->t0timer);
+ mod_timer(&neigh->t0timer,
+ jiffies + msecs_to_jiffies(sysctl_rose_restart_request_timeout));
}
void rose_stop_ftimer(struct rose_neigh *neigh)
diff --git a/net/rose/rose_loopback.c b/net/rose/rose_loopback.c
index 3444562..ed81864 100644
--- a/net/rose/rose_loopback.c
+++ b/net/rose/rose_loopback.c
@@ -54,13 +54,9 @@ static void rose_loopback_timer(unsigned long);
static void rose_set_loopback_timer(void)
{
- del_timer(&loopback_timer);
-
loopback_timer.data = 0;
loopback_timer.function = &rose_loopback_timer;
- loopback_timer.expires = jiffies + 10;
-
- add_timer(&loopback_timer);
+ mod_timer(&loopback_timer, jiffies + 10);
}
static void rose_loopback_timer(unsigned long param)
diff --git a/net/rose/rose_timer.c b/net/rose/rose_timer.c
index bc5469d..7495730 100644
--- a/net/rose/rose_timer.c
+++ b/net/rose/rose_timer.c
@@ -34,65 +34,45 @@ static void rose_idletimer_expiry(unsigned long);
void rose_start_heartbeat(struct sock *sk)
{
- del_timer(&sk->sk_timer);
-
sk->sk_timer.data = (unsigned long)sk;
sk->sk_timer.function = &rose_heartbeat_expiry;
- sk->sk_timer.expires = jiffies + 5 * HZ;
-
- add_timer(&sk->sk_timer);
+ mod_timer(&sk->sk_timer, jiffies + 5 * HZ);
}
void rose_start_t1timer(struct sock *sk)
{
struct rose_sock *rose = rose_sk(sk);
- del_timer(&rose->timer);
-
rose->timer.data = (unsigned long)sk;
rose->timer.function = &rose_timer_expiry;
- rose->timer.expires = jiffies + rose->t1;
-
- add_timer(&rose->timer);
+ mod_timer(&rose->timer, jiffies + rose->t1);
}
void rose_start_t2timer(struct sock *sk)
{
struct rose_sock *rose = rose_sk(sk);
- del_timer(&rose->timer);
-
rose->timer.data = (unsigned long)sk;
rose->timer.function = &rose_timer_expiry;
- rose->timer.expires = jiffies + rose->t2;
-
- add_timer(&rose->timer);
+ mod_timer(&rose->timer, jiffies + rose->t2);
}
void rose_start_t3timer(struct sock *sk)
{
struct rose_sock *rose = rose_sk(sk);
- del_timer(&rose->timer);
-
rose->timer.data = (unsigned long)sk;
rose->timer.function = &rose_timer_expiry;
- rose->timer.expires = jiffies + rose->t3;
-
- add_timer(&rose->timer);
+ mod_timer(&rose->timer, jiffies + rose->t3);
}
void rose_start_hbtimer(struct sock *sk)
{
struct rose_sock *rose = rose_sk(sk);
- del_timer(&rose->timer);
-
rose->timer.data = (unsigned long)sk;
rose->timer.function = &rose_timer_expiry;
- rose->timer.expires = jiffies + rose->hb;
-
- add_timer(&rose->timer);
+ mod_timer(&rose->timer, jiffies + rose->hb);
}
void rose_start_idletimer(struct sock *sk)
--
1.9.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net: rose: Use mod_timer
2015-06-06 4:22 [PATCH] net: rose: Use mod_timer Vaishali Thakkar
@ 2015-06-06 8:02 ` Ralf Baechle DL5RB
0 siblings, 0 replies; 2+ messages in thread
From: Ralf Baechle DL5RB @ 2015-06-06 8:02 UTC (permalink / raw)
To: Vaishali Thakkar
Cc: David S. Miller, linux-hams, netdev, linux-kernel, Julia Lawall
Hi Vaishali,
On Sat, Jun 06, 2015 at 09:52:34AM +0530, Vaishali Thakkar wrote:
> Use mod_timer instead of del_timer followed by add_timer to update
> the expire field of the active timer.
>
> The semantic patch that performs this transformation is as follows:
>
> @change@
> expression e1, e2, e3, e4;
> @@
>
> - del_timer(&e1);
> ... when != e1 = e3
> - e1.expires = e2;
> ... when != e1 = e4
> - add_timer (&e1);
> + mod_timer (&e1, e2);
This isn't quite right. All the instances of this pattern in the ROSE
stack also modify the timer's data and function fields which if the timer
is still running and expiring while being fiddled with, might result in
a race condition, that is the old function but new data field being used
in combination or something like that.
For some of the timers (maybe all?) it should be possible to proof that
always the same values for data and function are being used. These
initializations could then be used elsewhere and the code could then
indeed be switched to mod_timer.
Ralf
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-06-06 8:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-06 4:22 [PATCH] net: rose: Use mod_timer Vaishali Thakkar
2015-06-06 8:02 ` Ralf Baechle DL5RB
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).