diff options
author | Thomas Haller <thaller@redhat.com> | 2016-07-05 12:47:34 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-07-05 23:08:22 +0200 |
commit | 76b45f90df3e4b3e559ebec8037eac5fd922a739 (patch) | |
tree | 5bbd7ab8a64399c5a0ea3867b205e9991ce0d6d0 | |
parent | f9852821e39625787c9b97edd306839b326aa344 (diff) | |
download | NetworkManager-76b45f90df3e4b3e559ebec8037eac5fd922a739.tar.gz |
ethernet: minor cleanups in NMDeviceEthernet
-rw-r--r-- | src/devices/nm-device-ethernet.c | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 5f7c9f0da6..302ceef0c5 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -147,21 +147,21 @@ static void _update_s390_subchannels (NMDeviceEthernet *self) { NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self); - GUdevDevice *dev; - GUdevDevice *parent = NULL; + gs_unref_object GUdevDevice *dev = NULL; + gs_unref_object GUdevDevice *parent = NULL; const char *parent_path, *item, *driver; int ifindex; GDir *dir; GError *error = NULL; - ifindex = nm_device_get_ifindex (NM_DEVICE (self)); - dev = (GUdevDevice *) nm_platform_link_get_udev_device (NM_PLATFORM_GET, ifindex); + ifindex = nm_device_get_ifindex ((NMDevice *) self); + dev = (GUdevDevice *) nm_g_object_ref (nm_platform_link_get_udev_device (NM_PLATFORM_GET, ifindex)); if (!dev) { - _LOGW (LOGD_DEVICE | LOGD_HW, "failed to find device %d '%s' with udev", - ifindex, nm_device_get_iface (NM_DEVICE (self)) ?: "(null)"); - goto out; + _LOGW (LOGD_DEVICE | LOGD_HW, "failed to find device %s (%d) with udev", + nm_strquote_a (20, nm_device_get_iface ((NMDevice *) self)), + ifindex); + return; } - g_object_ref (dev); /* Try for the "ccwgroup" parent */ parent = g_udev_device_get_parent_with_subsystem (dev, "ccwgroup", NULL); @@ -169,7 +169,7 @@ _update_s390_subchannels (NMDeviceEthernet *self) /* FIXME: whatever 'lcs' devices' subsystem is here... */ if (!parent) { /* Not an s390 device */ - goto out; + return; } } @@ -179,7 +179,7 @@ _update_s390_subchannels (NMDeviceEthernet *self) _LOGW (LOGD_DEVICE | LOGD_HW, "failed to open directory '%s': %s", parent_path, error->message); g_clear_error (&error); - goto out; + return; } while ((item = g_dir_read_name (dir))) { @@ -235,15 +235,9 @@ _update_s390_subchannels (NMDeviceEthernet *self) priv->subchannels_dbus[2] = g_strdup (priv->subchan3); priv->subchannels_dbus[3] = NULL; - driver = nm_device_get_driver (NM_DEVICE (self)); + driver = nm_device_get_driver ((NMDevice *) self); _LOGI (LOGD_DEVICE | LOGD_HW, "found s390 '%s' subchannels [%s]", driver ? driver : "(unknown driver)", priv->subchannels); - -out: - if (parent) - g_object_unref (parent); - if (dev) - g_object_unref (dev); } static GObject* @@ -256,20 +250,16 @@ constructor (GType type, object = G_OBJECT_CLASS (nm_device_ethernet_parent_class)->constructor (type, n_construct_params, construct_params); - if (object) { -#ifndef G_DISABLE_ASSERT - int ifindex = nm_device_get_ifindex (NM_DEVICE (object)); - NMLinkType link_type = nm_platform_link_get_type (NM_PLATFORM_GET, ifindex); - - g_assert ( link_type == NM_LINK_TYPE_ETHERNET - || link_type == NM_LINK_TYPE_VETH - || link_type == NM_LINK_TYPE_NONE); -#endif - - /* s390 stuff */ - _update_s390_subchannels (NM_DEVICE_ETHERNET (object)); - } + if (!object) + return NULL; + + nm_assert (NM_IN_SET (nm_platform_link_get_type (NM_PLATFORM_GET, + nm_device_get_ifindex ((NMDevice *) object)), + NM_LINK_TYPE_NONE, + NM_LINK_TYPE_ETHERNET, + NM_LINK_TYPE_VETH)); + _update_s390_subchannels ((NMDeviceEthernet *) object); return object; } |