mirror of
https://github.com/torvalds/linux.git
synced 2024-11-16 09:02:00 +00:00
drm: set dev_mapping before calling drm_open_helper
Some drivers (specifically vmwgfx) look at dev_mapping in their open hook, so we have to set dev->dev_mapping earlier in the process. Reference: http://lists.freedesktop.org/archives/dri-devel/2012-October/029420.html Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com> Reported-by: Thomas Hellstrom <thellstrom@vmware.com> Cc: stable@vger.kernel.org Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
parent
0f1cb1bd94
commit
fdb40a08ef
@ -121,6 +121,8 @@ int drm_open(struct inode *inode, struct file *filp)
|
|||||||
int minor_id = iminor(inode);
|
int minor_id = iminor(inode);
|
||||||
struct drm_minor *minor;
|
struct drm_minor *minor;
|
||||||
int retcode = 0;
|
int retcode = 0;
|
||||||
|
int need_setup = 0;
|
||||||
|
struct address_space *old_mapping;
|
||||||
|
|
||||||
minor = idr_find(&drm_minors_idr, minor_id);
|
minor = idr_find(&drm_minors_idr, minor_id);
|
||||||
if (!minor)
|
if (!minor)
|
||||||
@ -132,26 +134,37 @@ int drm_open(struct inode *inode, struct file *filp)
|
|||||||
if (drm_device_is_unplugged(dev))
|
if (drm_device_is_unplugged(dev))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
retcode = drm_open_helper(inode, filp, dev);
|
if (!dev->open_count++)
|
||||||
if (!retcode) {
|
need_setup = 1;
|
||||||
atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
|
mutex_lock(&dev->struct_mutex);
|
||||||
if (!dev->open_count++) {
|
old_mapping = dev->dev_mapping;
|
||||||
retcode = drm_setup(dev);
|
if (old_mapping == NULL)
|
||||||
if (retcode)
|
dev->dev_mapping = &inode->i_data;
|
||||||
dev->open_count--;
|
/* ihold ensures nobody can remove inode with our i_data */
|
||||||
}
|
ihold(container_of(dev->dev_mapping, struct inode, i_data));
|
||||||
}
|
inode->i_mapping = dev->dev_mapping;
|
||||||
if (!retcode) {
|
filp->f_mapping = dev->dev_mapping;
|
||||||
mutex_lock(&dev->struct_mutex);
|
mutex_unlock(&dev->struct_mutex);
|
||||||
if (dev->dev_mapping == NULL)
|
|
||||||
dev->dev_mapping = &inode->i_data;
|
|
||||||
/* ihold ensures nobody can remove inode with our i_data */
|
|
||||||
ihold(container_of(dev->dev_mapping, struct inode, i_data));
|
|
||||||
inode->i_mapping = dev->dev_mapping;
|
|
||||||
filp->f_mapping = dev->dev_mapping;
|
|
||||||
mutex_unlock(&dev->struct_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
retcode = drm_open_helper(inode, filp, dev);
|
||||||
|
if (retcode)
|
||||||
|
goto err_undo;
|
||||||
|
atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
|
||||||
|
if (need_setup) {
|
||||||
|
retcode = drm_setup(dev);
|
||||||
|
if (retcode)
|
||||||
|
goto err_undo;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
err_undo:
|
||||||
|
mutex_lock(&dev->struct_mutex);
|
||||||
|
filp->f_mapping = old_mapping;
|
||||||
|
inode->i_mapping = old_mapping;
|
||||||
|
iput(container_of(dev->dev_mapping, struct inode, i_data));
|
||||||
|
dev->dev_mapping = old_mapping;
|
||||||
|
mutex_unlock(&dev->struct_mutex);
|
||||||
|
dev->open_count--;
|
||||||
return retcode;
|
return retcode;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(drm_open);
|
EXPORT_SYMBOL(drm_open);
|
||||||
|
Loading…
Reference in New Issue
Block a user