From db9645fcb3ca37d1598bffe9276692ac46906755 Mon Sep 17 00:00:00 2001 From: Rui Matos Date: Mon, 2 Mar 2015 17:38:41 +0100 Subject: [PATCH] monitor-manager-kms: Cope with non-existent connectors and encoders DRM objects like connectors and encoders might change at any time, in particular they might become invalid between drmModeGetResources() and getting the actual objects in which case they'll be NULL. Be defensive against that. Note that, if this happens, we should get another udev event soon which will cause us to update our state. https://bugzilla.gnome.org/show_bug.cgi?id=745476 --- src/backends/native/meta-monitor-manager-kms.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/backends/native/meta-monitor-manager-kms.c b/src/backends/native/meta-monitor-manager-kms.c index eeb5877b1..836df3b67 100644 --- a/src/backends/native/meta-monitor-manager-kms.c +++ b/src/backends/native/meta-monitor-manager-kms.c @@ -366,7 +366,7 @@ meta_monitor_manager_kms_read_current (MetaMonitorManager *manager) connector = drmModeGetConnector (manager_kms->fd, resources->connectors[i]); manager_kms->connectors[i] = connector; - if (connector->connection == DRM_MODE_CONNECTED) + if (connector && connector->connection == DRM_MODE_CONNECTED) { /* Collect all modes for this connector */ for (j = 0; j < (unsigned)connector->count_modes; j++) @@ -460,7 +460,7 @@ meta_monitor_manager_kms_read_current (MetaMonitorManager *manager) connector = manager_kms->connectors[i]; meta_output = &manager->outputs[n_actual_outputs]; - if (connector->connection == DRM_MODE_CONNECTED) + if (connector && connector->connection == DRM_MODE_CONNECTED) { meta_output->driver_private = output_kms = g_slice_new0 (MetaOutputKms); meta_output->driver_notify = (GDestroyNotify)meta_output_destroy_notify; @@ -509,6 +509,8 @@ meta_monitor_manager_kms_read_current (MetaMonitorManager *manager) for (j = 0; j < output_kms->n_encoders; j++) { output_kms->encoders[j] = drmModeGetEncoder (manager_kms->fd, connector->encoders[j]); + if (!output_kms->encoders[j]) + continue; /* We only list CRTCs as supported if they are supported by all encoders for this connectors. @@ -616,7 +618,8 @@ meta_monitor_manager_kms_read_current (MetaMonitorManager *manager) { for (k = 0; k < (unsigned)resources->count_encoders; k++) { - if (output_kms->encoders[j]->encoder_id == encoders[k]->encoder_id) + if (output_kms->encoders[j] && encoders[k] && + output_kms->encoders[j]->encoder_id == encoders[k]->encoder_id) { output_kms->encoder_mask |= (1 << k); break;