From e92b743ce926a49d84847d7c951cbc0ee343d19c Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 20 May 2016 10:09:39 +0200 Subject: [PATCH] device: don't use g_warning for differing hw-addr-len after reading permanent address Accessing the platform cache might anytime yield unexpected results. E.g. the link could be gone, or the ifindex could even be replaced by a different interface (yes, that can happen when moving links between network namespaces). It's not clear how to handle such a case at runtime. It seems wrong to me to just error out. Still, such case might happen under normal conditions, so it's wrong to just warn and proceed. --- src/devices/nm-device.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 22af8b17e..25bf01d4a 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -11391,15 +11391,20 @@ nm_device_update_initial_hw_address (NMDevice *self) if (priv->ifindex > 0) { guint8 buf[NM_UTILS_HWADDR_LEN_MAX]; size_t len = 0; + gboolean success_read; - if (nm_platform_link_get_permanent_address (NM_PLATFORM_GET, priv->ifindex, buf, &len)) { - g_warn_if_fail (len == priv->hw_addr_len); + success_read = nm_platform_link_get_permanent_address (NM_PLATFORM_GET, priv->ifindex, buf, &len); + + if (success_read && len == priv->hw_addr_len) { priv->perm_hw_addr = nm_utils_hwaddr_ntoa (buf, priv->hw_addr_len); _LOGD (LOGD_DEVICE | LOGD_HW, "read permanent MAC address %s", priv->perm_hw_addr); } else { /* Fall back to current address */ - _LOGD (LOGD_HW | LOGD_ETHER, "unable to read permanent MAC address"); + _LOGD (LOGD_HW | LOGD_ETHER, "%s", + success_read + ? "unable to read permanent MAC address" + : "read HW addr length of permanent MAC address differs"); priv->perm_hw_addr = g_strdup (priv->hw_addr); } }