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 <[email protected]>
Fixes: 536a71031d5c ("ptp4l: use ts label to get ts info")
Signed-off-by: Hangbin Liu <[email protected]>
---
 port.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/port.c b/port.c
index ad9554f..49c6f76 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 "
-- 
2.19.2



_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to