[PATCH v4] kernel-device: use device sysfs if physdev sysfs isn't available
Ben Chan
benchan at chromium.org
Fri Mar 3 02:57:14 UTC 2017
find_device_by_physdev_uid() expects a non-NULL UID of the physical
device. However, mm_kernel_device_get_physdev_uid() could potentially
return NULL on MMKernelDeviceUdev if find_physical_gudevdevice() in
mm-kernel-device-udev.c fails to find the physical device. When a NULL
physical device UID is passed to find_device_by_physdev_uid() and used
in g_hash_table_lookup(), it leads to a crash in g_str_hash(), which is
a bit obscure.
This patch updates kernel_device_get_physdev_uid() in
mm-kernel-device-udev.c to fall back to use the device sysfs if the
physical device sysfs isn't available, which is similar to how
kernel_device_get_physdev_uid() mm-kernel-device-generic.c is
implemented.
---
src/kerneldevice/mm-kernel-device-udev.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/src/kerneldevice/mm-kernel-device-udev.c b/src/kerneldevice/mm-kernel-device-udev.c
index ab75aa34..2b2f19cb 100644
--- a/src/kerneldevice/mm-kernel-device-udev.c
+++ b/src/kerneldevice/mm-kernel-device-udev.c
@@ -347,20 +347,25 @@ kernel_device_get_physdev_uid (MMKernelDevice *_self)
self = MM_KERNEL_DEVICE_UDEV (_self);
/* Prefer the one coming in the properties, if any */
- if (self->priv->properties)
- uid = mm_kernel_event_properties_get_uid (MM_KERNEL_DEVICE_UDEV (self)->priv->properties);
-
- if (!uid) {
- ensure_physdev (self);
- if (!self->priv->physdev)
- return NULL;
+ if (self->priv->properties) {
+ if ((uid = mm_kernel_event_properties_get_uid (self->priv->properties)) != NULL)
+ return uid;
+ }
- uid = g_udev_device_get_property (self->priv->physdev, "ID_MM_PHYSDEV_UID");
- if (!uid)
- uid = g_udev_device_get_sysfs_path (self->priv->physdev);
+ ensure_physdev (self);
+ if (self->priv->physdev) {
+ /* Try to load from properties set on the physical device */
+ if ((uid = g_udev_device_get_property (self->priv->physdev, "ID_MM_PHYSDEV_UID")) != NULL)
+ return uid;
+
+ /* Use physical device sysfs path, if any */
+ if ((uid = g_udev_device_get_sysfs_path (self->priv->physdev)) != NULL)
+ return uid;
}
- return uid;
+ /* If there is no physical device sysfs path, use the device sysfs itself */
+ g_assert (self->priv->device);
+ return g_udev_device_get_sysfs_path (self->priv->device);
}
static guint16
--
2.12.0.rc1.440.g5b76565f74-goog
More information about the ModemManager-devel
mailing list