From 77a3767d1e7f99a4f59d292eeab9363687697606 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 2 May 2015 07:59:59 +0200 Subject: [PATCH] platform: move code udev_get_driver() to nmp_utils_udev_get_driver() --- src/platform/nm-linux-platform.c | 44 ++------------------------------ src/platform/nm-platform-utils.c | 41 +++++++++++++++++++++++++++++ src/platform/nm-platform-utils.h | 5 ++++ 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index e55670c61..373c59125 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -58,6 +58,7 @@ #include "nm-core-internal.h" #include "NetworkManagerUtils.h" #include "nm-linux-platform.h" +#include "nm-platform-utils.h" #include "NetworkManagerUtils.h" #include "nm-utils.h" #include "nm-logging.h" @@ -479,47 +480,6 @@ ethtool_get_permanent_address (const char *ifname, return TRUE; } -/****************************************************************** - * udev - ******************************************************************/ - -static const char * -udev_get_driver (GUdevDevice *device, int ifindex) -{ - GUdevDevice *parent = NULL, *grandparent = NULL; - const char *driver, *subsys; - - driver = g_udev_device_get_driver (device); - if (driver) - goto out; - - /* Try the parent */ - parent = g_udev_device_get_parent (device); - if (parent) { - driver = g_udev_device_get_driver (parent); - if (!driver) { - /* Try the grandparent if it's an ibmebus device or if the - * subsys is NULL which usually indicates some sort of - * platform device like a 'gadget' net interface. - */ - subsys = g_udev_device_get_subsystem (parent); - if ( (g_strcmp0 (subsys, "ibmebus") == 0) - || (subsys == NULL)) { - grandparent = g_udev_device_get_parent (parent); - if (grandparent) - driver = g_udev_device_get_driver (grandparent); - } - } - } - g_clear_object (&parent); - g_clear_object (&grandparent); - -out: - /* Intern the string so we don't have to worry about memory - * management in NMPlatformLink. */ - return g_intern_string (driver); -} - /****************************************************************** * NMPlatform types and functions ******************************************************************/ @@ -1102,7 +1062,7 @@ init_link (NMPlatform *platform, NMPlatformLink *info, struct rtnl_link *rtnllin udev_device = g_hash_table_lookup (priv->udev_devices, GINT_TO_POINTER (info->ifindex)); if (udev_device) { - info->driver = udev_get_driver (udev_device, info->ifindex); + info->driver = nmp_utils_udev_get_driver (udev_device); info->udi = g_udev_device_get_sysfs_path (udev_device); info->initialized = TRUE; } diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index 34d4b0a69..62127142c 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -20,4 +20,45 @@ #include "nm-platform-utils.h" +/****************************************************************** + * udev + ******************************************************************/ + +const char * +nmp_utils_udev_get_driver (GUdevDevice *device) +{ + GUdevDevice *parent = NULL, *grandparent = NULL; + const char *driver, *subsys; + + driver = g_udev_device_get_driver (device); + if (driver) + goto out; + + /* Try the parent */ + parent = g_udev_device_get_parent (device); + if (parent) { + driver = g_udev_device_get_driver (parent); + if (!driver) { + /* Try the grandparent if it's an ibmebus device or if the + * subsys is NULL which usually indicates some sort of + * platform device like a 'gadget' net interface. + */ + subsys = g_udev_device_get_subsystem (parent); + if ( (g_strcmp0 (subsys, "ibmebus") == 0) + || (subsys == NULL)) { + grandparent = g_udev_device_get_parent (parent); + if (grandparent) + driver = g_udev_device_get_driver (grandparent); + } + } + } + g_clear_object (&parent); + g_clear_object (&grandparent); + +out: + /* Intern the string so we don't have to worry about memory + * management in NMPlatformLink. */ + return g_intern_string (driver); +} + diff --git a/src/platform/nm-platform-utils.h b/src/platform/nm-platform-utils.h index a6da1a893..76f285d7d 100644 --- a/src/platform/nm-platform-utils.h +++ b/src/platform/nm-platform-utils.h @@ -23,7 +23,12 @@ #include "config.h" +#include + #include "nm-platform.h" +const char *nmp_utils_udev_get_driver (GUdevDevice *device); + + #endif /* __NM_PLATFORM_UTILS_H__ */