From 51d76bdfb7423947dbb3e250c86d83f9edb0a15b Mon Sep 17 00:00:00 2001 From: Hangbin Liu Date: Wed, 20 Mar 2019 14:44:13 +0800 Subject: [PATCH] port: should check the new phc_index before switching In logic, when we want to switch phc, we should check if the new phc index is valid instead of checking the previous one. In reality, if we use linux team interface with activebackup mode. As teamd is a userspace tool, it sets the new slave as active port after receiving link change message. If we set current active port down and another slave up. There is a race that we receive the new slave's link up message while active port(ts_index) is still the old one. This means we may use a link down interface as ts_index and get phc_index with -1. If we update the p->phc_index to -1, there will be no possibility to change it back to other value as we swith phc only when p->phc_index >= 0. With this fix, we will not switch phc_index until receiving the real active port(p->iface->ts_info.phc_index >= 0) update message. Reported-by: Miroslav Lichvar Fixes: 536a71031d5c ("ptp4l: use ts label to get ts info") Signed-off-by: Hangbin Liu --- port.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/port.c b/port.c index 9264211..facebd2 100644 --- a/port.c +++ b/port.c @@ -2442,7 +2442,7 @@ void port_link_status(void *ctx, int linkup, int ts_index) sk_get_ts_info(p->iface->ts_label, &p->iface->ts_info); /* Only switch phc with HW time stamping mode */ - if (p->phc_index >= 0 && p->iface->ts_info.valid) { + if (p->iface->ts_info.valid && p->iface->ts_info.phc_index >= 0) { required_modes = clock_required_modes(p->clock); if ((p->iface->ts_info.so_timestamping & required_modes) != required_modes) { pr_err("interface '%s' does not support requested "