Skip to content

Commit

Permalink
net: gptp: Do not handle multiple pdelay requests at once
Browse files Browse the repository at this point in the history
The problem with the previous approach was that the response timestamp
callback which calls net_pkt_unref could be skipped if the callback was
already registered for another packet. The net_pkt_ref function was
always called which led to memory leaks.

This commit simply disallows handling multiple pdelay requests at once.
If the timestamp callback is already registered, the received request
will not be handled.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
  • Loading branch information
tgorochowik authored and jukkar committed Jul 2, 2018
1 parent b422d38 commit 7e545c9
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions subsys/net/l2/ethernet/gptp/gptp_messages.c
Expand Up @@ -723,27 +723,30 @@ void gptp_handle_pdelay_req(int port, struct net_pkt *pkt)

GPTP_STATS_INC(port, rx_pdelay_req_count);

if (ts_cb_registered) {
NET_WARN("Multiple pdelay requests");
return;
}

/* Prepare response and send */
reply = gptp_prepare_pdelay_resp(port, pkt);
if (reply) {
if (!ts_cb_registered) {
net_if_register_timestamp_cb(
&pdelay_response_timestamp_cb,
net_pkt_iface(pkt),
gptp_pdelay_response_timestamp_callback);

ts_cb_registered = true;
}
if (!reply) {
return;
}

/* TS thread will send this back to us so increment ref count
* so that the packet is not removed when sending it.
* This will be unref'ed by timestamp callback in
* gptp_pdelay_response_timestamp_callback()
*/
net_pkt_ref(reply);
net_if_register_timestamp_cb(&pdelay_response_timestamp_cb,
net_pkt_iface(pkt),
gptp_pdelay_response_timestamp_callback);

gptp_send_pdelay_resp(port, reply, net_pkt_timestamp(pkt));
}
ts_cb_registered = true;

/* TS thread will send this back to us so increment ref count so that
* the packet is not removed when sending it. This will be unref'ed by
* timestamp callback in gptp_pdelay_response_timestamp_callback()
*/
net_pkt_ref(reply);

gptp_send_pdelay_resp(port, reply, net_pkt_timestamp(pkt));
}

int gptp_handle_pdelay_resp(int port, struct net_pkt *pkt)
Expand Down

0 comments on commit 7e545c9

Please sign in to comment.