aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Chan <benchan@chromium.org>2017-03-02 18:57:14 -0800
committerAleksander Morgado <aleksander@aleksander.es>2017-03-03 07:26:59 +0100
commitf0cda2093078d630ca164b3872f742609e091a20 (patch)
treec4075f0b6982c51803248dc0ba5b38571f61f177 /src
parent8c3312918adf8ba49bb242cd21b306d3a7ff3a09 (diff)
kernel-device: use device sysfs if physdev sysfs isn't available
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.
Diffstat (limited to 'src')
-rw-r--r--src/kerneldevice/mm-kernel-device-udev.c27
1 files 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