From 8546ca31ff91d5adcec6d5d028f8fcdeee239985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 18 Nov 2021 17:15:57 +0100 Subject: [PATCH] kms/connector: Fix updating the state when drmConnector is NULL When a docking station is disconnected, a few previously existing DRM connectors may now be gone. When this happens, getting them via the libdrm API results in NULL pointers returning, and we need to handle this gracefully by making sure the connector state is properly updated. Part-of: --- src/backends/native/meta-kms-connector.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/backends/native/meta-kms-connector.c b/src/backends/native/meta-kms-connector.c index 5121dc94d..4f1b38da5 100644 --- a/src/backends/native/meta-kms-connector.c +++ b/src/backends/native/meta-kms-connector.c @@ -138,7 +138,9 @@ sync_fd_held (MetaKmsConnector *connector, { gboolean should_hold_fd; - should_hold_fd = connector->current_state->current_crtc_id != 0; + should_hold_fd = + connector->current_state && + connector->current_state->current_crtc_id != 0; if (connector->fd_held == should_hold_fd) return; @@ -569,6 +571,13 @@ meta_kms_connector_read_state (MetaKmsConnector *connector, current_state = g_steal_pointer (&connector->current_state); changes = META_KMS_UPDATE_CHANGE_NONE; + if (!drm_connector) + { + if (current_state) + changes = META_KMS_UPDATE_CHANGE_FULL; + goto out; + } + if (drm_connector->connection != DRM_MODE_CONNECTED) { if (drm_connector->connection != connector->connection) @@ -577,7 +586,7 @@ meta_kms_connector_read_state (MetaKmsConnector *connector, changes |= META_KMS_UPDATE_CHANGE_FULL; } - return changes; + goto out; } state = meta_kms_connector_state_new (); @@ -616,8 +625,8 @@ meta_kms_connector_read_state (MetaKmsConnector *connector, changes |= connector_changes; } - if (changes != META_KMS_UPDATE_CHANGE_NONE) - sync_fd_held (connector, impl_device); +out: + sync_fd_held (connector, impl_device); return changes; } @@ -634,13 +643,10 @@ meta_kms_connector_update_state (MetaKmsConnector *connector, drm_connector = drmModeGetConnector (meta_kms_impl_device_get_fd (impl_device), connector->id); - if (!drm_connector) - return META_KMS_UPDATE_CHANGE_FULL; - changes = meta_kms_connector_read_state (connector, impl_device, drm_connector, drm_resources); - drmModeFreeConnector (drm_connector); + g_clear_pointer (&drm_connector, drmModeFreeConnector); return changes; }