Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 290191
b: refs/heads/master
c: a04ccd5
h: refs/heads/master
i:
  290189: a0a7121
  290187: b836f76
  290183: ab62eb6
  290175: d2438fc
v: v3
  • Loading branch information
Martin Hundebøll authored and Marek Lindner committed Feb 16, 2012
1 parent e0cee81 commit d0325cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c51f9c09fabc96f23e449b5e39b1fc4e2cabcd85
refs/heads/master: a04ccd5970ec11f0b320971051435d86d3233c92
11 changes: 11 additions & 0 deletions trunk/net/batman-adv/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,17 @@ static inline int compare_eth(const void *data1, const void *data2)
return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
}

/**
* has_timed_out - compares current time (jiffies) and timestamp + timeout
* @timestamp: base value to compare with (in jiffies)
* @timeout: added to base value before comparing (in milliseconds)
*
* Returns true if current time is after timestamp + timeout
*/
static inline bool has_timed_out(unsigned long timestamp, unsigned int timeout)
{
return time_is_before_jiffies(timestamp + msecs_to_jiffies(timeout));
}

#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)

Expand Down
32 changes: 12 additions & 20 deletions trunk/net/batman-adv/translation-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,6 @@ static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv,

}

static bool is_out_of_time(unsigned long starting_time, unsigned long timeout)
{
unsigned long deadline;
deadline = starting_time + msecs_to_jiffies(timeout);

return time_after(jiffies, deadline);
}

static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry)
{
if (atomic_dec_and_test(&tt_local_entry->common.refcount))
Expand Down Expand Up @@ -420,8 +412,8 @@ static void tt_local_purge(struct bat_priv *bat_priv)
if (tt_local_entry->common.flags & TT_CLIENT_PENDING)
continue;

if (!is_out_of_time(tt_local_entry->last_seen,
TT_LOCAL_TIMEOUT * 1000))
if (!has_timed_out(tt_local_entry->last_seen,
TT_LOCAL_TIMEOUT * 1000))
continue;

tt_local_set_pending(bat_priv, tt_local_entry,
Expand Down Expand Up @@ -758,8 +750,8 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv)
common);
if (!(tt_global_entry->common.flags & TT_CLIENT_ROAM))
continue;
if (!is_out_of_time(tt_global_entry->roam_at,
TT_CLIENT_ROAM_TIMEOUT * 1000))
if (!has_timed_out(tt_global_entry->roam_at,
TT_CLIENT_ROAM_TIMEOUT * 1000))
continue;

bat_dbg(DBG_TT, bat_priv, "Deleting global "
Expand Down Expand Up @@ -978,8 +970,8 @@ static void tt_req_purge(struct bat_priv *bat_priv)

spin_lock_bh(&bat_priv->tt_req_list_lock);
list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) {
if (is_out_of_time(node->issued_at,
TT_REQUEST_TIMEOUT * 1000)) {
if (has_timed_out(node->issued_at,
TT_REQUEST_TIMEOUT * 1000)) {
list_del(&node->list);
kfree(node);
}
Expand All @@ -997,8 +989,8 @@ static struct tt_req_node *new_tt_req_node(struct bat_priv *bat_priv,
spin_lock_bh(&bat_priv->tt_req_list_lock);
list_for_each_entry(tt_req_node_tmp, &bat_priv->tt_req_list, list) {
if (compare_eth(tt_req_node_tmp, orig_node) &&
!is_out_of_time(tt_req_node_tmp->issued_at,
TT_REQUEST_TIMEOUT * 1000))
!has_timed_out(tt_req_node_tmp->issued_at,
TT_REQUEST_TIMEOUT * 1000))
goto unlock;
}

Expand Down Expand Up @@ -1591,8 +1583,8 @@ static void tt_roam_purge(struct bat_priv *bat_priv)

spin_lock_bh(&bat_priv->tt_roam_list_lock);
list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) {
if (!is_out_of_time(node->first_time,
ROAMING_MAX_TIME * 1000))
if (!has_timed_out(node->first_time,
ROAMING_MAX_TIME * 1000))
continue;

list_del(&node->list);
Expand All @@ -1619,8 +1611,8 @@ static bool tt_check_roam_count(struct bat_priv *bat_priv,
if (!compare_eth(tt_roam_node->addr, client))
continue;

if (is_out_of_time(tt_roam_node->first_time,
ROAMING_MAX_TIME * 1000))
if (has_timed_out(tt_roam_node->first_time,
ROAMING_MAX_TIME * 1000))
continue;

if (!atomic_dec_not_zero(&tt_roam_node->counter))
Expand Down

0 comments on commit d0325cd

Please sign in to comment.