Skip to content

Commit a5f7e33

Browse files
committed
net: lldp: Fix timeout triggering if multiple workers
The code was not working properly if there was multiple timers that were triggered in different times. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent d36aae1 commit a5f7e33

File tree

1 file changed

+12
-5
lines changed
  • subsys/net/l2/ethernet/lldp

1 file changed

+12
-5
lines changed

subsys/net/l2/ethernet/lldp/lldp.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#endif
1515

1616
#include <errno.h>
17+
#include <stdlib.h>
18+
1719
#include <net/net_core.h>
1820
#include <net/ethernet.h>
1921
#include <net/net_mgmt.h>
@@ -66,9 +68,7 @@ static void lldp_submit_work(u32_t timeout)
6668
static bool lldp_check_timeout(s64_t start, u32_t time, s64_t timeout)
6769
{
6870
start += time;
69-
if (start < 0) {
70-
start = -start;
71-
}
71+
start = abs(start);
7272

7373
if (start > timeout) {
7474
return false;
@@ -144,16 +144,23 @@ static int lldp_send(struct ethernet_lldp *lldp)
144144
}
145145

146146
out:
147+
lldp->tx_timer_start = k_uptime_get();
148+
147149
return ret;
148150
}
149151

150152
static u32_t lldp_manage_timeouts(struct ethernet_lldp *lldp, s64_t timeout)
151153
{
154+
s32_t next_timeout;
155+
152156
if (lldp_timedout(lldp, timeout)) {
153157
lldp_send(lldp);
154158
}
155159

156-
return lldp->tx_timer_timeout;
160+
next_timeout = timeout - (lldp->tx_timer_start +
161+
lldp->tx_timer_timeout);
162+
163+
return abs(next_timeout);
157164
}
158165

159166
static void lldp_tx_timeout(struct k_work *work)
@@ -173,7 +180,7 @@ static void lldp_tx_timeout(struct k_work *work)
173180
}
174181
}
175182

176-
if (timeout_update != UINT32_MAX) {
183+
if (timeout_update < (UINT32_MAX - 1)) {
177184
NET_DBG("Waiting for %u ms", timeout_update);
178185

179186
k_delayed_work_submit(&lldp_tx_timer, timeout_update);

0 commit comments

Comments
 (0)