|
|
776610 |
From 255146e4a3d16c74390f8fdd6cae46b5d0d59ad5 Mon Sep 17 00:00:00 2001
|
|
|
776610 |
From: Iain Lane <iainl@gnome.org>
|
|
|
776610 |
Date: Fri, 10 Aug 2018 09:46:51 +0000
|
|
|
776610 |
Subject: [PATCH 1/2] gpu-kms: Handle drmModeGetResources() failing
|
|
|
776610 |
|
|
|
776610 |
Avoid dereferencing the NULL return value if it fails. We still create
|
|
|
776610 |
the MetaGpu, but we treat it as if it has no outputs.
|
|
|
776610 |
|
|
|
776610 |
Closes: https://gitlab.gnome.org/GNOME/mutter/issues/223
|
|
|
776610 |
|
|
|
776610 |
|
|
|
776610 |
(cherry picked from commit 29cc526e2eab65d856d1fd0a652f22dcdb5d72dd)
|
|
|
776610 |
---
|
|
|
776610 |
src/backends/native/meta-gpu-kms.c | 36 +++++++++++++++++++++++++-----
|
|
|
776610 |
1 file changed, 31 insertions(+), 5 deletions(-)
|
|
|
776610 |
|
|
|
776610 |
diff --git a/src/backends/native/meta-gpu-kms.c b/src/backends/native/meta-gpu-kms.c
|
|
|
776610 |
index 1d1c28809..7e7607c46 100644
|
|
|
776610 |
--- a/src/backends/native/meta-gpu-kms.c
|
|
|
776610 |
+++ b/src/backends/native/meta-gpu-kms.c
|
|
|
776610 |
@@ -62,6 +62,8 @@ struct _MetaGpuKms
|
|
|
776610 |
int max_buffer_height;
|
|
|
776610 |
|
|
|
776610 |
gboolean page_flips_not_supported;
|
|
|
776610 |
+
|
|
|
776610 |
+ gboolean resources_init_failed_before;
|
|
|
776610 |
};
|
|
|
776610 |
|
|
|
776610 |
G_DEFINE_QUARK (MetaGpuKmsError, meta_gpu_kms_error)
|
|
|
776610 |
@@ -709,20 +711,34 @@ init_outputs (MetaGpuKms *gpu_kms,
|
|
|
776610 |
setup_output_clones (gpu);
|
|
|
776610 |
}
|
|
|
776610 |
|
|
|
776610 |
-static void
|
|
|
776610 |
-meta_kms_resources_init (MetaKmsResources *resources,
|
|
|
776610 |
- int fd)
|
|
|
776610 |
+static gboolean
|
|
|
776610 |
+meta_kms_resources_init (MetaKmsResources *resources,
|
|
|
776610 |
+ int fd,
|
|
|
776610 |
+ GError **error)
|
|
|
776610 |
+
|
|
|
776610 |
{
|
|
|
776610 |
drmModeRes *drm_resources;
|
|
|
776610 |
unsigned int i;
|
|
|
776610 |
|
|
|
776610 |
drm_resources = drmModeGetResources (fd);
|
|
|
776610 |
+
|
|
|
776610 |
+ if (!drm_resources)
|
|
|
776610 |
+ {
|
|
|
776610 |
+ g_set_error (error,
|
|
|
776610 |
+ G_IO_ERROR,
|
|
|
776610 |
+ G_IO_ERROR_FAILED,
|
|
|
776610 |
+ "Calling drmModeGetResources() failed");
|
|
|
776610 |
+ return FALSE;
|
|
|
776610 |
+ }
|
|
|
776610 |
+
|
|
|
776610 |
resources->resources = drm_resources;
|
|
|
776610 |
|
|
|
776610 |
resources->n_encoders = (unsigned int) drm_resources->count_encoders;
|
|
|
776610 |
resources->encoders = g_new (drmModeEncoder *, resources->n_encoders);
|
|
|
776610 |
for (i = 0; i < resources->n_encoders; i++)
|
|
|
776610 |
resources->encoders[i] = drmModeGetEncoder (fd, drm_resources->encoders[i]);
|
|
|
776610 |
+
|
|
|
776610 |
+ return TRUE;
|
|
|
776610 |
}
|
|
|
776610 |
|
|
|
776610 |
static void
|
|
|
776610 |
@@ -734,7 +750,7 @@ meta_kms_resources_release (MetaKmsResources *resources)
|
|
|
776610 |
drmModeFreeEncoder (resources->encoders[i]);
|
|
|
776610 |
g_free (resources->encoders);
|
|
|
776610 |
|
|
|
776610 |
- drmModeFreeResources (resources->resources);
|
|
|
776610 |
+ g_clear_pointer (&resources->resources, drmModeFreeResources);
|
|
|
776610 |
}
|
|
|
776610 |
|
|
|
776610 |
static gboolean
|
|
|
776610 |
@@ -745,8 +761,18 @@ meta_gpu_kms_read_current (MetaGpu *gpu,
|
|
|
776610 |
MetaMonitorManager *monitor_manager =
|
|
|
776610 |
meta_gpu_get_monitor_manager (gpu);
|
|
|
776610 |
MetaKmsResources resources;
|
|
|
776610 |
+ g_autoptr (GError) local_error = NULL;
|
|
|
776610 |
|
|
|
776610 |
- meta_kms_resources_init (&resources, gpu_kms->fd);
|
|
|
776610 |
+ if (!meta_kms_resources_init (&resources, gpu_kms->fd, &local_error))
|
|
|
776610 |
+ {
|
|
|
776610 |
+ if (!gpu_kms->resources_init_failed_before)
|
|
|
776610 |
+ {
|
|
|
776610 |
+ g_warning ("meta_kms_resources_init failed: %s, assuming we have no outputs",
|
|
|
776610 |
+ local_error->message);
|
|
|
776610 |
+ gpu_kms->resources_init_failed_before = TRUE;
|
|
|
776610 |
+ }
|
|
|
776610 |
+ return TRUE;
|
|
|
776610 |
+ }
|
|
|
776610 |
|
|
|
776610 |
gpu_kms->max_buffer_width = resources.resources->max_width;
|
|
|
776610 |
gpu_kms->max_buffer_height = resources.resources->max_height;
|
|
|
776610 |
--
|
|
|
776610 |
2.19.0
|
|
|
776610 |
|