aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2009-06-29 14:24:43 -0400
committerDan Williams <dcbw@redhat.com>2009-06-29 14:24:43 -0400
commit853af00142256d2eeae7039a1b7e8dd64cf9105e (patch)
tree501a71d4dcb70f1579115b57c18894c2f0c9c4ae /src
parentc106368ce7c06e0ae5b64cc6146ad05c3b9fa819 (diff)
plugin-base: fix finding the physical device again
Don't mis-use udev's ID_BUS key.
Diffstat (limited to 'src')
-rw-r--r--src/mm-plugin-base.c53
-rw-r--r--src/mm-plugin-base.h4
2 files changed, 25 insertions, 32 deletions
diff --git a/src/mm-plugin-base.c b/src/mm-plugin-base.c
index 367f40ea..3b172dc6 100644
--- a/src/mm-plugin-base.c
+++ b/src/mm-plugin-base.c
@@ -680,48 +680,37 @@ get_driver_name (GUdevDevice *device)
static GUdevDevice *
real_find_physical_device (MMPluginBase *plugin, GUdevDevice *child)
{
- GUdevDevice *parent = NULL, *physdev = NULL;
+ GUdevDevice *iter, *old = NULL;
+ GUdevDevice *physdev = NULL;
const char *subsys, *type;
+ guint32 i = 0;
+ gboolean is_usb = FALSE, is_pci = FALSE;
g_return_val_if_fail (child != NULL, NULL);
- subsys = g_udev_device_get_subsystem (child);
- g_assert (subsys);
- if (strcmp (subsys, "usb") && strcmp (subsys, "pci")) {
- /* Try the parent */
- parent = g_udev_device_get_parent (child);
- if (!parent)
- goto out;
-
- subsys = g_udev_device_get_subsystem (parent);
- if (strcmp (subsys, "usb") && strcmp (subsys, "pci"))
- goto out;
- }
-
- if (!strcmp (subsys, "usb")) {
- GUdevDevice *iter, *old = NULL;
-
- /* Walk the parents to find the 'usb_device' for this device. */
- iter = g_object_ref (child);
- while (iter) {
- type = g_udev_device_get_devtype (iter);
- if (type && !strcmp (type, "usb_device")) {
+ iter = g_object_ref (child);
+ while (iter && i++ < 5) {
+ subsys = g_udev_device_get_subsystem (iter);
+ if (subsys) {
+ if (is_usb || !strcmp (subsys, "usb")) {
+ is_usb = TRUE;
+ type = g_udev_device_get_devtype (iter);
+ if (type && !strcmp (type, "usb_device")) {
+ physdev = iter;
+ break;
+ }
+ } else if (is_pci || !strcmp (subsys, "pci")) {
+ is_pci = TRUE;
physdev = iter;
break;
}
-
- old = iter;
- iter = g_udev_device_get_parent (old);
- g_object_unref (old);
}
- } else if (!strcmp (subsys, "pci"))
- physdev = g_udev_device_get_parent (child);
- // FIXME: pcmcia (like Sierra 850/860)
+ old = iter;
+ iter = g_udev_device_get_parent (old);
+ g_object_unref (old);
+ }
-out:
- if (parent)
- g_object_unref (parent);
return physdev;
}
diff --git a/src/mm-plugin-base.h b/src/mm-plugin-base.h
index e426956d..91d3ddba 100644
--- a/src/mm-plugin-base.h
+++ b/src/mm-plugin-base.h
@@ -102,6 +102,10 @@ struct _MMPluginBaseClass {
void (*cancel_task) (MMPluginBase *plugin,
MMPluginBaseSupportsTask *task);
+ /* Find a the physical device of a port, ie the USB or PCI or whatever
+ * "master" device that owns the port. The GUdevDevice object returned
+ * will be unref-ed by the caller.
+ */
GUdevDevice * (*find_physical_device) (MMPluginBase *plugin,
GUdevDevice *port);