From ccd2ec7b343e1078c8b5d0cd3ee9d8cfd46ddd3f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Jan 2016 21:54:23 +0100 Subject: wifi: don't fail construction of NMDeviceWifi in constructor We cannot abort the construction of a GLib object instance like we did for NMDeviceWifi and NMDeviceOlpcMesh when nm_platform_wifi_get_capabilities() failed. Instead, check the capabilities first (in the factory method) and only create the object instance when the device can be handled. https://bugzilla.gnome.org/show_bug.cgi?id=760154 (cherry picked from commit 044de4cea2c82d289033e75f1e12c7d346dc5537) --- src/devices/wifi/nm-wifi-factory.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/devices/wifi/nm-wifi-factory.c') diff --git a/src/devices/wifi/nm-wifi-factory.c b/src/devices/wifi/nm-wifi-factory.c index c4b4042e70..3e31ddf412 100644 --- a/src/devices/wifi/nm-wifi-factory.c +++ b/src/devices/wifi/nm-wifi-factory.c @@ -29,6 +29,8 @@ #include "nm-device-olpc-mesh.h" #include "nm-settings-connection.h" #include "nm-platform.h" +#include "nm-macros-internal.h" +#include "nm-logging.h" #define NM_TYPE_WIFI_FACTORY (nm_wifi_factory_get_type ()) #define NM_WIFI_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_WIFI_FACTORY, NMWifiFactory)) @@ -61,11 +63,22 @@ nm_device_factory_create (GError **error) static NMDevice * new_link (NMDeviceFactory *factory, NMPlatformLink *plink, gboolean *out_ignore, GError **error) { + NMDeviceWifiCapabilities capabilities; + + g_return_val_if_fail (plink != NULL, NULL); + g_return_val_if_fail (NM_IN_SET (plink->type, NM_LINK_TYPE_WIFI, NM_LINK_TYPE_OLPC_MESH), NULL); + + if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET, + plink->ifindex, + &capabilities)) { + nm_log_warn (LOGD_HW | LOGD_WIFI, "(%s) failed to initialize Wi-Fi driver for ifindex %d", plink->name, plink->ifindex); + return NULL; + } + if (plink->type == NM_LINK_TYPE_WIFI) - return nm_device_wifi_new (plink); - else if (plink->type == NM_LINK_TYPE_OLPC_MESH) + return nm_device_wifi_new (plink, capabilities); + else return nm_device_olpc_mesh_new (plink); - g_assert_not_reached (); } NM_DEVICE_FACTORY_DECLARE_TYPES ( -- cgit v1.2.3