bc0aa7a
From 3b40f521aa2f42862203497a94ae77536f41ade2 Mon Sep 17 00:00:00 2001
bc0aa7a
From: Hans de Goede <hdegoede@redhat.com>
bc0aa7a
Date: Thu, 12 Oct 2017 19:44:48 +0200
bc0aa7a
Subject: [PATCH] staging: vboxvideo: Fix reporting invalid
bc0aa7a
 suggested-offset-properties
bc0aa7a
bc0aa7a
The x and y hints receives from the host are unsigned 32 bit integers and
bc0aa7a
they get set to -1 (0xffffffff) when invalid. Before this commit the
bc0aa7a
vboxvideo driver was storing them in an u16 causing the -1 to be truncated
bc0aa7a
to 65535 which, once reported to userspace, was breaking gnome 3.26+
bc0aa7a
in Wayland mode.
bc0aa7a
bc0aa7a
This commit stores the host values in 32 bit variables, removing the
bc0aa7a
truncation and checks for -1, replacing it with 0 as -1 is not a valid
bc0aa7a
suggested-offset-property value. Likewise the properties are now
bc0aa7a
initialized to 0 instead of -1, since -1 is not a valid value.
bc0aa7a
This fixes gnome 3.26+ in Wayland mode not working with the vboxvideo
bc0aa7a
driver.
bc0aa7a
bc0aa7a
Reported-by: Gianfranco Costamagna <locutusofborg@debian.org>
bc0aa7a
Cc: stable@vger.kernel.org
bc0aa7a
Cc: Michael Thayer <michael.thayer@oracle.com>
bc0aa7a
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
bc0aa7a
---
bc0aa7a
 drivers/staging/vboxvideo/vbox_drv.h  |  8 ++++----
bc0aa7a
 drivers/staging/vboxvideo/vbox_irq.c  |  4 ++--
bc0aa7a
 drivers/staging/vboxvideo/vbox_mode.c | 26 ++++++++++++++++++--------
bc0aa7a
 3 files changed, 24 insertions(+), 14 deletions(-)
bc0aa7a
bc0aa7a
diff --git a/drivers/staging/vboxvideo/vbox_drv.h b/drivers/staging/vboxvideo/vbox_drv.h
bc0aa7a
index 4b9302703b36..eeac4f0cb2c6 100644
bc0aa7a
--- a/drivers/staging/vboxvideo/vbox_drv.h
bc0aa7a
+++ b/drivers/staging/vboxvideo/vbox_drv.h
bc0aa7a
@@ -137,8 +137,8 @@ struct vbox_connector {
bc0aa7a
 	char name[32];
bc0aa7a
 	struct vbox_crtc *vbox_crtc;
bc0aa7a
 	struct {
bc0aa7a
-		u16 width;
bc0aa7a
-		u16 height;
bc0aa7a
+		u32 width;
bc0aa7a
+		u32 height;
bc0aa7a
 		bool disconnected;
bc0aa7a
 	} mode_hint;
bc0aa7a
 };
bc0aa7a
@@ -150,8 +150,8 @@ struct vbox_crtc {
bc0aa7a
 	unsigned int crtc_id;
bc0aa7a
 	u32 fb_offset;
bc0aa7a
 	bool cursor_enabled;
bc0aa7a
-	u16 x_hint;
bc0aa7a
-	u16 y_hint;
bc0aa7a
+	u32 x_hint;
bc0aa7a
+	u32 y_hint;
bc0aa7a
 };
bc0aa7a
 
