summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-01-06 21:54:23 +0100
committerThomas Haller <thaller@redhat.com>2016-01-06 22:34:29 +0100
commitccd2ec7b343e1078c8b5d0cd3ee9d8cfd46ddd3f (patch)
tree75017df3e53268c534647e751e2d119740d0b0d3 /src
parent75131ed65411239851ea1dfc3a2fcc40103dbe6d (diff)
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)
Diffstat (limited to 'src')
-rw-r--r--src/devices/wifi/nm-device-olpc-mesh.c10
-rw-r--r--src/devices/wifi/nm-device-wifi.c24
-rw-r--r--src/devices/wifi/nm-device-wifi.h2
-rw-r--r--src/devices/wifi/nm-wifi-factory.c19
4 files changed, 30 insertions, 25 deletions
diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c
index 8dffeb4b39..021b385de9 100644
--- a/src/devices/wifi/nm-device-olpc-mesh.c
+++ b/src/devices/wifi/nm-device-olpc-mesh.c
@@ -447,22 +447,14 @@ constructor (GType type,
GObjectClass *klass;
NMDeviceOlpcMesh *self;
NMDeviceOlpcMeshPrivate *priv;
- NMDeviceWifiCapabilities caps;
klass = G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class);
object = klass->constructor (type, n_construct_params, construct_params);
- if (!object)
- return NULL;
+ g_return_val_if_fail (object, NULL);
self = NM_DEVICE_OLPC_MESH (object);
priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
- if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), &caps)) {
- _LOGW (LOGD_HW | LOGD_OLPC, "failed to initialize WiFi driver");
- g_object_unref (object);
- return NULL;
- }
-
priv->manager = g_object_ref (nm_manager_get ());
g_signal_connect (priv->manager, "device-added", G_CALLBACK (device_added_cb), self);
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index 1bf64bcc20..dec4e4f2ce 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -201,20 +201,11 @@ constructor (GType type,
klass = G_OBJECT_CLASS (nm_device_wifi_parent_class);
object = klass->constructor (type, n_construct_params, construct_params);
- if (!object)
- return NULL;
+ g_return_val_if_fail (object, NULL);
self = NM_DEVICE_WIFI (object);
priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
- if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET,
- nm_device_get_ifindex (NM_DEVICE (self)),
- &priv->capabilities)) {
- _LOGW (LOGD_HW | LOGD_WIFI, "failed to initialize WiFi driver");
- g_object_unref (object);
- return NULL;
- }
-
if (priv->capabilities & NM_WIFI_DEVICE_CAP_AP)
_LOGI (LOGD_HW | LOGD_WIFI, "driver supports Access Point (AP) mode");
@@ -3196,7 +3187,7 @@ set_enabled (NMDevice *device, gboolean enabled)
/********************************************************************/
NMDevice *
-nm_device_wifi_new (NMPlatformLink *platform_device)
+nm_device_wifi_new (NMPlatformLink *platform_device, NMDeviceWifiCapabilities capabilities)
{
g_return_val_if_fail (platform_device != NULL, NULL);
@@ -3205,6 +3196,7 @@ nm_device_wifi_new (NMPlatformLink *platform_device)
NM_DEVICE_TYPE_DESC, "802.11 WiFi",
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_WIFI,
NM_DEVICE_RFKILL_TYPE, RFKILL_TYPE_WLAN,
+ NM_DEVICE_WIFI_CAPABILITIES, (guint) capabilities,
NULL);
}
@@ -3296,7 +3288,14 @@ static void
set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
+ NMDeviceWifi *device = NM_DEVICE_WIFI (object);
+ NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
+
switch (prop_id) {
+ case PROP_CAPABILITIES:
+ /* construct-only */
+ priv->capabilities = g_value_get_uint (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -3381,7 +3380,8 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
(object_class, PROP_CAPABILITIES,
g_param_spec_uint (NM_DEVICE_WIFI_CAPABILITIES, "", "",
0, G_MAXUINT32, NM_WIFI_DEVICE_CAP_NONE,
- G_PARAM_READABLE |
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property
diff --git a/src/devices/wifi/nm-device-wifi.h b/src/devices/wifi/nm-device-wifi.h
index bcba91da2f..b141140d24 100644
--- a/src/devices/wifi/nm-device-wifi.h
+++ b/src/devices/wifi/nm-device-wifi.h
@@ -75,7 +75,7 @@ struct _NMDeviceWifiClass
GType nm_device_wifi_get_type (void);
-NMDevice *nm_device_wifi_new (NMPlatformLink *platform_device);
+NMDevice *nm_device_wifi_new (NMPlatformLink *platform_device, NMDeviceWifiCapabilities capabilities);
G_END_DECLS
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 (