* [PATCH 1/2] drm: restore open_count if drm_setup fails
@ 2012-10-29 17:35 Ilija Hadzic
2012-10-29 17:35 ` [PATCH 2/2] drm: set dev_mapping before calling drm_open_helper Ilija Hadzic
2012-10-30 13:51 ` [PATCH 1/2] drm: restore open_count if drm_setup fails Thomas Hellstrom
0 siblings, 2 replies; 4+ messages in thread
From: Ilija Hadzic @ 2012-10-29 17:35 UTC (permalink / raw)
To: dri-devel; +Cc: stable
If drm_setup (called at first open) fails, the whole
open call has failed, so we should not keep the
open_count incremented.
Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com>
Cc: stable@vger.kernel.org
---
drivers/gpu/drm/drm_fops.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index 7ef1b67..af68eca 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -135,8 +135,11 @@ int drm_open(struct inode *inode, struct file *filp)
retcode = drm_open_helper(inode, filp, dev);
if (!retcode) {
atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
- if (!dev->open_count++)
+ if (!dev->open_count++) {
retcode = drm_setup(dev);
+ if (retcode)
+ dev->open_count--;
+ }
}
if (!retcode) {
mutex_lock(&dev->struct_mutex);
--
1.7.12.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] drm: set dev_mapping before calling drm_open_helper
2012-10-29 17:35 [PATCH 1/2] drm: restore open_count if drm_setup fails Ilija Hadzic
@ 2012-10-29 17:35 ` Ilija Hadzic
2012-10-30 13:54 ` Thomas Hellstrom
2012-10-30 13:51 ` [PATCH 1/2] drm: restore open_count if drm_setup fails Thomas Hellstrom
1 sibling, 1 reply; 4+ messages in thread
From: Ilija Hadzic @ 2012-10-29 17:35 UTC (permalink / raw)
To: dri-devel; +Cc: stable
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
---
drivers/gpu/drm/drm_fops.c | 47 +++++++++++++++++++++++++++++-----------------
1 file changed, 30 insertions(+), 17 deletions(-)
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index af68eca..133b413 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -121,6 +121,8 @@ int drm_open(struct inode *inode, struct file *filp)
int minor_id = iminor(inode);
struct drm_minor *minor;
int retcode = 0;
+ int need_setup = 0;
+ struct address_space *old_mapping;
minor = idr_find(&drm_minors_idr, minor_id);
if (!minor)
@@ -132,26 +134,37 @@ int drm_open(struct inode *inode, struct file *filp)
if (drm_device_is_unplugged(dev))
return -ENODEV;
+ if (!dev->open_count++)
+ need_setup = 1;
+ mutex_lock(&dev->struct_mutex);
+ old_mapping = dev->dev_mapping;
+ if (old_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) {
- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
- if (!dev->open_count++) {
- retcode = drm_setup(dev);
- if (retcode)
- dev->open_count--;
- }
- }
- if (!retcode) {
- mutex_lock(&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);
+ 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;
}
EXPORT_SYMBOL(drm_open);
--
1.7.12.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] drm: set dev_mapping before calling drm_open_helper
2012-10-29 17:35 ` [PATCH 2/2] drm: set dev_mapping before calling drm_open_helper Ilija Hadzic
@ 2012-10-30 13:54 ` Thomas Hellstrom
0 siblings, 0 replies; 4+ messages in thread
From: Thomas Hellstrom @ 2012-10-30 13:54 UTC (permalink / raw)
To: Ilija Hadzic; +Cc: stable, dri-devel
Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
On 10/29/2012 06:35 PM, Ilija Hadzic wrote:
> 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
> ---
> drivers/gpu/drm/drm_fops.c | 47 +++++++++++++++++++++++++++++-----------------
> 1 file changed, 30 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
> index af68eca..133b413 100644
> --- a/drivers/gpu/drm/drm_fops.c
> +++ b/drivers/gpu/drm/drm_fops.c
> @@ -121,6 +121,8 @@ int drm_open(struct inode *inode, struct file *filp)
> int minor_id = iminor(inode);
> struct drm_minor *minor;
> int retcode = 0;
> + int need_setup = 0;
> + struct address_space *old_mapping;
>
> minor = idr_find(&drm_minors_idr, minor_id);
> if (!minor)
> @@ -132,26 +134,37 @@ int drm_open(struct inode *inode, struct file *filp)
> if (drm_device_is_unplugged(dev))
> return -ENODEV;
>
> + if (!dev->open_count++)
> + need_setup = 1;
> + mutex_lock(&dev->struct_mutex);
> + old_mapping = dev->dev_mapping;
> + if (old_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) {
> - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
> - if (!dev->open_count++) {
> - retcode = drm_setup(dev);
> - if (retcode)
> - dev->open_count--;
> - }
> - }
> - if (!retcode) {
> - mutex_lock(&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);
> + 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;
> }
> EXPORT_SYMBOL(drm_open);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] drm: restore open_count if drm_setup fails
2012-10-29 17:35 [PATCH 1/2] drm: restore open_count if drm_setup fails Ilija Hadzic
2012-10-29 17:35 ` [PATCH 2/2] drm: set dev_mapping before calling drm_open_helper Ilija Hadzic
@ 2012-10-30 13:51 ` Thomas Hellstrom
1 sibling, 0 replies; 4+ messages in thread
From: Thomas Hellstrom @ 2012-10-30 13:51 UTC (permalink / raw)
To: Ilija Hadzic; +Cc: stable, dri-devel
Reviewed-by: Thomas Hellstrom <thellstrom@vmware.com>
On 10/29/2012 06:35 PM, Ilija Hadzic wrote:
> If drm_setup (called at first open) fails, the whole
> open call has failed, so we should not keep the
> open_count incremented.
>
> Signed-off-by: Ilija Hadzic <ihadzic@research.bell-labs.com>
> Cc: stable@vger.kernel.org
> ---
> drivers/gpu/drm/drm_fops.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
> index 7ef1b67..af68eca 100644
> --- a/drivers/gpu/drm/drm_fops.c
> +++ b/drivers/gpu/drm/drm_fops.c
> @@ -135,8 +135,11 @@ int drm_open(struct inode *inode, struct file *filp)
> retcode = drm_open_helper(inode, filp, dev);
> if (!retcode) {
> atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
> - if (!dev->open_count++)
> + if (!dev->open_count++) {
> retcode = drm_setup(dev);
> + if (retcode)
> + dev->open_count--;
> + }
> }
> if (!retcode) {
> mutex_lock(&dev->struct_mutex);
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-10-30 13:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-29 17:35 [PATCH 1/2] drm: restore open_count if drm_setup fails Ilija Hadzic
2012-10-29 17:35 ` [PATCH 2/2] drm: set dev_mapping before calling drm_open_helper Ilija Hadzic
2012-10-30 13:54 ` Thomas Hellstrom
2012-10-30 13:51 ` [PATCH 1/2] drm: restore open_count if drm_setup fails Thomas Hellstrom
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).