device: fix check on device state in carrier_changed()
authorBeniamino Galvani <bgalvani@redhat.com>
Tue, 19 Jan 2016 20:20:46 +0000 (21:20 +0100)
committerBeniamino Galvani <bgalvani@redhat.com>
Wed, 20 Jan 2016 08:53:10 +0000 (09:53 +0100)
The function can now be called on unrealized devices before the
initial unmanaged flags are set and for those devices
nm_device_get_managed() will return TRUE. Since we only accept
states > UNMANAGED, return early when the condition is not met.

Fixes the following failed assertion:

carrier_changed: assertion 'priv->state >= NM_DEVICE_STATE_UNAVAILABLE' failed

https://bugzilla.gnome.org/show_bug.cgi?id=760844

src/devices/nm-device.c

index 93782a4..6e9a156 100644 (file)
@@ -1272,7 +1272,7 @@ carrier_changed (NMDevice *self, gboolean carrier)
 {
        NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
 
-       if (!nm_device_get_managed (self))
+       if (priv->state <= NM_DEVICE_STATE_UNMANAGED)
                return;
 
        nm_device_recheck_available_connections (self);
@@ -1304,8 +1304,6 @@ carrier_changed (NMDevice *self, gboolean carrier)
        }
 
        if (carrier) {
-               g_warn_if_fail (priv->state >= NM_DEVICE_STATE_UNAVAILABLE);
-
                if (priv->state == NM_DEVICE_STATE_UNAVAILABLE) {
                        nm_device_queue_state (self, NM_DEVICE_STATE_DISCONNECTED,
                                               NM_DEVICE_STATE_REASON_CARRIER);
@@ -1324,8 +1322,6 @@ carrier_changed (NMDevice *self, gboolean carrier)
                        update_dynamic_ip_setup (self);
                }
        } else {
-               g_return_if_fail (priv->state >= NM_DEVICE_STATE_UNAVAILABLE);
-
                if (priv->state == NM_DEVICE_STATE_UNAVAILABLE) {
                        if (nm_device_queued_state_peek (self) >= NM_DEVICE_STATE_DISCONNECTED)
                                nm_device_queued_state_clear (self);