drm: factor out drm_close_helper() function
Subsystems (2)
PATCH 1/2 drm: factor out drm_close_helper() function
From: Emil Velikov <[email protected]>
Will be used to plug an existing memory leak.
--- drivers/gpu/drm/drm_file.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_file.c +13 -5
@@ -262,6 +262,18 @@ void drm_file_free(struct drm_file *file)kfree (file); } +static void drm_close_helper (struct file *filp) +{ +struct drm_file *file_priv = filp->private_data; +struct drm_device *dev = file_priv->minor->dev; + +mutex_lock (&dev->filelist_mutex); +list_del (&file_priv->lhead); +mutex_unlock (&dev->filelist_mutex); + +drm_file_free (file_priv); +} +static int drm_setup (struct drm_device * dev) {int ret;
@@ -473,11 +485,7 @@ int drm_release(struct inode *inode, struct file *filp)DRM_DEBUG ("open_count = %d\n" , dev->open_count); -mutex_lock (&dev->filelist_mutex); -list_del (&file_priv->lhead); -mutex_unlock (&dev->filelist_mutex); - -drm_file_free (file_priv); +drm_close_helper (filp);if (!--dev->open_count) {drm_lastclose (dev);
Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/2 drm: plug memory leak on drm_setup() failure
From: Emil Velikov <[email protected]>
Currently we fail to free and detach the drm_file when drm_setup() fails. Use the drm_close_helper to do address that.
--- drivers/gpu/drm/drm_file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_file.c +3 -1
@@ -330,8 +330,10 @@ int drm_open(struct inode *inode, struct file *filp) goto err_undo;if (need_setup) { retcode =drm_setup (dev); -if (retcode) +if (retcode) { +drm_close_helper (filp); goto err_undo; + } }return 0 ;
Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: plug memory leak on drm_setup() failure
Quoted 15 lines · Emil Velikov
From: Emil Velikov <[email protected]>
Currently we fail to free and detach the
drm_filewhendrm_setup()fails. Use thedrm_close_helperto do address that.Signed-off-by Emil Velikov <[email protected]>--- drivers/gpu/drm/drm_file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_file.c +0
-0
drivers/gpu/drm/drm_file.c int drm_open(struct inode *inode, struct file *filp) · line 334
Quoted 6 lines
drivers/gpu/drm/drm_file.c +2
-1@@ -330,8 +330,10 @@ int drm_open(struct inode *inode, struct file *filp) goto err_undo;if (need_setup) { retcode =drm_setup (dev); -if (retcode) +if (retcode) { +drm_close_helper (filp);
I freaked out mildly because drm_open_helper already adds the drm_file to the filelist (hence publishes it), and publishing objects before they're fully set up is a Bad Idea :-)
But drm_setup only does legacy setup, so who cares. On both patches:
And if you feel like doing an s/drm_setup()/drm_legacy_setup()/, with or w/o changing the condition to if (need_setup && drm_core_check_feature(dev, DRIVER_LEGACY)), then that patch would also have my
Quoted 12 lines
drivers/gpu/drm/drm_file.c +1
-0goto err_undo; + } }return 0 ;Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: plug memory leak on drm_setup() failure
Quoted 27 lines · Daniel Vetter
Quoted 15 lines · Emil Velikov
From: Emil Velikov <[email protected]>
Currently we fail to free and detach the
drm_filewhendrm_setup()fails. Use thedrm_close_helperto do address that.Signed-off-by Emil Velikov <[email protected]>--- drivers/gpu/drm/drm_file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_file.c +0
-0drivers/gpu/drm/drm_file.c int drm_open(struct inode *inode, struct file *filp) · line 334
Quoted 6 lines
drivers/gpu/drm/drm_file.c +2
-1@@ -330,8 +330,10 @@ int drm_open(struct inode *inode, struct file *filp) goto err_undo;if (need_setup) { retcode =drm_setup (dev); -if (retcode) +if (retcode) { +drm_close_helper (filp);I freaked out mildly because
drm_open_helperalready adds thedrm_fileto the filelist (hence publishes it), and publishing objects before they're fully set up is a Bad Idea :-)
Quoted 4 lines
But
drm_setuponly does legacy setup, so who cares. On both patches:Reviewed-by Daniel Vetter <[email protected]>
Thanks.
Quoted 7 lines
And if you feel like doing an s/drm_setup()/drm_legacy_setup()/, with or w/o changing the condition to if (
need_setup&&drm_core_check_feature(dev, DRIVER_LEGACY)), then that patch would also have myReviewed-by Daniel Vetter <[email protected]>
I'll leave that for another day, since the inverse vfunc (firstopen <> lastclose) is not a legacy only one. Which kind of irks me a bit.
-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm: plug memory leak on drm_setup() failure
Quoted 39 lines · Emil Velikov
Quoted 27 lines · Daniel Vetter
Quoted 15 lines · Emil Velikov
From: Emil Velikov <[email protected]>
Currently we fail to free and detach the
drm_filewhendrm_setup()fails. Use thedrm_close_helperto do address that.Signed-off-by Emil Velikov <[email protected]>--- drivers/gpu/drm/drm_file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_file.c +0
-0drivers/gpu/drm/drm_file.c int drm_open(struct inode *inode, struct file *filp) · line 334
Quoted 6 lines
drivers/gpu/drm/drm_file.c +2
-1@@ -330,8 +330,10 @@ int drm_open(struct inode *inode, struct file *filp) goto err_undo;if (need_setup) { retcode =drm_setup (dev); -if (retcode) +if (retcode) { +drm_close_helper (filp);I freaked out mildly because
drm_open_helperalready adds thedrm_fileto the filelist (hence publishes it), and publishing objects before they're fully set up is a Bad Idea :-)Quoted 4 lines
But
drm_setuponly does legacy setup, so who cares. On both patches:Reviewed-by Daniel Vetter <[email protected]>Thanks.
Quoted 5 lines
And if you feel like doing an s/drm_setup()/drm_legacy_setup()/, with or w/o changing the condition to if (
need_setup&&drm_core_check_feature(dev, DRIVER_LEGACY)), then that patch would also have my
Quoted 4 lines
Quoted 2 lines
Reviewed-by Daniel Vetter <[email protected]>I'll leave that for another day, since the inverse vfunc (firstopen <> lastclose) is not a legacy only one. Which kind of irks me a bit.
We need lastclose for the fbdev emulation. Which is already fixed through the new drm_client stuff and the new generic fbdev. It's a matter of rolling that out. The other use is for delayed vgaswitcheroo changes, which I think is a bit a hack ... Since I don't have a solution for that I guess lasclose will stay with us for a while longer.
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel