aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@googlemail.com>2012-11-15 08:04:37 -0500
committerDave Airlie <airlied@redhat.com>2012-11-20 00:35:05 -0500
commit08bec5b4edd13a7cb0bc2fb27c529d794ae67054 (patch)
tree59edffe156e39c01d69a32a7738c056db50ceb4c
parent9fabd4eedeb904173d05cb1ced3c3e6b9d2e8137 (diff)
drm: fix returning -EINVAL on setmaster if another master is active
We link every DRM "file_priv" to a "drm_master" structure. Currently, the drmSetMaster() call returns 0 when there is _any_ active master associated with the "drm_master" structure of the calling "file_priv". This means, that after drmSetMaster() we are not guaranteed to be DRM-Master and might not be able to perform mode-setting. A way to reproduce this is by starting weston with the DRM backend from within an X-console (eg., xterm). Because the xserver's "drm_master" is currently active, weston is assigned to the same master but is inactive because its VT is inactive and the xserver is still active. But when "fake-activating" weston, it calls drmSetMaster(). With current behavior this returns "0/success" and weston thinks that it is DRM-Master, even though it is not (as the xserver is still DRM-Master). Expected behavior would be drmSetMaster() to return -EINVAL, because the xserver is still DRM-Master. This patch changes exactly that. The only way this bogus behavior would be useful is for clients to check whether their associated "drm_master" is currently the active DRM-Master. But this logic fails if no DRM-Master is currently active at all. Because then the client itself would become DRM-Master (if it is root) and this makes this whole thing useles. Also note that the second "if-condition": file_priv->minor->master != file_priv->master is always true and can be skipped. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
-rw-r--r--drivers/gpu/drm/drm_stub.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
index c236fd27eba6..581e61d04057 100644
--- a/drivers/gpu/drm/drm_stub.c
+++ b/drivers/gpu/drm/drm_stub.c
@@ -221,20 +221,20 @@ int drm_setmaster_ioctl(struct drm_device *dev, void *data,
221 if (!file_priv->master) 221 if (!file_priv->master)
222 return -EINVAL; 222 return -EINVAL;
223 223
224 if (!file_priv->minor->master && 224 if (file_priv->minor->master)
225 file_priv->minor->master != file_priv->master) { 225 return -EINVAL;
226 mutex_lock(&dev->struct_mutex); 226
227 file_priv->minor->master = drm_master_get(file_priv->master); 227 mutex_lock(&dev->struct_mutex);
228 file_priv->is_master = 1; 228 file_priv->minor->master = drm_master_get(file_priv->master);
229 if (dev->driver->master_set) { 229 file_priv->is_master = 1;
230 ret = dev->driver->master_set(dev, file_priv, false); 230 if (dev->driver->master_set) {
231 if (unlikely(ret != 0)) { 231 ret = dev->driver->master_set(dev, file_priv, false);
232 file_priv->is_master = 0; 232 if (unlikely(ret != 0)) {
233 drm_master_put(&file_priv->minor->master); 233 file_priv->is_master = 0;
234 } 234 drm_master_put(&file_priv->minor->master);
235 } 235 }
236 mutex_unlock(&dev->struct_mutex);
237 } 236 }
237 mutex_unlock(&dev->struct_mutex);
238 238
239 return 0; 239 return 0;
240} 240}