From ce6b667a6850fa42ae1d09e50b863fdfbb4a9e26 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 19 Mar 2012 16:09:46 -0500 Subject: [PATCH] wifi: make sure we're connected to netlink before using it This should fix the warning "failed to allocate link cache" when a new device is added. It doesn't affect WiFi operation, and the code would fall back to non-nl80211 mechanisms of detecting whether a device was wifi or not, so it corrects this check and quiets the error message. --- src/wifi/wifi-utils-nl80211.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/wifi/wifi-utils-nl80211.c b/src/wifi/wifi-utils-nl80211.c index af839e0987..4a4e661e6a 100644 --- a/src/wifi/wifi-utils-nl80211.c +++ b/src/wifi/wifi-utils-nl80211.c @@ -754,13 +754,14 @@ error: static int iface_to_index (struct nl_sock *nl_sock, const char *iface) { - struct nl_cache *link_cache; + struct nl_cache *link_cache = NULL; int err, ifindex; /* name to index */ err = rtnl_link_alloc_cache (nl_sock, &link_cache); if (err < 0) { - nm_log_warn (LOGD_HW, "failed to allocate link cache"); + nm_log_warn (LOGD_HW, "failed to allocate link cache: (%d) %s", + err, nl_geterror (err)); return -1; } nl_cache_mngt_provide (link_cache); @@ -787,11 +788,11 @@ wifi_nl80211_is_wifi (const char *iface) if (nl_sock == NULL) return FALSE; + if (genl_connect (nl_sock)) + goto error; + ifindex = iface_to_index (nl_sock, iface); if (ifindex < 0) - return FALSE; - - if (genl_connect (nl_sock)) goto error; id = genl_ctrl_resolve (nl_sock, "nl80211");