libteam: don't crash when trying to print unregistered device name

team_port_str() will crash when trying to print port name that was
just unregistered, if dellink event is handled before port removal

This is regression from Commit 046fb6ba0aec ("libteam: resynchronize
ifinfo after lost RTNLGRP_LINK notifications"), which made it free
all removed interfaces after ifinfo handlers are called.

Put the ifinfo_destroy_removed() back to dellink/newlink handlers as
it was before that commit. Clean up the ifinfo list after change handlers
only if it refreshed the entire ifinfo list after lost events.

There's still a rare possibility that dellink event is missed due to
full socket receive buffer, which would cause ifinfo refresh and clearing
removed interfaces. For this, add NULL check to team_port_str() so it
doesn't try to print port device name in this situation.

Signed-off-by: Antti Tiainen <>
Signed-off-by: Jiri Pirko <>
4 files changed