bc0aa7a
 struct vbox_encoder {
bc0aa7a
diff --git a/drivers/staging/vboxvideo/vbox_irq.c b/drivers/staging/vboxvideo/vbox_irq.c
bc0aa7a
index 3ca8bec62ac4..74abdf02d9fd 100644
bc0aa7a
--- a/drivers/staging/vboxvideo/vbox_irq.c
bc0aa7a
+++ b/drivers/staging/vboxvideo/vbox_irq.c
bc0aa7a
@@ -150,8 +150,8 @@ static void vbox_update_mode_hints(struct vbox_private *vbox)
bc0aa7a
 
bc0aa7a
 		disconnected = !(hints->enabled);
bc0aa7a
 		crtc_id = vbox_conn->vbox_crtc->crtc_id;
bc0aa7a
-		vbox_conn->mode_hint.width = hints->cx & 0x8fff;
bc0aa7a
-		vbox_conn->mode_hint.height = hints->cy & 0x8fff;
bc0aa7a
+		vbox_conn->mode_hint.width = hints->cx;
bc0aa7a
+		vbox_conn->mode_hint.height = hints->cy;
bc0aa7a
 		vbox_conn->vbox_crtc->x_hint = hints->dx;
bc0aa7a
 		vbox_conn->vbox_crtc->y_hint = hints->dy;
bc0aa7a
 		vbox_conn->mode_hint.disconnected = disconnected;
bc0aa7a
diff --git a/drivers/staging/vboxvideo/vbox_mode.c b/drivers/staging/vboxvideo/vbox_mode.c
bc0aa7a
index 257a77830410..6f08dc966719 100644
bc0aa7a
--- a/drivers/staging/vboxvideo/vbox_mode.c
bc0aa7a
+++ b/drivers/staging/vboxvideo/vbox_mode.c
bc0aa7a
@@ -553,12 +553,22 @@ static int vbox_get_modes(struct drm_connector *connector)
bc0aa7a
 		++num_modes;
bc0aa7a
 	}
bc0aa7a
 	vbox_set_edid(connector, preferred_width, preferred_height);
bc0aa7a
-	drm_object_property_set_value(
bc0aa7a
-		&connector->base, vbox->dev->mode_config.suggested_x_property,
bc0aa7a
-		vbox_connector->vbox_crtc->x_hint);
bc0aa7a
-	drm_object_property_set_value(
bc0aa7a
-		&connector->base, vbox->dev->mode_config.suggested_y_property,
bc0aa7a
-		vbox_connector->vbox_crtc->y_hint);
bc0aa7a
+
bc0aa7a
+	if (vbox_connector->vbox_crtc->x_hint != -1)
bc0aa7a
+		drm_object_property_set_value(&connector->base,
bc0aa7a
+			vbox->dev->mode_config.suggested_x_property,
bc0aa7a
+			vbox_connector->vbox_crtc->x_hint);
bc0aa7a
+	else
bc0aa7a
+		drm_object_property_set_value(&connector->base,
bc0aa7a
+			vbox->dev->mode_config.suggested_x_property, 0);
bc0aa7a
+
bc0aa7a
+	if (vbox_connector->vbox_crtc->y_hint != -1)
bc0aa7a
+		drm_object_property_set_value(&connector->base,
bc0aa7a
+			vbox->dev->mode_config.suggested_y_property,
bc0aa7a
+			vbox_connector->vbox_crtc->y_hint);
bc0aa7a
+	else
bc0aa7a
+		drm_object_property_set_value(&connector->base,
bc0aa7a
+			vbox->dev->mode_config.suggested_y_property, 0);
bc0aa7a
 
bc0aa7a
 	return num_modes;
bc0aa7a
 }
bc0aa7a
@@ -640,9 +650,9 @@ static int vbox_connector_init(struct drm_device *dev,
bc0aa7a
 
bc0aa7a
 	drm_mode_create_suggested_offset_properties(dev);
bc0aa7a
 	drm_object_attach_property(&connector->base,
bc0aa7a
-				   dev->mode_config.suggested_x_property, -1);
bc0aa7a
+				   dev->mode_config.suggested_x_property, 0);
bc0aa7a
 	drm_object_attach_property(&connector->base,
bc0aa7a
-				   dev->mode_config.suggested_y_property, -1);
bc0aa7a
+				   dev->mode_config.suggested_y_property, 0);
bc0aa7a
 	drm_connector_register(connector);
bc0aa7a
 
bc0aa7a
 	drm_mode_connector_attach_encoder(connector, encoder);
bc0aa7a
-- 
bc0aa7a
2.14.2
bc0aa7a